77require 'rotp'
88
99module INWX
10+ # Domain Robot class
1011 class Domrobot
1112 attr_accessor :client , :cookie , :language , :api_type , :url , :debug
13+
1214 URL_LIVE = 'api.domrobot.com'
1315 URL_OTE = 'api.ote.domrobot.com'
1416 TYPE_JSON = '/jsonrpc/'
@@ -47,7 +49,7 @@ def use_xml
4749 self
4850 end
4951
50- def set_debug ( value )
52+ def show_debug ( value )
5153 self . debug = value
5254 self
5355 end
@@ -61,7 +63,7 @@ def create_client
6163 end
6264 end
6365
64- def login ( username = false , password = false , shared_secret = nil )
66+ def login ( username : false , password : false , shared_secret : nil )
6567 create_client
6668
6769 params = { user : username , pass : password , lang : language }
@@ -89,10 +91,10 @@ def call(object, method, params = {})
8991
9092 def call_xml ( object , method , params = { } )
9193 client . cookie = cookie
92- res = client . call ( object + '.' + method , params )
94+ res = client . call ( " #{ object } . #{ method } " , params )
9395
9496 save_cookie ( client . cookie )
95- debug_sent = { method : object + '.' + method , params : params }
97+ debug_sent = { method : " #{ object } . #{ method } " , params : params }
9698 output_debug ( debug_sent . to_json , res . to_json )
9799
98100 res
@@ -101,7 +103,7 @@ def call_xml(object, method, params = {})
101103 def call_json ( object , method , params = { } )
102104 req = Net ::HTTP ::Post . new ( api_type )
103105
104- json_params = { method : object + '.' + method , params : params }
106+ json_params = { method : " #{ object } . #{ method } " , params : params }
105107
106108 req . body = json_params . to_json
107109 req [ 'Cookie' ] = cookie
@@ -118,13 +120,13 @@ def save_cookie(cookie)
118120 end
119121
120122 def output_debug ( sent , received )
121- if debug
122- puts 'Sent:'
123- puts JSON . pretty_generate ( JSON . parse ( sent ) )
124- puts 'Received:'
125- puts JSON . pretty_generate ( JSON . parse ( received ) )
126- puts '-------------------------'
127- end
123+ return unless debug
124+
125+ puts 'Sent:'
126+ puts JSON . pretty_generate ( JSON . parse ( sent ) )
127+ puts 'Received:'
128+ puts JSON . pretty_generate ( JSON . parse ( received ) )
129+ puts '-------------------------'
128130 end
129131
130132 def get_secret_code ( shared_secret )
0 commit comments