reg.api2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.yard_redcarpet_ext +1 -0
  2. data/.yardopts +1 -0
  3. data/README.md +119 -7
  4. data/Rakefile +6 -2
  5. data/bin/regapi2console +10 -0
  6. data/lib/reg_api2/bill.rb +76 -0
  7. data/lib/reg_api2/common.rb +2 -4
  8. data/lib/reg_api2/console.rb +15 -0
  9. data/lib/reg_api2/console_helpers.rb +24 -0
  10. data/lib/reg_api2/domain.rb +96 -0
  11. data/lib/reg_api2/folder.rb +87 -0
  12. data/lib/reg_api2/impl.rb +18 -36
  13. data/lib/reg_api2/request_contract.rb +106 -0
  14. data/lib/reg_api2/result_contract.rb +118 -0
  15. data/lib/reg_api2/service.rb +122 -1
  16. data/lib/reg_api2/sym_hash.rb +63 -0
  17. data/lib/reg_api2/user.rb +15 -1
  18. data/lib/reg_api2/version.rb +1 -1
  19. data/lib/reg_api2/zone.rb +236 -0
  20. data/lib/reg_api2.rb +57 -17
  21. data/reg.api2.gemspec +3 -1
  22. data/spec/lib/reg_api2/bill_spec.rb +80 -0
  23. data/spec/lib/reg_api2/common_spec.rb +11 -9
  24. data/spec/lib/reg_api2/domain_spec.rb +26 -0
  25. data/spec/lib/reg_api2/folder_spec.rb +52 -0
  26. data/spec/lib/reg_api2/{request_contract/default_spec.rb → request_contract_spec.rb} +2 -2
  27. data/spec/lib/reg_api2/result_contract_spec.rb +58 -0
  28. data/spec/lib/reg_api2/service_spec.rb +27 -9
  29. data/spec/lib/reg_api2/sym_hash_spec.rb +81 -0
  30. data/spec/lib/reg_api2/user_spec.rb +35 -15
  31. data/spec/lib/reg_api2/zone_spec.rb +228 -0
  32. data/spec/spec_helper.rb +0 -1
  33. metadata +48 -22
  34. data/lib/reg_api2/clients.rb +0 -14
  35. data/lib/reg_api2/domains.rb +0 -13
  36. data/lib/reg_api2/request_contract/default.rb +0 -66
  37. data/lib/reg_api2/result_contract/default.rb +0 -25
  38. data/lib/reg_api2/result_contract/single_field.rb +0 -16
  39. data/lib/reg_api2/util.rb +0 -13
  40. data/spec/lib/reg_api2/clients_spec.rb +0 -10
  41. data/spec/lib/reg_api2/domains_spec.rb +0 -9
  42. data/spec/lib/reg_api2/result_contract/default_spec.rb +0 -25
  43. data/spec/lib/reg_api2/result_contract/single_field_spec.rb +0 -22
@@ -0,0 +1,236 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # REG.API zone category
4
+ module Zone
5
+
6
+ include RegApi2::Builder
7
+
8
+ category :zone
9
+
10
+ # @!method nop(opts = {})
11
+ # @param [Hash] opts
12
+ # @option opts [Array(dname:String)] :domains A list if domains.
13
+ # This function serves for testing purposes. You can check if you can manage DNS zones of domains. DNS zone management is possible only with domains associated with REG.RU DNS servers.
14
+ # @return [Hash(domains)] A list of domains. Domains that allow DNS zone management will have the “success” value in the “result” field, otherwise the “result” field will feature an error code explaining the error reason.
15
+ # @note Support of service lists: yes
16
+ # @note Accessibility: clients
17
+ # @example Get domains
18
+ # RegApi2.zone.nop domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
19
+ define :nop
20
+
21
+ # @!method add_alias(opts = {})
22
+ # @param [Hash] opts
23
+ # @option opts [String] :subdomain Name of the subdomain assigned an IP address. To assign an IP address to a domain, transfer the “@” value. To assign an IP address to all subdomains, which are not explicitly defined in other records, use the “*” value.
24
+ # @option opts [String or IPAddr] :ipaddr IP address assigned to the subdomain.
25
+ # Use this function to tie subdomains to IP addresses.
26
+ # @return [Hash(domains)] A list of domains with results.
27
+ # @note Support of service lists: yes
28
+ # @note Accessibility: clients
29
+ # @example Assign the IP address 111.111.111.111 to the domains test.ru and test.com.
30
+ # RegApi2.zone.add_alias domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: '@', ipaddr: IPAddr.new("111.111.111.111")
31
+ # @example Same with ip addresses as strings.
32
+ # RegApi2.zone.add_alias domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: '@', ipaddr: "111.111.111.111"
33
+ define :add_alias, required: { ipaddr: { ipaddr: true }, subdomain: {} }
34
+
35
+ # @!method add_aaaa(opts = {})
36
+ # @param [Hash] opts
37
+ # @option opts [String] :subdomain Name of the subdomain assigned an IP address. To assign an IP address to a domain, transfer the “@” value. To assign an IP address to all subdomains, which are not explicitly defined in other records, use the “*” value.
38
+ # @option opts [String or IPAddr] :ipaddr The IPv6 address assigned to the subdomain.
39
+ # Use this function to tie subdomains to IPv6 addresses.
40
+ # @return [Hash(domains)] A list of domains with results.
41
+ # @note Support of service lists: yes
42
+ # @note Accessibility: clients
43
+ # @example Assign the IPv6 address aa11::a111:11aa:aaa1:aa1a to the domains test.ru and test.com.
44
+ # RegApi2.zone.add_aaaa domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: '@', ipaddr: IPAddr.new("aa11::a111:11aa:aaa1:aa1a")
45
+ # @example Same with ipv6 addresses as strings.
46
+ # RegApi2.zone.add_aaaa domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: '@', ipaddr: "aa11::a111:11aa:aaa1:aa1a"
47
+ define :add_aaaa, required: { ipaddr: { ipaddr: true }, subdomain: {} }
48
+
49
+ # @!method add_cname(opts = {})
50
+ # @param [Hash] opts
51
+ # @option opts [String] :subdomain Name of the subdomain assigned an IP address. To assign an IP address to a domain, transfer the “@” value. To assign an IP address to all subdomains, which are not explicitly defined in other records, use the “*” value.
52
+ # @option opts [String] :canonical_name Name of the domain assigned a synonym.
53
+ # Use this function to tie a subdomain to another’s domain name.
54
+ # @return [Hash(domains)] A list of domains with results.
55
+ # @note Support of service lists: yes
56
+ # @note Accessibility: clients
57
+ # @example Tie the third-level domains mail.test.ru and mail.test.com to mx10.test.ru.
58
+ # RegApi2.zone.add_cname domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: "mail", canonical_name: "mx10.test.ru"
59
+ define :add_cname, required: { canonical_name: {}, subdomain: {} }
60
+
61
+ # @!method add_mx(opts = {})
62
+ # @param [Hash] opts
63
+ # @option opts [String] :subdomain Name of the subdomain, to which the address is assigned. The default value is “@”, i.e. the main domain.
64
+ # @option opts [Fixnum] :priority Mail server priority: from 0 (highest) through 10 (lowest).
65
+ # @option opts [String or IPAddr] :mail_server Domain name or IP address of the mail server (domain name is more preferable because not all mail servers admit IP addresses).
66
+ # Use this function to define the IP address or domain name of the mail server, which will received email destined to your domain.
67
+ # @return [Hash(domains)] A list of domains with results.
68
+ # @note Support of service lists: yes
69
+ # @note Accessibility: clients
70
+ # @example Tie the the domains test.ru and test.com to the mail servers mail.test.ru and mail.test.com.
71
+ # RegApi2.zone.add_mx domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: "@", mail_server: "mail"
72
+ define :add_mx, required: { mail_server: { ipaddr: :optional } }, optional: %w[ subdomain ]
73
+
74
+ # @!method add_ns(opts = {})
75
+ # @param [Hash] opts
76
+ # @option opts [String] :subdomain Name of the subdomain that will be handed over to other DNS servers.
77
+ # @option opts [String] :dns_server Domain name of the DNS-server.
78
+ # @option opts [Fixnum] :record_number Order number of the NS record that determines relative arrangement of NS records for the subdomain.
79
+ # You can use this function to hand over a subdomain to other DNS servers.
80
+ # @return [Hash(domains)] A list of domains with results.
81
+ # @note Support of service lists: yes
82
+ # @note Accessibility: clients
83
+ # @example Hand over domains tt.test.ru and tt.test.com to the DNS server ns1.test.ru.
84
+ # RegApi2.zone.add_ns domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: "tt", dns_server: "ns1.test.ru", record_number: 10
85
+ define :add_ns, required: { dns_server: {}, subdomain: {}, record_number: { re: /\d\d?/ } }
86
+
87
+ # @!method add_txt(opts = {})
88
+ # @param [Hash] opts
89
+ # @option opts [String] :subdomain Name of the subdomain, about which the record is added.
90
+ # @option opts [String] :text Text of the note. Only ASCII alphanumeric characters are allowed.
91
+ # Add an arbitrary note about the subdomain.
92
+ # @return [Hash(domains)] A list of domains with results.
93
+ # @note Support of service lists: yes
94
+ # @note Accessibility: clients
95
+ # @example Add notes about the mail.test.ru and mail.test.com domains.
96
+ # RegApi2.zone.add_txt domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: "mail", text: "testmail"
97
+ define :add_txt, required: { text: {}, subdomain: {} }
98
+
99
+ # @!method add_srv(opts = {})
100
+ # @param [Hash] opts
101
+ # @option opts [String] :service The service that will be matched against the defined server. For example, to make the sip.test.ru server handle SIP calls over UDP, you should specify the following string: _sip._udp.
102
+ # @option opts [Fixnum] :priority Record priority.
103
+ # @option opts [Fixnum] :weight The load that the servers can handle. Optional field. Default value: 0.
104
+ # @option opts [String] :target The server used by the service.
105
+ # @option opts [Fixnum] :port The port used by the service.
106
+ # Add service record.
107
+ # @return [Hash(domains)] A list of domains with results.
108
+ # @note Support of service lists: yes
109
+ # @note Accessibility: clients
110
+ # @example Make the sip.test.ru server handle SIP calls destined to xxx@test.ru and xxx@test.com on port 5060 over UDP.
111
+ # RegApi2.zone.add_srv domains: [ { dname: "test.ru" }, { dname: "test.com" } ], service: "_sip._udp", priority: 0, port: 5060, target: "sip.test.ru"
112
+ define :add_srv, required: { service: {}, priority: { re: /\A\d+\z/ }, target: {}, port: { re: /\A\d+\z/ } }, optional: { weight: { re: /\A\d+\z/ } }
113
+
114
+ # @!method get_resource_records(opts = {})
115
+ # Use this fuction to get zone resource records for each domains.
116
+ # @param [Hash] opts
117
+ # @option opts [Array(Hash(dname))] :domains A list of domains, where domains that allow zone management will have the “success” value in the “result” field. Otherwise the “result” field will include the error code explaining the reason of error.
118
+ # @return [Hash(domains)] A list of domains with results.
119
+ # @note Support of service lists: yes
120
+ # @note Accessibility: clients
121
+ # @example Request records for test.ru and test.com.
122
+ # RegApi2.zone.get_resource_records domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
123
+ define :get_resource_records
124
+
125
+ # @!method update_records(opts = {})
126
+ # You can use this function to add and/or delete several resource records by means of a single request. The order of elements in the transferred array is important. Records can interrelate with each other, and if an error is found in one of the records from the action_list fields, the rest of the records will be ignored.
127
+ # @param [Hash] opts
128
+ # @option opts [Array(Hash)] :action_list A hash array, where every hash provides parameters for creation/deletion of a resource record. The class/type of the created records is defined in the “action” field, allowed values are: add_alias, add_aaaa, add_cname, add_mx, add_ns, add_txt, add_srv, remove_record. The rest of hash fields depend on the “action” value and correspond to the functions described above.
129
+ # For the example given below the structure of action_list will look as follows:
130
+ # ```
131
+ # action_list => [
132
+ # {
133
+ # action => 'add_alias',
134
+ # subdomain => 'www',
135
+ # ipaddr => '11.22.33.44'
136
+ # },
137
+ # {
138
+ # action => 'add_cname',
139
+ # subdomain => '@',
140
+ # canonical_name => 'www.test.ru'
141
+ # }
142
+ # ]
143
+ # ```
144
+ # @return [Hash(domains)] A list of domains with results.
145
+ # @note Support of service lists: yes
146
+ # @note Accessibility: partners
147
+ # @example Tie the IP address 11.22.33.44 to the www.test.ru domain and assign the test.ru alias to it.
148
+ # RegApi2.zone.update_records domain_name: "test.ru", action_list: [
149
+ # { action: :add_alias, subdomain: "www", ipaddr: "11.22.33.44" },
150
+ # { action: :add_cname, subdomain: "@", canonical_name: "www.test.ru" }
151
+ # ]
152
+ define :update_records
153
+
154
+ # @!method update_soa(opts = {})
155
+ # You can use this function to change a zone cache TTL.
156
+ # @param [Hash] opts
157
+ # @option opts [Fixnum or String] :ttl Cache TTL of a zone. Valid values: a number for seconds or a number with a suffix (m – for months, w – for weeks, d – for days, h – for hours). Example: 600 (seconds), 5m (months).
158
+ # @option opts [Fixnum or String] :minimum_ttl Cache TTL for negative responses. The format is the same as for the “ttl” field.
159
+ # @return [Hash(domains)] A list of domains with results.
160
+ # @note Support of service lists: yes
161
+ # @note Accessibility: clients
162
+ # @example Set TTL.
163
+ # RegApi2.zone.update_soa domains: [ { dname: "test.ru" }, { dname: "test.com" } ], ttl: "1d", minimum_ttl: "4h"
164
+ define :update_soa, required: %w[ ttl minimum_ttl ]
165
+
166
+ # @!method tune_forwarding(opts = {})
167
+ # Use this function to add resource records required for web forwarding.
168
+ # @param [Hash] opts
169
+ # @return [Hash(domains)] A list of domains with results.
170
+ # @note Support of service lists: yes
171
+ # @note Accessibility: clients
172
+ # @see #clear_forwarding
173
+ # @example Add resource records required for web forwarding.
174
+ # RegApi2.zone.tune_forwarding domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
175
+ define :tune_forwarding
176
+
177
+ # @!method clear_forwarding(opts = {})
178
+ # Use this function to delete resource records required for web forwarding.
179
+ # @param [Hash] opts
180
+ # @return [Hash(domains)] A list of domains with results.
181
+ # @note Support of service lists: yes
182
+ # @note Accessibility: clients
183
+ # @see #tune_forwarding
184
+ # @example Delete resource records required for web forwarding.
185
+ # RegApi2.zone.clear_forwarding domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
186
+ define :clear_forwarding
187
+
188
+ # @!method tune_parking(opts = {})
189
+ # Use this function to add resource records required for domain parking.
190
+ # @param [Hash] opts
191
+ # @return [Hash(domains)] A list of domains with results.
192
+ # @note Support of service lists: yes
193
+ # @note Accessibility: clients
194
+ # @see #clear_parking
195
+ # @example Add resource records required for domain parking.
196
+ # RegApi2.zone.tune_parking domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
197
+ define :tune_parking
198
+
199
+ # @!method clear_parking(opts = {})
200
+ # Use this function to delete resource records required for domain parking.
201
+ # @param [Hash] opts
202
+ # @return [Hash(domains)] A list of domains with results.
203
+ # @note Support of service lists: yes
204
+ # @note Accessibility: clients
205
+ # @see #tune_parking
206
+ # @example Delete resource records required for domain parking.
207
+ # RegApi2.zone.clear_parking domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
208
+ define :clear_parking
209
+
210
+ # @!method remove_record(opts = {})
211
+ # Use this function to delete resource records.
212
+ # @param [Hash] opts
213
+ # @option opts [String] :subdomain The subdomain for which the resource record will be deleted.
214
+ # @option opts [String or Symbol] :record_type The class/type of the deleted record. Mandatory field.
215
+ # @option opts [Fixnum] :priority Optional field. Default value: 0. Not applicable to the request for removal of an A-record (and similar records).
216
+ # @option opts [String] :content The content of the record. Optional field. If it is not available, all records satisfying the settings of the rest of parameters will be deleted.
217
+ # @return [Hash(domains)] A list of domains with results.
218
+ # @note Support of service lists: yes
219
+ # @note Accessibility: clients
220
+ # @example Delete A record with 111.111.111.111 ip from @.
221
+ # RegApi2.zone.remove_record domains: [ { dname: "test.ru" }, { dname: "test.com" } ], subdomain: '@', content: '111.111.111.111', record_type: :A
222
+ define :remove_record, required: %w[ subdomain record_type ]
223
+
224
+ # @!method clear(opts = {})
225
+ # Delete all resource records.
226
+ # @param [Hash] opts
227
+ # @return [Hash(domains)] A list of domains with results.
228
+ # @note Support of service lists: yes
229
+ # @note Accessibility: clients
230
+ # @example Delete all resource records.
231
+ # RegApi2.zone.clear domains: [ { dname: "test.ru" }, { dname: "test.com" } ]
232
+ define :clear
233
+
234
+ extend self
235
+ end
236
+ end
data/lib/reg_api2.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require "reg_api2/version"
3
3
 
4
- require "reg_api2/request_contract/default"
5
- require "reg_api2/result_contract/default"
4
+ require "reg_api2/request_contract"
5
+ require "reg_api2/result_contract"
6
6
 
7
7
  require "reg_api2/impl"
8
8
  require 'reg_api2/builder'
9
9
 
10
10
  require 'reg_api2/common'
11
- require 'reg_api2/domains'
12
- require 'reg_api2/clients'
11
+ require 'reg_api2/domain'
13
12
  require 'reg_api2/user'
14
13
  require 'reg_api2/service'
14
+ require 'reg_api2/bill'
15
+ require 'reg_api2/folder'
16
+ require 'reg_api2/zone'
15
17
 
16
- # REG.API v2
18
+ # # REG.API v2
17
19
  # @example List of services by specified identifiers
18
20
  # RegApi2.service.nop(services: [
19
21
  # { dname:"test.ru" },
@@ -22,32 +24,70 @@ require 'reg_api2/service'
22
24
  # { service_id: "22bug22" },
23
25
  # { surprise: "surprise.ru" }
24
26
  # ])
27
+ #
28
+ # ## RegApi2 module
29
+ #
30
+ # Provides r/w settings for API connection:
31
+ #
32
+ # * {RegApi2.username} - Your user name. `test` by default.
33
+ # * {RegApi2.password} - Your password. `test` by default.
34
+ # * {RegApi2.io_encoding} - Input/ouput encoding. `utf-8` by default.
35
+ # * {RegApi2.lang} - Language of API answers. `en` by default.
36
+ #
37
+ # Provides shortcuts for API categories:
38
+ #
39
+ # * {RegApi2.common} API category implemented as {RegApi2::Common} methods.
40
+ # * {RegApi2.domain} API category implemented as {RegApi2::Domain} methods.
41
+ # * {RegApi2.user} API category implemented as {RegApi2::User} methods.
42
+ # * {RegApi2.service} API category implemented as {RegApi2::Service} methods.
43
+ # * {RegApi2.bill} API category implemented as {RegApi2::Bill} methods.
44
+ # * {RegApi2.folder} API category implemented as {RegApi2::Folder} methods.
45
+ # * {RegApi2.zone} API category implemented as {RegApi2::Zone} methods.
46
+ #
47
+ # Please read {file:README.md} for API overview.
25
48
 
26
49
  module RegApi2
27
50
 
28
51
  # Shortcut for {RegApi2::Common} methods
29
- # @return [Module]
52
+ # @return [Module] {RegApi2::Common}
53
+ # @api Shortcuts
30
54
  def common; RegApi2::Common; end
31
55
  module_function :common
32
56
 
33
- # Shortcut for {RegApi2::Domains} methods.
34
- # @return [Module]
35
- def domains; RegApi2::Domains; end
36
- module_function :domains
37
-
38
- # Shortcut for {RegApi2::Clients} methods.
39
- # @return [Module]
40
- def clients; RegApi2::Clients; end
41
- module_function :clients
57
+ # Shortcut for {RegApi2::Domain} methods.
58
+ # @return [Module] {RegApi2::Domain}
59
+ # @api Shortcuts
60
+ def domain; RegApi2::Domain; end
61
+ module_function :domain
42
62
 
43
63
  # Shortcut for {RegApi2::User} methods.
44
- # @return [Module]
64
+ # @return [Module] {RegApi2::User}
65
+ # @api Shortcuts
45
66
  def user; RegApi2::User; end
46
67
  module_function :user
47
68
 
48
69
  # Shortcut for {RegApi2::Service} methods.
49
- # @return [Module]
70
+ # @return [Module] {RegApi2::Service}
71
+ # @api Shortcuts
50
72
  def service; RegApi2::Service; end
51
73
  module_function :service
52
74
 
75
+ # Shortcut for {RegApi2::Bill} methods.
76
+ # @return [Module] {RegApi2::Bill}
77
+ # @api Shortcuts
78
+ def bill; RegApi2::Bill; end
79
+ module_function :bill
80
+
81
+ # Shortcut for {RegApi2::Folder} methods.
82
+ # @return [Module] {RegApi2::Folder}
83
+ # @api Shortcuts
84
+ def folder; RegApi2::Folder; end
85
+ module_function :folder
86
+
87
+ # Shortcut for {RegApi2::Zone} methods.
88
+ # @return [Module] {RegApi2::Zone}
89
+ # @api Shortcuts
90
+ def zone; RegApi2::Zone; end
91
+ module_function :zone
92
+
53
93
  end
data/reg.api2.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'reg_api2/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "reg.api2"
8
- spec.version = RegApi2::VERSION
8
+ spec.version = RegApi2::VERSION.dup
9
9
  spec.authors = ["Akzhan Abdulin"]
10
10
  spec.email = ["akzhan.abdulin@gmail.com"]
11
11
  spec.description = %q{REG.API v2 Implementation}
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+ spec.has_rdoc = 'yard'
20
21
 
21
22
  spec.add_runtime_dependency "yajl-ruby", "~> 1.0"
22
23
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -28,4 +29,5 @@ Gem::Specification.new do |spec|
28
29
  spec.add_development_dependency "machinist"
29
30
  spec.add_development_dependency "yard"
30
31
  spec.add_development_dependency "redcarpet"
32
+ spec.add_development_dependency "yard-redcarpet-ext"
31
33
  end
@@ -0,0 +1,80 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ describe RegApi2::Bill do
4
+
5
+ include RegApi2
6
+
7
+ describe :nop do
8
+ it "should raise nothing" do
9
+ lambda { bill.nop }.should_not raise_error
10
+ end
11
+
12
+ it "should return nil" do
13
+ bill.nop.should be_nil
14
+ end
15
+
16
+ it "should return bill if specified" do
17
+ bill.nop(bill_id: 12345).bills.should have(1).bill
18
+ end
19
+
20
+ it "should return bills if specified" do
21
+ bill.nop(bills: [ 12345, 12346 ]).bills.should have(2).bills
22
+ end
23
+ end
24
+
25
+ describe :get_not_payed do
26
+ it "should raise nothing" do
27
+ lambda { bill.get_not_payed }.should_not raise_error
28
+ end
29
+
30
+ it "should return something real" do
31
+ bill.get_not_payed.bills.should have(1).bill
32
+ end
33
+ end
34
+
35
+ describe :get_for_period do
36
+ it "should raise ContractError without dates" do
37
+ lambda { bill.get_for_period }.should raise_error RegApi2::ContractError
38
+ end
39
+
40
+ it "should return something real" do
41
+ bill.get_for_period(
42
+ start_date: Date.new(2000, 1, 1),
43
+ end_date: Date.new(2015, 1, 1)
44
+ ).bills.should have(1).bill
45
+ end
46
+ end
47
+
48
+ describe :change_pay_type do
49
+ it "should raise if no currency given" do
50
+ lambda { bill.change_pay_type(
51
+ pay_type: :prepay,
52
+ bills: [ 123456 ]
53
+ ) }.should raise_error RegApi2::ContractError
54
+ end
55
+ it "should raise if no pay_type given" do
56
+ lambda { bill.change_pay_type(
57
+ currency: :RUR,
58
+ bills: [ 123456 ]
59
+ ) }.should raise_error RegApi2::ContractError
60
+ end
61
+ it "should raise nothing if ok" do
62
+ bill.change_pay_type(
63
+ pay_type: :prepay,
64
+ currency: :RUR,
65
+ bills: [ 123456 ]
66
+ ).bills.should have(1).bill
67
+ end
68
+ end
69
+
70
+ describe :delete do
71
+ it "should remove three bills if specified" do
72
+ ans = bill.delete(
73
+ bills: [ { bill_id: 12345 }, { bill_id: 12346 }, { bill_id: 12347 } ]
74
+ ).bills
75
+ ans.map { |b| b.bill_id }.should == [ 12345, 12346, 12347 ]
76
+ ans.each { |b| b.result.should == 'success' }
77
+ ans.each { |b| b.status.should == 'deleted' }
78
+ end
79
+ end
80
+ end
@@ -1,39 +1,41 @@
1
1
  # -*- encoding : utf-8 -*-
2
- describe RegApi2 do
2
+ describe RegApi2::Common do
3
+
4
+ include RegApi2
3
5
 
4
6
  describe :nop do
5
7
  it "should raise nothing" do
6
- lambda { RegApi2.common.nop }.should_not raise_error
8
+ lambda { common.nop }.should_not raise_error
7
9
  end
8
10
  it "should return login" do
9
- RegApi2.common.nop['login'].should == RegApi2.username
11
+ common.nop.login.should == RegApi2.username
10
12
  end
11
13
  end
12
14
 
13
15
  describe :reseller_nop do
14
16
  it "should raise nothing" do
15
- lambda { RegApi2.common.reseller_nop }.should_not raise_error
17
+ lambda { common.reseller_nop }.should_not raise_error
16
18
  end
17
19
  it "should return login" do
18
- RegApi2.common.reseller_nop['login'].should == RegApi2.username
20
+ common.reseller_nop.login.should == RegApi2.username
19
21
  end
20
22
  end
21
23
 
22
24
  describe :get_user_id do
23
25
  it "should raise nothing" do
24
- lambda { RegApi2.common.get_user_id }.should_not raise_error
26
+ lambda { common.get_user_id }.should_not raise_error
25
27
  end
26
28
  it "should return user id" do
27
- RegApi2.common.get_user_id.should be_kind_of(Fixnum)
29
+ common.get_user_id.should be_kind_of(Fixnum)
28
30
  end
29
31
  end
30
32
 
31
33
  describe :get_service_id do
32
34
  it "should raise nothing" do
33
- lambda { RegApi2.common.get_service_id(service_id: 123456) }.should_not raise_error
35
+ lambda { common.get_service_id(service_id: 123456) }.should_not raise_error
34
36
  end
35
37
  it "should return user id" do
36
- RegApi2.common.get_service_id(service_id: 123456) == 123456
38
+ common.get_service_id(service_id: 123456) == 123456
37
39
  end
38
40
  end
39
41
  end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2::Domain do
3
+
4
+ include RegApi2
5
+
6
+ describe :nop do
7
+ it "should raise nothing" do
8
+ lambda { domain.nop }.should_not raise_error
9
+ end
10
+
11
+ it "should return service id if domain exist"
12
+ # RegApi2.domain.nop(dname: 'test.ru').should be_nil
13
+ end
14
+
15
+ describe :get_prices do
16
+ it "should return prices" do
17
+ prices = domain.get_prices(
18
+ show_renew_data: true,
19
+ show_update_data: true,
20
+ currency: :USD
21
+ )
22
+ prices.should have_key(:price_group)
23
+ prices.currency.should == 'USD'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ describe RegApi2::Folder do
4
+
5
+ include RegApi2
6
+
7
+ EXAMPLE_FOLDER_DATA = { "name" => "test_folder_name", "id" => "-1" }.freeze
8
+
9
+ describe :nop do
10
+ it "should raise nothing" do
11
+ lambda { folder.nop }.should_not raise_error
12
+ end
13
+
14
+ it "should return default folder if no ops set" do
15
+ folder.nop.should == EXAMPLE_FOLDER_DATA
16
+ end
17
+
18
+ it "should return folder data if folder_id specified" do
19
+ folder.nop(folder_id: 12345).should == EXAMPLE_FOLDER_DATA
20
+ end
21
+
22
+ it "should return folder data if test_folder_name specified" do
23
+ folder.nop(folder_name: "test_folder_name").should == EXAMPLE_FOLDER_DATA
24
+ end
25
+ end
26
+
27
+ describe :create do
28
+ it "should create a folder" do
29
+ folder.create(folder_name: 'test_folder_name').should be_nil
30
+ end
31
+ end
32
+
33
+ describe :remove do
34
+ it "should remove a folder by id" do
35
+ folder.remove(folder_id: 123456).should be_nil
36
+ end
37
+
38
+ it "should remove a folder by name" do
39
+ folder.remove(folder_name: 'test_folder_name').should be_nil
40
+ end
41
+ end
42
+
43
+ describe :rename do
44
+ it "should rename a folder by id" do
45
+ folder.rename(folder_id: 123456, new_folder_name: 'new_test_folder_name').should have_key(:folder_content)
46
+ end
47
+
48
+ it "should rename a folder by name" do
49
+ folder.rename(folder_name: 'test_folder_name', new_folder_name: 'new_test_folder_name').should have_key(:folder_content)
50
+ end
51
+ end
52
+ end
@@ -1,8 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
- describe RegApi2::RequestContract::Default do
2
+ describe RegApi2::RequestContract do
3
3
 
4
4
  let!(:contract) {
5
- RegApi2::RequestContract::Default.new(
5
+ RegApi2::RequestContract.new(
6
6
  required: %w[ a b ],
7
7
  optional: %w[ c d ]
8
8
  )
@@ -0,0 +1,58 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2::ResultContract do
3
+
4
+ let!(:contract) { RegApi2::ResultContract.new(a: 1, b: 4) }
5
+
6
+ describe :initialize do
7
+ it "should assign opts" do
8
+ contract.opts.should == { a: 1, b: 4 }
9
+ end
10
+ end
11
+
12
+ describe :handle_result do
13
+ it "should return handle_answer" do
14
+ expected = 'OOLOLLO'
15
+ mock(contract).handle_answer({}) { expected }
16
+ contract.handle_result({ "answer" => {} }).should == expected
17
+ end
18
+ end
19
+
20
+ describe :handle_answer do
21
+ it "should return specified value" do
22
+ contract.handle_answer("FX").should == "FX"
23
+ end
24
+
25
+ it "should return field value if exists" do
26
+ contract = RegApi2::ResultContract.new(a:1, field: :a)
27
+ contract.handle_result({ answer: { "a" => "FX" } }).should == "FX"
28
+ end
29
+ end
30
+
31
+ describe :convert do
32
+ it "should convert fields of some types for hashes" do
33
+ ans = contract.convert({
34
+ active_domains_cnt: "6",
35
+ success: "0",
36
+ amount: "15",
37
+ text: "2323"
38
+ })
39
+ ans.should == {
40
+ active_domains_cnt: 6,
41
+ success: false,
42
+ amount: 15.0,
43
+ text: "2323"
44
+ }
45
+ ans = contract.convert({
46
+ success: "1",
47
+ })
48
+ ans.should == {
49
+ success: true,
50
+ }
51
+ end
52
+
53
+ it "should proceed arrays too" do
54
+ ans = contract.convert([ 1, 2, [ 1 ], { amount: "4543" } ])
55
+ ans.should == [ 1, 2, [ 1 ], { amount: 4543.0} ]
56
+ end
57
+ end
58
+ end