moo_moo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +59 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +21 -0
  7. data/README.md +63 -0
  8. data/Rakefile +55 -0
  9. data/lib/cacert.pem +3910 -0
  10. data/lib/moo_moo/config.rb +13 -0
  11. data/lib/moo_moo/opensrs/args.rb +109 -0
  12. data/lib/moo_moo/opensrs/base.rb +75 -0
  13. data/lib/moo_moo/opensrs/command.rb +190 -0
  14. data/lib/moo_moo/opensrs/cookie_commands.rb +52 -0
  15. data/lib/moo_moo/opensrs/lookup_commands.rb +195 -0
  16. data/lib/moo_moo/opensrs/nameserver_commands.rb +70 -0
  17. data/lib/moo_moo/opensrs/opensrsexception.rb +6 -0
  18. data/lib/moo_moo/opensrs/provisioning_commands.rb +167 -0
  19. data/lib/moo_moo/opensrs/response.rb +41 -0
  20. data/lib/moo_moo/opensrs/transfer_commands.rb +83 -0
  21. data/lib/moo_moo/opensrs/utils.rb +13 -0
  22. data/lib/moo_moo/opensrs.rb +8 -0
  23. data/lib/moo_moo/version.rb +3 -0
  24. data/lib/moo_moo.rb +16 -0
  25. data/moo_moo.gemspec +33 -0
  26. data/spec/moo_moo_spec.rb +17 -0
  27. data/spec/opensrs/args_spec.rb +179 -0
  28. data/spec/opensrs/cookie_spec.rb +78 -0
  29. data/spec/opensrs/lookup_spec.rb +212 -0
  30. data/spec/opensrs/nameserver_spec.rb +124 -0
  31. data/spec/opensrs/opensrs_spec.rb +35 -0
  32. data/spec/opensrs/provisioning_spec.rb +271 -0
  33. data/spec/opensrs/transfer_spec.rb +197 -0
  34. data/spec/opensrs/utils_spec.rb +12 -0
  35. data/spec/spec_helper.rb +57 -0
  36. data/spec/vcr_cassettes/cookie/delete_cookie.yml +219 -0
  37. data/spec/vcr_cassettes/cookie/quit_session.yml +97 -0
  38. data/spec/vcr_cassettes/cookie/set_cookie.yml +123 -0
  39. data/spec/vcr_cassettes/cookie/set_cookie_fail.yml +54 -0
  40. data/spec/vcr_cassettes/cookie/update_cookie.yml +239 -0
  41. data/spec/vcr_cassettes/lookup/belongs_to_rsp.yml +54 -0
  42. data/spec/vcr_cassettes/lookup/belongs_to_rsp_negative.yml +55 -0
  43. data/spec/vcr_cassettes/lookup/get_balance.yml +55 -0
  44. data/spec/vcr_cassettes/lookup/get_deleted_domains.yml +80 -0
  45. data/spec/vcr_cassettes/lookup/get_domain.yml +211 -0
  46. data/spec/vcr_cassettes/lookup/get_domain_fail.yml +269 -0
  47. data/spec/vcr_cassettes/lookup/get_domains_by_expiredate.yml +76 -0
  48. data/spec/vcr_cassettes/lookup/get_domains_contacts.yml +129 -0
  49. data/spec/vcr_cassettes/lookup/get_domains_contacts_fail.yml +58 -0
  50. data/spec/vcr_cassettes/lookup/get_notes_for_domain.yml +85 -0
  51. data/spec/vcr_cassettes/lookup/get_notes_for_order.yml +61 -0
  52. data/spec/vcr_cassettes/lookup/get_notes_for_transfer.yml +61 -0
  53. data/spec/vcr_cassettes/lookup/get_order_info.yml +139 -0
  54. data/spec/vcr_cassettes/lookup/get_orders_by_domain.yml +76 -0
  55. data/spec/vcr_cassettes/lookup/get_price.yml +54 -0
  56. data/spec/vcr_cassettes/lookup/get_product_info.yml +49 -0
  57. data/spec/vcr_cassettes/lookup/lookup_domain_available.yml +55 -0
  58. data/spec/vcr_cassettes/lookup/lookup_domain_registered.yml +55 -0
  59. data/spec/vcr_cassettes/lookup/name_suggest.yml +396 -0
  60. data/spec/vcr_cassettes/nameserver/create.yml +49 -0
  61. data/spec/vcr_cassettes/nameserver/delete.yml +49 -0
  62. data/spec/vcr_cassettes/nameserver/get.yml +71 -0
  63. data/spec/vcr_cassettes/nameserver/modify.yml +49 -0
  64. data/spec/vcr_cassettes/provisioning/cancel_order.yml +56 -0
  65. data/spec/vcr_cassettes/provisioning/cancel_order_invalid.yml +49 -0
  66. data/spec/vcr_cassettes/provisioning/cancel_pending_orders.yml +58 -0
  67. data/spec/vcr_cassettes/provisioning/modify_all_domains.yml +49 -0
  68. data/spec/vcr_cassettes/provisioning/modify_domain.yml +49 -0
  69. data/spec/vcr_cassettes/provisioning/process_pending.yml +57 -0
  70. data/spec/vcr_cassettes/provisioning/register_domain.yml +57 -0
  71. data/spec/vcr_cassettes/provisioning/register_pending_domain.yml +55 -0
  72. data/spec/vcr_cassettes/provisioning/register_taken_domain.yml +55 -0
  73. data/spec/vcr_cassettes/provisioning/renew_domain.yml +58 -0
  74. data/spec/vcr_cassettes/provisioning/revoke_domain.yml +55 -0
  75. data/spec/vcr_cassettes/provisioning/trust_service.yml +60 -0
  76. data/spec/vcr_cassettes/provisioning/update_contacts.yml +66 -0
  77. data/spec/vcr_cassettes/transfer/cancel_transfer.yml +49 -0
  78. data/spec/vcr_cassettes/transfer/cancel_trasnfer_order.yml +49 -0
  79. data/spec/vcr_cassettes/transfer/check_transfer.yml +56 -0
  80. data/spec/vcr_cassettes/transfer/check_transfer_exists.yml +57 -0
  81. data/spec/vcr_cassettes/transfer/get_transfers_away.yml +60 -0
  82. data/spec/vcr_cassettes/transfer/get_transfers_in.yml +80 -0
  83. data/spec/vcr_cassettes/transfer/process_transfer.yml +49 -0
  84. data/spec/vcr_cassettes/transfer/process_transfer_unsuccessful.yml +49 -0
  85. data/spec/vcr_cassettes/transfer/rsp2rsp_push_transfer.yml +49 -0
  86. data/spec/vcr_cassettes/transfer/send_password.yml +49 -0
  87. data/spec/vcr_cassettes/transfer/transfer.yml +58 -0
  88. metadata +280 -0
@@ -0,0 +1,13 @@
1
+ module MooMoo
2
+ class Config
3
+ attr_accessor :host
4
+ attr_accessor :key
5
+ attr_accessor :user
6
+ attr_accessor :pass
7
+ attr_accessor :port
8
+
9
+ def initialize
10
+ @host = 'horizion.opensrs.net'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,109 @@
1
+ module MooMoo
2
+ class MooMooArgumentError < ArgumentError; end
3
+
4
+ class Args
5
+ attr_reader :required_params, :boolean_params, :optional_params, :one_of_params
6
+ attr_reader :options
7
+ # Check the included hash for the included parameters.
8
+ # Raises MooMooArgumentError when it's mising the proper params
9
+ #
10
+ # ==== Example
11
+ #
12
+ # Args.new(options) do |c|
13
+ # c.requries :user, :pass
14
+ # c.booleans :name
15
+ # c.optionals :whatever
16
+ # end
17
+ def initialize(options)
18
+ @required_params ||= []
19
+ @boolean_params ||= []
20
+ @optional_params ||= []
21
+ @one_of_params ||= []
22
+ @options = options
23
+
24
+ yield self
25
+
26
+ requires!
27
+ booleans!
28
+ one_ofs!
29
+ valid_options!
30
+ end
31
+
32
+ # Specifies the required arguments
33
+ def requires(*values)
34
+ @optional_params.concat(values)
35
+ @required_params = values
36
+ end
37
+
38
+ # Specifies which arguments are boolean
39
+ def booleans(*values)
40
+ @optional_params.concat(values)
41
+ @boolean_params = values
42
+ end
43
+
44
+ # Specifies which arguments are optional
45
+ def optionals(*values)
46
+ @optional_params.concat(values)
47
+ end
48
+
49
+ # Specifies which arguments take one of a set of arguments
50
+ def one_of(*values)
51
+ @optional_params.concat(values)
52
+ @one_of_params = values
53
+ end
54
+
55
+ protected
56
+
57
+ # Verifies that all required arguments are present
58
+ def requires!
59
+ @required_params.each do |param|
60
+ key = (param.is_a?(Array) ? param.first : param)
61
+ verify_required_param(key)
62
+ end
63
+ end
64
+
65
+
66
+ # Checks to see if supplied params (which are booleans) contain
67
+ # either a 1 ("Yes") or 0 ("No") value.
68
+ def booleans!
69
+ @boolean_params.each do |param|
70
+ key = (param.is_a?(Array) ? param.first : param)
71
+ verify_boolean_param(key)
72
+ end
73
+ end
74
+
75
+ # Verifies that only valid arguments were set
76
+ def valid_options!
77
+ @options.keys.uniq.each do |key|
78
+ raise MooMoo::MooMooArgumentError.new("Not a valid parameter: #{key}") unless @optional_params.include?(key)
79
+ end
80
+ end
81
+
82
+ # Verifies that the one_of arguments were used correctly
83
+ def one_ofs!
84
+ if @one_of_params.size > 1
85
+ specified = @options.keys.select { |key| @one_of_params.include?(key) }.uniq
86
+ if specified.size > 1 || specified.size == 0
87
+ raise MooMoo::MooMooArgumentError.new("The parameters may include only one of '#{@one_of_params.join(', ')}'")
88
+ end
89
+ else
90
+ raise MooMoo::MooMooArgumentError.new("One of requires two or more items") unless @one_of_params.empty?
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ # Internal method for verifiying required arguments
97
+ def verify_required_param(param)
98
+ raise MooMoo::MooMooArgumentError.new("Missing required parameter: #{param}") unless @options.has_key?(param)
99
+ raise MooMoo::MooMooArgumentError.new("Required parameter cannot be blank: #{param}") if (@options[param].nil? || (@options[param].respond_to?(:empty?) && @options[param].empty?))
100
+ end
101
+
102
+ # Internal method for verifying boolean arguments
103
+ def verify_boolean_param(param)
104
+ if @options.include?(param) && ![true, false].include?(@options[param])
105
+ raise MooMoo::MooMooArgumentError.new("Boolean parameter must be \"true\" or \"false\": #{param}")
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,75 @@
1
+ module MooMoo
2
+ module OpenSRS
3
+ autoload :OpenSRSException, 'moo_moo/opensrs/opensrsexception'
4
+ autoload :Command, 'moo_moo/opensrs/command'
5
+ autoload :Utils, 'moo_moo/opensrs/utils'
6
+ autoload :LookupCommands, 'moo_moo/opensrs/lookup_commands'
7
+ autoload :ProvisioningCommands, 'moo_moo/opensrs/provisioning_commands'
8
+ autoload :TransferCommands, 'moo_moo/opensrs/transfer_commands'
9
+ autoload :NameserverCommands, 'moo_moo/opensrs/nameserver_commands'
10
+ autoload :CookieCommands, 'moo_moo/opensrs/cookie_commands'
11
+
12
+ class Base
13
+ include LookupCommands
14
+ include ProvisioningCommands
15
+ include TransferCommands
16
+ include NameserverCommands
17
+ include CookieCommands
18
+ include Utils
19
+
20
+ attr_reader :host, :key, :user, :pass, :port
21
+
22
+ # Constructor
23
+ #
24
+ # === Required
25
+ # * <tt>:host</tt> - host of the OpenSRS server
26
+ # * <tt>:key</tt> - private key
27
+ # * <tt>:user</tt> - username of the reseller
28
+ # * <tt>:pass</tt> - password of the rseller
29
+ #
30
+ # === Optional
31
+ # * <tt>:port</tt> - port to connect on
32
+ def initialize(host = nil, key = nil, user = nil, pass = nil, port = 55443)
33
+ @host = host || MooMoo.config.host
34
+ @key = key || MooMoo.config.key
35
+ @user = user || MooMoo.config.user
36
+ @pass = pass || MooMoo.config.pass
37
+ @port = port || MooMoo.config.port
38
+ end
39
+
40
+ # Runs a command
41
+ #
42
+ # === Required
43
+ # * <tt>:command</tt> - command to run
44
+ # * <tt>:command</tt> - command to run
45
+ #
46
+ # === Optional
47
+ # * <tt>:params</tt> - parameters for the command
48
+ # * <tt>:cookie</tt> - cookie, if the command requires it
49
+ def run_command(action, object, params = {}, cookie = nil)
50
+ cmd = Command.new(action, object, params, cookie)
51
+
52
+ try_opensrs do
53
+ result = cmd.run(@host, @key, @user, @port)
54
+ Response.new(result, params[:key])
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ # Indexes an array by building a hash with numeric keys
61
+ #
62
+ # === Required
63
+ # * <tt>:arr</tt> - array to build an indexed hash of
64
+ def index_array(arr)
65
+ arr_indexed = {}
66
+
67
+ arr.each_with_index do |item, index|
68
+ arr_indexed[index] = item
69
+ end
70
+
71
+ arr_indexed
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,190 @@
1
+ require 'rexml/document'
2
+ require 'digest/md5'
3
+ require 'net/http'
4
+
5
+ module MooMoo
6
+ module OpenSRS
7
+ class Command
8
+ # Constructor
9
+ #
10
+ # ==== Required
11
+ # * <tt>:action</tt> - action of the command
12
+ # * <tt>:object</tt> - object the command operates on
13
+ # * <tt>:params</tt> - additional parameters for the command
14
+ #
15
+ # ==== Optional
16
+ # * <tt>:cookie</tt> - a cookie for the domain if the command requires it
17
+ def initialize(action, object, params = {}, cookie = nil)
18
+ @action = action
19
+ @object = object
20
+ @params = params
21
+ @cookie = cookie
22
+ end
23
+
24
+ # Runs the command against OpenSRS server
25
+ #
26
+ # ==== Required
27
+ # * <tt>:host</tt> - host of the OpenSRS server
28
+ # * <tt>:key</tt> - private key for the account
29
+ # * <tt>:user</tt> - username for the account
30
+ # * <tt>:port</tt> - port to connect to
31
+ def run(host, key, user, port)
32
+ xml = build_command(@action, @object, @params, @cookie)
33
+
34
+ md5_signature = Digest::MD5.hexdigest(
35
+ Digest::MD5.hexdigest(
36
+ xml + key
37
+ ) + key
38
+ )
39
+
40
+ headers = {
41
+ 'Content-Type' => 'text/xml',
42
+ 'X-Username' => user,
43
+ 'X-Signature' => md5_signature,
44
+ 'Content-Length' => xml.size.to_s
45
+ }
46
+
47
+ http = Net::HTTP.new(URI.encode(host), port)
48
+ http.use_ssl = true
49
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
+ #http.ca_file = File.join(File.dirname(__FILE__), "../..", "cacert.pem")
51
+ res = http.post(URI.encode("/"), xml, headers)
52
+
53
+ @returned_parameters = parse_response(res.body)
54
+ end
55
+
56
+ private
57
+
58
+ # Adds XML child elements to the specified XML element for a given collection
59
+ #
60
+ # ==== Required
61
+ # * <tt>:elem</tt> - XML element to add the child nodes to
62
+ # * <tt>:coll</tt> - collection that will be added as XML child elements
63
+ def xml_add_collection_as_child(elem, coll)
64
+ # default collection type is array
65
+ dt_type = 'dt_array'
66
+
67
+ # if it's a hash, make sure the keys aren't numeric
68
+ if coll.is_a?(Hash)
69
+ begin
70
+ Float(coll.keys.first)
71
+ rescue
72
+ # the keys weren't numeric, so it really is an association (hash)
73
+ dt_type = 'dt_assoc'
74
+ end
75
+ end
76
+
77
+ elem = elem.add_element(dt_type)
78
+ coll = coll.first if coll.is_a? Array
79
+
80
+ coll.each do |key, value|
81
+ child = elem.add_element('item', {'key' => key})
82
+ if value.is_a?(Hash) || value.is_a?(Array)
83
+ xml_add_collection_as_child(child, value)
84
+ else
85
+ child.text = value
86
+ end
87
+ end
88
+ end
89
+
90
+ # Builds an XML string of the command which can be sent to OpenSRS
91
+ #
92
+ # ==== Required
93
+ # * <tt>:action</tt> - action of the command
94
+ # * <tt>:object</tt> - object the command operates on
95
+ #
96
+ # ==== Optional
97
+ # * <tt>:attributes</tt> - additional attributes for the command
98
+ # * <tt>:cookie</tt> - cookie for the domain if the command requires it
99
+ def build_command(action, object, attributes = nil, cookie = nil)
100
+ xml = <<-XML
101
+
102
+ <?xml version='1.0' encoding='UTF-8' standalone='no' ?>
103
+ <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
104
+ <OPS_envelope>
105
+ <header>
106
+ <version>0.9</version>
107
+ </header>
108
+ <body>
109
+ <data_block>
110
+ <dt_assoc>
111
+ <item key="protocol">XCP</item>
112
+ <item key="action">GET_BALANCE</item>
113
+ <item key="object">BALANCE</item>
114
+ <item key="registrant_ip"/>
115
+ </dt_assoc>
116
+ </data_block>
117
+ </body>
118
+ </OPS_envelope>
119
+ XML
120
+
121
+ doc = REXML::Document.new(xml)
122
+ doc.root.elements["body/data_block/dt_assoc/item[@key='action']"].text = action
123
+ doc.root.elements["body/data_block/dt_assoc/item[@key='object']"].text = object
124
+
125
+ unless cookie.nil?
126
+ cookie_elem = doc.root.elements["body/data_block/dt_assoc"].add_element('item', {'key' => 'cookie'})
127
+ cookie_elem.text = cookie
128
+ end
129
+
130
+ unless attributes.nil?
131
+ elem = doc.root.elements["body/data_block/dt_assoc"].add_element('item', {'key' => 'attributes'})
132
+ elem = elem.add_element('dt_assoc')
133
+ attributes.each_pair do |key, value|
134
+ attrib_elem = elem.add_element('item', {'key' => key})
135
+ if value.is_a?(Hash) || value.is_a?(Array)
136
+ xml_add_collection_as_child(attrib_elem, value)
137
+ else
138
+ attrib_elem.text = (value.is_a?(String) ? value.dup : value)
139
+ end
140
+ end
141
+ end
142
+
143
+ doc.to_s
144
+ end
145
+
146
+ # Parses an XML response from the OpenSRS registry and generates a
147
+ # hash containing all of the data. Elements with child elements
148
+ # are converted into hashes themselves, with the :element_text entry
149
+ # containing any raw text
150
+ #
151
+ # ==== Required
152
+ # * <tt>data</tt> - data of the response
153
+ def parse_response(data)
154
+ doc = REXML::Document.new(data)
155
+
156
+ values = {}
157
+
158
+ elements = doc.elements["/OPS_envelope/body/data_block/dt_assoc"].select { |item|
159
+ item.is_a? REXML::Element
160
+ }
161
+
162
+ build_xml_hash(elements)
163
+ end
164
+
165
+ # Builds a hash from a collection of XML elements
166
+ #
167
+ # ==== Required
168
+ # * <tt>elements</tt> - collection of elemenents
169
+ def build_xml_hash(elements)
170
+ data_hash = {}
171
+
172
+ elements.each do |elem|
173
+ key = elem.attributes['key']
174
+
175
+ if elem.elements.size > 0
176
+ if key.nil?
177
+ data_hash.merge!(build_xml_hash(elem.elements))
178
+ else
179
+ data_hash[key] = build_xml_hash(elem.elements)
180
+ end
181
+ else
182
+ data_hash[key] = elem.text unless key.nil?
183
+ end
184
+ end
185
+
186
+ data_hash
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,52 @@
1
+ module MooMoo
2
+ module OpenSRS
3
+ module CookieCommands
4
+ # Creates a cookie for a domain
5
+ #
6
+ # ==== Required
7
+ # * <tt>:username</tt> - username of the registrant
8
+ # * <tt>:password</tt> - password of the registrant
9
+ # * <tt>:domain</tt> - domain to set the cookie for
10
+ def set_cookie(params)
11
+ run_command :set, :cookie, {
12
+ :reg_username => params[:username],
13
+ :reg_password => params[:password],
14
+ :domain => params[:domain],
15
+ :key => 'attributes'
16
+ }
17
+ end
18
+
19
+ # Deletes a cookie that was previously set
20
+ #
21
+ # ==== Required
22
+ # * <tt>:cookie</tt> - cookie to delete
23
+ def delete_cookie(cookie)
24
+ run_command :delete, :cookie, {
25
+ :cookie => cookie
26
+ }, cookie
27
+ end
28
+
29
+ # Updates a cookie to be valid for a different domain
30
+ #
31
+ # ==== Required
32
+ # * <tt>:old_domain</tt> - domain the cookie is currently set for
33
+ # * <tt>:new_domain</tt> - domain to set the cookie for
34
+ # * <tt>:cookie</tt> - cookie to update
35
+ def update_cookie(attribs)
36
+ run_command :update, :cookie, {
37
+ :reg_username => MooMoo.config.user,
38
+ :reg_password => '',
39
+ :domain => attribs[:old_domain],
40
+ :domain_new => attribs[:new_domain],
41
+ :key => 'attributes'
42
+ }, attribs[:cookie]
43
+ end
44
+
45
+ # Cleanly terminates the connection
46
+ #
47
+ def quit_session
48
+ run_command :quit, :session
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,195 @@
1
+ module MooMoo
2
+ module OpenSRS
3
+ module LookupCommands
4
+ # Determines whether a domain belongs to the reseller
5
+ #
6
+ # ==== Required
7
+ # * <tt>:domain</tt> - domain to check ownership of
8
+ def belongs_to_rsp?(domain)
9
+ run_command :belongs_to_rsp, :domain, {
10
+ :domain => domain,
11
+ :key => 'attributes'
12
+ }
13
+ end
14
+
15
+ # Returns the balance of the reseller's account
16
+ #
17
+ def get_balance
18
+ run_command :get_balance, :balance, {
19
+ :key => 'attributes'
20
+ }
21
+ end
22
+
23
+ # Lists domains that have been deleted due to expiration or request
24
+ #
25
+ def get_deleted_domains
26
+ run_command :get_deleted_domains, :domain, {
27
+ :key => 'attributes'
28
+ }
29
+ end
30
+
31
+ # Queries various types of data associated with a domain
32
+ #
33
+ # ==== Required
34
+ # * <tt>:domain</tt> - domain to query
35
+ # * <tt>:cookie</tt> - cookie for the domain
36
+ #
37
+ # ==== Optional
38
+ # * <tt>:type</tt> - type of query to perform
39
+ def get_domain(params)
40
+ params[:type] = 'all_info' unless params[:type]
41
+
42
+ run_command :get, :domain, {
43
+ :type => params[:type],
44
+ :key => 'attributes'
45
+ }, params[:cookie]
46
+ end
47
+
48
+ # Queries contact information for a list of domains
49
+ #
50
+ # ==== Required
51
+ # * <tt>:domains</tt> - domains to get contact information for
52
+ def get_domains_contacts(*domains)
53
+ domain_list = {}
54
+ domains.each_with_index do |domain, index|
55
+ domain_list[index] = domain
56
+ end
57
+
58
+ run_command :get_domains_contacts, :domain, {
59
+ :domain_list => domain_list,
60
+ :key => 'attributes'
61
+ }
62
+ end
63
+
64
+ # Queries the domains expiring within the specified date range
65
+ #
66
+ # ==== Required
67
+ # * <tt>:start_date</tt> - beginning date of the expiration range
68
+ # * <tt>:end_date</tt> - ending date of the expiration range
69
+ def get_domains_by_expiredate(attribs)
70
+ Args.new(attribs) do |c|
71
+ c.requires :start_date, :end_date
72
+ end
73
+
74
+ run_command :get_domains_by_expiredate, :domain, {
75
+ :exp_from => attribs[:start_date].to_s,
76
+ :exp_to => attribs[:end_date].to_s,
77
+ :key => 'attributes'
78
+ }
79
+ end
80
+
81
+ # Retrieves the domain notes that detail the history of the domain (renewals, transfers, etc.)
82
+ #
83
+ # ==== Required
84
+ # * <tt>:domain</tt> - domain to get the notes for
85
+ def get_notes_for_domain(domain)
86
+ run_command :get_notes, :domain, {
87
+ :domain => domain,
88
+ :type => 'domain',
89
+ :key => 'attributes'
90
+ }
91
+ end
92
+
93
+ # Retrieves the domain notes based on an order
94
+ #
95
+ # ==== Required
96
+ # * <tt>:domain</tt> - domain to get the notes for
97
+ # * <tt>:order_id</tt> - ID of the order
98
+ def get_notes_for_order(params)
99
+ run_command :get_notes, :domain, {
100
+ :domain => params[:domain],
101
+ :order_id => params[:order_id],
102
+ :type => 'order',
103
+ :key => 'attributes'
104
+ }
105
+ end
106
+
107
+ # Retrieves the domain notes based on a transfer ID
108
+ #
109
+ # ==== Required
110
+ # * <tt>:domain</tt> - domain to get the notes for
111
+ # * <tt>:transfer_id</tt> - ID of the transfer
112
+ def get_notes_for_transfer(params)
113
+ run_command :get_notes, :domain, {
114
+ :domain => params[:domain],
115
+ :transfer_id => params[:transfer_id],
116
+ :type => 'transfer',
117
+ :key => 'attributes'
118
+ }
119
+ end
120
+
121
+ # Queries all information related to an order
122
+ #
123
+ # ==== Required
124
+ # * <tt>:order_id</tt> - ID of the order
125
+ def get_order_info(order_id)
126
+ run_command :get_order_info, :domain, {
127
+ :order_id => order_id,
128
+ :key => 'attributes'
129
+ }
130
+ end
131
+
132
+ # Retrieves information about orders placed for a specific domain
133
+ #
134
+ # ==== Required
135
+ # * <tt>:domain</tt> - domain to get orders for
136
+ def get_orders_by_domain(domain)
137
+ run_command :get_orders_by_domain, :domain, {
138
+ :domain => domain,
139
+ :key => 'attributes'
140
+ }
141
+ end
142
+
143
+ # Queries the price of a domain
144
+ #
145
+ # ==== Required
146
+ # * <tt>:domain</tt> - domain to query the price of
147
+ def get_price(domain)
148
+ run_command :get_price, :domain, {
149
+ :domain => domain,
150
+ :key => 'attributes'
151
+ }
152
+ end
153
+
154
+ # Queries the properties of the specified Trust Service product
155
+ #
156
+ # ==== Required
157
+ # * <tt>:product_id</tt> - ID of the product
158
+ def get_product_info(product_id)
159
+ run_command :get_product_info, :trust_service, {
160
+ :product_id => product_id,
161
+ :key => 'attributes'
162
+ }
163
+ end
164
+
165
+ # Determines the availability of a domain
166
+ #
167
+ # ==== Required
168
+ # * <tt>:domain</tt> - domain to check availability of
169
+ def lookup_domain(domain)
170
+ run_command :lookup, :domain, {
171
+ :domain => domain,
172
+ :key => 'attributes'
173
+ }
174
+ end
175
+
176
+ # Provides suggestions for a domain name for the specified TLDs
177
+ #
178
+ # ==== Required
179
+ # * <tt>:domain</tt> - domain
180
+ # * <tt>:tlds</tt> - list of TLDs to make suggestions with
181
+ def name_suggest(domain, tlds)
182
+ tlds_indexed = {}
183
+ tlds.each_with_index do |tld, index|
184
+ tlds_indexed[index] = tld
185
+ end
186
+
187
+ run_command :name_suggest, :domain, {
188
+ :searchstring => domain,
189
+ :tlds => tlds_indexed,
190
+ :key => 'attributes'
191
+ }
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,70 @@
1
+ module MooMoo
2
+ module OpenSRS
3
+ module NameserverCommands
4
+ # Creates a nameserver
5
+ #
6
+ # ==== Required
7
+ # * <tt>:name</tt> - name of the nameserver
8
+ # * <tt>:ip</tt> - ip address for the nameserver
9
+ # * <tt>:domain</tt> - domain name to create it for
10
+ #
11
+ # ==== Optional
12
+ # * <tt>:cookie</tt> - cookie for domain
13
+ def create_nameserver(attribs)
14
+ Args.new(attribs) do |c|
15
+ c.requires :name, :ip, :domain
16
+ c.optionals :cookie
17
+ end
18
+
19
+ cookie = attribs.delete :cookie
20
+ run_command :create, :nameserver, attribs, cookie
21
+ end
22
+
23
+ # Deletes a nameserver
24
+ #
25
+ # ==== Required
26
+ # * <tt>:name</tt> - name of the nameserver
27
+ # * <tt>:ip</tt> - ip address for the nameserver
28
+ # * <tt>:domain</tt> - domain name to create it for
29
+ #
30
+ # ==== Optional
31
+ # * <tt>:cookie</tt> - cookie for domain
32
+ def delete_nameserver(attribs, cookie = nil)
33
+ Args.new(attribs) do |c|
34
+ c.requires :name, :ip, :domain
35
+ c.optionals :cookie
36
+ end
37
+
38
+ cookie = attribs.delete :cookie
39
+ run_command :delete, :nameserver, attribs, cookie
40
+ end
41
+
42
+ # Queries nameservers that exist for the given domain
43
+ #
44
+ # ==== Required
45
+ # * <tt>:domain</tt> - domain profile to query
46
+ def get_nameserver(domain)
47
+ run_command :get, :nameserver, {
48
+ :name => 'all',
49
+ :domain => domain,
50
+ :key => 'attributes'
51
+ }
52
+ end
53
+
54
+ # Renames a nameserver
55
+ #
56
+ # ==== Required
57
+ # * <tt>:name</tt> - current name of the nameserver
58
+ # * <tt>:ip</tt> - ip address of the name server
59
+ # * <tt>:new_name</tt> - new name for the nameserver
60
+ # * <tt>:domain</tt> - domain profile the nameserver was created for
61
+ def modify_nameserver(attribs)
62
+ Args.new(attribs) do |c|
63
+ c.requires :name, :ip, :new_name, :domain
64
+ end
65
+
66
+ run_command :modify, :nameserver, attribs
67
+ end
68
+ end
69
+ end
70
+ end