Class: INWX::Domrobot
- Inherits:
-
Object
- Object
- INWX::Domrobot
- Defined in:
- lib/inwx-domrobot.rb
Instance Attribute Summary collapse
-
#api_type ⇒ Object
Returns the value of attribute api_type.
-
#client ⇒ Object
Returns the value of attribute client.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#language ⇒ Object
Returns the value of attribute language.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #call(object, method, params = {}) ⇒ Object
- #call_json(object, method, params = {}) ⇒ Object
- #call_xml(object, method, params = {}) ⇒ Object
- #create_client ⇒ Object
- #get_secret_code(shared_secret) ⇒ Object
-
#initialize ⇒ Domrobot
constructor
A new instance of Domrobot.
- #login(username = false, password = false, shared_secret = nil) ⇒ Object
- #logout ⇒ Object
- #output_debug(sent, received) ⇒ Object
- #save_cookie(cookie) ⇒ Object
- #set_debug(value) ⇒ Object
- #set_language(language = 'en') ⇒ Object
- #use_json ⇒ Object
- #use_live ⇒ Object
- #use_ote ⇒ Object
- #use_xml ⇒ Object
Constructor Details
#initialize ⇒ Domrobot
Returns a new instance of Domrobot.
18 19 20 21 22 23 |
# File 'lib/inwx-domrobot.rb', line 18 def initialize self. = '' self.debug = false self.url = URL_OTE self.api_type = TYPE_JSON end |
Instance Attribute Details
#api_type ⇒ Object
Returns the value of attribute api_type.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def api_type @api_type end |
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def client @client end |
#cookie ⇒ Object
Returns the value of attribute cookie.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def @cookie end |
#debug ⇒ Object
Returns the value of attribute debug.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def debug @debug end |
#language ⇒ Object
Returns the value of attribute language.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def language @language end |
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/inwx-domrobot.rb', line 11 def url @url end |
Instance Method Details
#call(object, method, params = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/inwx-domrobot.rb', line 82 def call(object, method, params = {}) if api_type == TYPE_XML call_xml(object, method, params) else call_json(object, method, params) end end |
#call_json(object, method, params = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/inwx-domrobot.rb', line 101 def call_json(object, method, params = {}) req = Net::HTTP::Post.new(api_type) json_params = { method: object + '.' + method, params: params } req.body = json_params.to_json req['Cookie'] = res = client.request(req) (res.response['set-cookie']) output_debug(req.body, res.body) JSON.parse(res.body) end |
#call_xml(object, method, params = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/inwx-domrobot.rb', line 90 def call_xml(object, method, params = {}) client. = res = client.call(object + '.' + method, params) (client.) debug_sent = { method: object + '.' + method, params: params } output_debug(debug_sent.to_json, res.to_json) res end |
#create_client ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/inwx-domrobot.rb', line 55 def create_client if api_type == TYPE_XML self.client = XMLRPC::Client.new(url, api_type, '443', nil, nil, nil, nil, true, 100) else self.client = Net::HTTP.new(url, 443) client.use_ssl = true end end |
#get_secret_code(shared_secret) ⇒ Object
130 131 132 133 |
# File 'lib/inwx-domrobot.rb', line 130 def get_secret_code(shared_secret) totp = ROTP::TOTP.new(shared_secret) totp.now end |
#login(username = false, password = false, shared_secret = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/inwx-domrobot.rb', line 64 def login(username = false, password = false, shared_secret = nil) create_client params = { user: username, pass: password, lang: language } ret = call('account', 'login', params) unless shared_secret.nil? secret_code = get_secret_code(shared_secret) ret = call('account', 'unlock', tan: secret_code) end ret end |
#logout ⇒ Object
78 79 80 |
# File 'lib/inwx-domrobot.rb', line 78 def logout call('account', 'logout') end |
#output_debug(sent, received) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/inwx-domrobot.rb', line 120 def output_debug(sent, received) if debug puts 'Sent:' puts JSON.pretty_generate(JSON.parse(sent)) puts 'Received:' puts JSON.pretty_generate(JSON.parse(received)) puts '-------------------------' end end |
#save_cookie(cookie) ⇒ Object
116 117 118 |
# File 'lib/inwx-domrobot.rb', line 116 def () self. = unless .nil? end |
#set_debug(value) ⇒ Object
50 51 52 53 |
# File 'lib/inwx-domrobot.rb', line 50 def set_debug(value) self.debug = value self end |
#set_language(language = 'en') ⇒ Object
25 26 27 28 |
# File 'lib/inwx-domrobot.rb', line 25 def set_language(language = 'en') self.language = language self end |
#use_json ⇒ Object
40 41 42 43 |
# File 'lib/inwx-domrobot.rb', line 40 def use_json self.api_type = TYPE_JSON self end |
#use_live ⇒ Object
35 36 37 38 |
# File 'lib/inwx-domrobot.rb', line 35 def use_live self.url = URL_LIVE self end |
#use_ote ⇒ Object
30 31 32 33 |
# File 'lib/inwx-domrobot.rb', line 30 def use_ote self.url = URL_OTE self end |
#use_xml ⇒ Object
45 46 47 48 |
# File 'lib/inwx-domrobot.rb', line 45 def use_xml self.api_type = TYPE_XML self end |