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 @@
1
+ tables
data/.yardopts CHANGED
@@ -2,6 +2,7 @@
2
2
  --markup-provider redcarpet
3
3
  --charset utf-8
4
4
  --readme README.md
5
+ --plugin redcarpet-ext
5
6
  -
6
7
  README.md
7
8
  LICENSE
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  REG.API v2 Implementation.
8
8
 
9
+ We want to note that Ruby client uses recommended way to access API: POST requests with JSON input/output in utf-8 encoding over HTTPS protocol.
10
+
9
11
  ## Installation
10
12
 
11
13
  Add this line to your application's Gemfile:
@@ -27,8 +29,12 @@ Or install it yourself as:
27
29
  ```ruby
28
30
  require "reg_api2"
29
31
 
32
+ RegApi2.username = 'test'
33
+ RegApi2.password = 'test'
34
+ RegApi2.lang = 'ru'
35
+
30
36
  RegApi2.service.nop(services: [
31
- { dname:"test.ru" },
37
+ { dname: "test.ru" },
32
38
  { dname: "test.su", servtype: "srv_hosting_ispmgr" },
33
39
  { service_id: 111111 },
34
40
  { service_id: "22bug22" },
@@ -36,21 +42,127 @@ RegApi2.service.nop(services: [
36
42
  ])
37
43
  ```
38
44
 
45
+ Other examples available as examples of concrete method calls.
46
+
47
+ ### Console
48
+
49
+ This gem also provides `regapi2console` utility that allows You
50
+ to query REG.API interactively using `irb` shell.
51
+
52
+ ```
53
+ $ regapi2console
54
+ Your default username: "test", and You can change it with "~/.regapi2".
55
+ 1.9.3-p194 :001 > folder.nop
56
+ => {"name"=>"test_folder_name", "id"=>"-1"}
57
+ 1.9.3-p194 :002 >
58
+ ```
59
+
60
+ ## Recommendations for effective use of REG.API
61
+ This section provides information that will help you to make you work with REG.API more productive and convenient.
62
+
63
+ One of the most frequent problems our partners face when working with REG.API is exceeding the maximum request limit (1,200 requests per hour).
64
+
65
+ The analysis of such situations showed that in most cases such problems are the results of improper use or misuse of REG.API due to bugs or design faults in the software used by partners.
66
+
67
+ The recommendations below will, on the one hand, allow you to preclude situations with excessive requests to REG.API leading to temporary blocking of user accounts, and, on the other hand, to reduce the load on RegRuSRS.
68
+
69
+ 1. We recommend you to send WHOIS requests (for the display of WHOIS data on your sites) not to REG.API, but directly to the WHOIS servers of the corresponding domain zones.
70
+
71
+ The advantages of this approach are as follows:
72
+ * The responses to WHOIS requests will arriver faster.
73
+ * You will get data directly from its source without mediation.
74
+ * The overall number of requests will decrease, thus the likelihood of blocking of your account due to excessive requests to REG.API decreases as well.
75
+
76
+ We can offer you ready-to-use software solutions that will allow you to optimize your procedures of getting WHOIS data.
77
+
78
+ 2. We recommend you to use REG.API for placing orders or changing data rather than for obtaining data. The software employed by some of our partners either do not locally store domain-related data or store incomplete data. As a result this data is dynamically downloaded from our system with the help of such functions domain_list, service/get_info, domain/get_contacts, domain/get_nss, etc.
79
+ We advise you to store all domain- and service-related locally and address to REG.API only when you want to change some data in the registry. This will ensure fast and reliable operation of your applications and minimize your dependency on the availability of our system.
80
+
81
+ 3. All data change requests should be performed asynchronously.
82
+
83
+ Some applications perform domain/service registration operations, as well as data change operations right at the moment of processing HTTP requests from clients. But if the execution of an API request fails for some reason (connection loss, exceeding of request limit, parallel request blocking), this request will get lost and the client will receive an error message.
84
+
85
+ This mode of interaction is very unreliable and inconvenient for your customers.
86
+
87
+ We recommend you to perform all service ordering/data changing requests asynchronously using the queue mechanism. In such a case:
88
+ * You will exclude the possibility of API request blockings (because only one API request is performed at a time).
89
+ * In case of connection failures the request can be repeated until it is executed (this significantly increases the system reliability).
90
+ * In case of request processing errors (if REG.RU returned an error code), you can fix the problem and repeat the request, while the customer will not get any error messages. You can solve the major part of your customers’ problems on your own without their participation.
91
+
92
+ 4. It is a good practice to keep logs of all API request and responses. If a problem arises, logs will help you or our support engineers to efficiently locate and solve it.
93
+
94
+ We hope that this information will be useful for you and that it will help you to optimize your work with REG.API.
95
+
96
+ ## REG.API 2.0 overview
97
+
98
+ ### Service identification parameters
99
+ This group of parameters serves for identification of specific pre-ordered services.
100
+
101
+ Services can be identified by:
102
+
103
+ * service ID (both domains and services),
104
+ * domain name (domains only),
105
+ * domain name and service type (services only),
106
+ * ID of a parent service, service type or subtype (services only).
107
+
108
+ Identification by numeric service identifiers is the most reliable and quick method. For this reason, we recommend that you save and store domain/service IDs on your side and use them for service identification.
109
+
110
+ | Parameter | Description |
111
+ | ----------- | ------------------------------- |
112
+ | | **Identification by service ID (recommended)** |
113
+ | service_id | Numeric service identifier. |
114
+ | | **Identification by service ID passed by the user** |
115
+ | user_servid | Alphanumeric service identifier. To use such an identifier, you should define it during domain/service creation. To learn the pre-defined identifier, use the `RegApi2.service.get_info` function.|
116
+ | | **Domain identification by name** |
117
+ | domain_name | Domain name. Russian domain names should be passed in the punycode or national encoding. |
118
+ | | **Service identification by domain name and type of service (except for VPS)** |
119
+ | domain_name | Name of the domain the service is associated with. Russian domain names should be passed in the punycode or national encoding. |
120
+ | servtype | Service type. For example, «srv_hosting_ispmgr» for hosting or «srv_webfwd» for the web-forwarding service. |
121
+ | | **Service identification by parent service ID, service type or subtype** |
122
+ | uplink_service_id | ID of the parent service with which the required service is associated. |
123
+ | servtype | Service type. For example, «srv_hosting_ispmgr» for hosting or «srv_webfwd» for the web-forwarding service. |
124
+ | subtype | Service subtype. For example, «pro» for the ISP Manager Pro license. |
125
+
126
+ ### Service list identification parameters
127
+
128
+ | Parameter | Description |
129
+ | ----------- | ------------------------------- |
130
+ | domains | A list where each element includes a domain name or its service_ID in compliance with common service identification parameters. You can specify not more than 1000 services in one request. |
131
+ | services | A list where each element includes a domain name + service type or service_ID in compliance common service identification parameters. |
132
+
133
+ ### Folder identification parameters
134
+
135
+ | Parameter | Description |
136
+ | ----------- | ------------------------------- |
137
+ | folder_id | Numeric folder identifier (recommended). |
138
+ | folder_name | Folder name. |
139
+
140
+ ### Common payment options
141
+
142
+ This section describes the parameters common for the functions dealing with service ordering or renewal of services, i.e. the functions that involve payments.
143
+
144
+ | Parameter | Description |
145
+ | ----------- | ------------------------------- |
146
+ | point_of_sale | An arbitrary string that identifies a system/web site used by the customer for placing an order for a domain. Optional field. Example: «regpanel.ru». |
147
+ | pay_type | Payment option. Currently available payment options: (WM, bank, pbank, prepay, yamoney, rapida, robox, paymer, cash, chronopay). Default value: prepay. Please note that automatic payments can be done only if the selected payment method is «prepay» and you have enough funds in your account. Otherwise, your order will be marked as unpaid and you will have to arrange the payment manually from your profile page. |
148
+ | ok_if_no_money | Enable to create bill when not enough funds to complete the operation. In this case requested operation is stored in the system, however it will be processed after submitting "change payment method" request via web interface. Return error if this flag not set and not enough funds to complete the operation. |
149
+
39
150
  ## Documentation
40
151
 
41
- Simply do
152
+ Actual documentation available at https://www.reg.com/support/help/API-version2
153
+
154
+ For developers: Ruby client documentation can be accessed as:
42
155
 
43
156
  ```bash
44
157
  bundle exec rake yard
45
158
  open doc/index.html
46
159
  ```
47
160
 
48
- Also documentation available at https://www.reg.com/support/help/API-version2
49
-
50
161
  ## Contributing
51
162
 
52
163
  1. Fork it
53
164
  2. Create your feature branch (`git checkout -b my-new-feature`)
54
- 3. Commit your changes (`git commit -am 'Add some feature'`)
55
- 4. Push to the branch (`git push origin my-new-feature`)
56
- 5. Create new Pull Request
165
+ 3. Add your tests and run `rake`.
166
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
167
+ 5. Push to the branch (`git push origin my-new-feature`)
168
+ 6. Create new Pull Request
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
2
  require "bundler/gem_tasks"
4
3
 
5
4
  APP_ROOT = File.dirname(__FILE__).freeze
6
5
 
6
+ lib = File.expand_path('lib', APP_ROOT)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'reg_api2/version'
9
+
7
10
  begin
8
11
  require 'rspec/core/rake_task'
9
12
 
@@ -24,7 +27,8 @@ begin
24
27
  require 'yard'
25
28
 
26
29
  YARD::Rake::YardocTask.new do |yard|
27
- version = File.exists?('VERSION') ? IO.read('VERSION') : ""
30
+
31
+ version = RegApi2::VERSION
28
32
  yard.options << "--title='reg.api2 #{version}'"
29
33
  end
30
34
  rescue LoadError
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'reg_api2/console'
5
+ rescue LoadError # local run
6
+ APP_ROOT = File.expand_path('..', File.dirname(__FILE__)).freeze
7
+ lib = File.expand_path('lib', APP_ROOT)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require 'reg_api2/console'
10
+ end
@@ -0,0 +1,76 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # REG.API bill category
4
+ module Bill
5
+
6
+ include RegApi2::Builder
7
+
8
+ category :bill
9
+
10
+ # @!method nop(opts = {})
11
+ # @param [Hash] opts
12
+ # @option opts [String] :bill_id Invoice number in case of a single-invoice request.
13
+ # @option opts [Array] :bills A list if invoice numbers.
14
+ # For testing purposes.
15
+ # @return [NilClass or Hash(bills)] nil or bills.
16
+ # @note Support of invoice lists: yes
17
+ # @example Get single bill
18
+ # RegApi2.bill.nop bill_id: 12345
19
+ # @example Get bills
20
+ # RegApi2.bill.nop bills: ["12345","12346"]
21
+ define :nop
22
+
23
+ # @!method get_not_payed(opts = {})
24
+ # Use this function to obtain a list of unpaid invoices.
25
+ # @param [Hash] opts
26
+ # @option opts [Fixnum] :limit Defines the number of invoices to be included in the output at a time. Default value: 100. Maximum value: 1024.
27
+ # @option opts [Fixnum] :offset The offset from the starting point, if the number of invoices exceeds the defined limit.
28
+ # @return [Hash(bills)] Bills.
29
+ # @note Accessibility: clients
30
+ # @note Support of invoice lists: yes
31
+ define :get_not_payed
32
+
33
+ # @!method get_for_period(opts = {})
34
+ # Use this function to obtain a list of invoices for the defined period.
35
+ # @param [Hash] opts
36
+ # @option opts [String, Date] :start_date Starting date of the requested period in the ISO format. Mandatory field.
37
+ # @option opts [String, Date] :end_date End date of the requested period in the ISO format. Mandatory field.
38
+ # @option opts [String] :pay_type Payment method. For information about available alternatives refer to the description of response fields.
39
+ # @option opts [Fixnum] :limit Defines the number of invoices to be included in the output at a time. Default value: 100. Maximum value: 1024.
40
+ # @option opts [Fixnum] :offset The offset from the starting point, if the number of invoices exceeds the defined limit.
41
+ # @option opts [Boolean] :all Show inactive invoices, i.e. invoices for outdated services and invoices cancelled due to impossibility of order execution.
42
+ # @return [Hash(bills)] Bills.
43
+ # @note Accessibility: partners
44
+ # @note Support of invoice lists: yes
45
+ define :get_for_period, required: { start_date: { iso_date: true }, end_date: { iso_date: true } }
46
+
47
+ # @!method change_pay_type(opts = {})
48
+ # You can use this function to change payment methods. Some of the methods allow issue of invoices in the defined payment systems, advance payments are made immediately.
49
+ # @note Accessibility: clients
50
+ # @param [Hash] opts
51
+ # @option opts [Fixnum] :bill_id Invoice ID (in case of single invoice request).
52
+ # @option opts [Array(Fixnum)] :bills A list of invoice IDs.
53
+ # @option opts [String] :pay_type New payment type. Mandatory field. Valid values: prepay — advance payment (to be made immediately); WM — WebMoney. With the WMID defined, the invoices are issued to the customer’s WM account; yamoney, ymbill — Yandex.Dengi. To issue an invoice, define ymbill and in advance allow the receipt of invoices from REG.; bank — bank transfer
54
+ # @option opts [String] :currency Currency. Mandatory field. «Yandex.Dengi» allows RUR only, «bank» and «prepay» – RUR and USD, «WebMoney» also allows EUR and UAH.
55
+ # @option opts [Fixnum] :wmid WebMoney ID
56
+ # @note Support of invoice lists: yes
57
+ # @return [Hash(bills)] Bills.
58
+ # @example Example of request
59
+ # bill.change_pay_type(currency: :RUR, pay_type: :prepay, bills: [ 123456 ])
60
+ define :change_pay_type, required: %w[ currency pay_type ]
61
+
62
+ # @!method delete(opts = {})
63
+ # Deletion of unpaid invoices.
64
+ # @note Accessibility: clients
65
+ # @note Support of invoice lists: yes
66
+ # @param [Hash] opts
67
+ # @option opts [Fixnum] :bill_id Invoice ID (in case of single invoice request).
68
+ # @option opts [Array(Fixnum)] :bills A list of invoice IDs.
69
+ # @return [Hash(bills)] Bills.
70
+ # @example Delete three bills.
71
+ # bill.delete(bills: [ { bill_id: 12345 }, { bill_id: 12346 }, { bill_id: 12347 } ])
72
+ define :delete
73
+
74
+ extend self
75
+ end
76
+ end
@@ -1,7 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require 'reg_api2/result_contract/single_field'
4
-
5
3
  module RegApi2
6
4
 
7
5
  # REG.API common category
@@ -31,14 +29,14 @@ module RegApi2
31
29
  # @param None
32
30
  # For testing purposes (returns the identifier of the user logged into the system).
33
31
  # @return [String] user_id
34
- define :get_user_id, result: :single_field, field: 'user_id'
32
+ define :get_user_id, field: :user_id
35
33
 
36
34
  # @!method get_service_id(opts = {})
37
35
  # @param [Hash] opts The options.
38
36
  # @option opts [FixNum] :service_id Service identifier.
39
37
  # Gets service/domain identifier
40
38
  # @return [String] service_id
41
- define :get_service_id, result: :single_field, field: 'service_id'
39
+ define :get_service_id, field: :service_id
42
40
 
43
41
  extend self
44
42
  end
@@ -0,0 +1,15 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # Runs Interactive Ruby Shell
4
+ class Console
5
+ # Gem root.
6
+ GEM_ROOT = File.expand_path("../..", File.dirname(__FILE__)).freeze
7
+
8
+ # Runs irb with our console helpers.
9
+ def self.run!
10
+ Kernel.exec("irb --readline -I #{File.join(GEM_ROOT, 'lib')} -r reg_api2/console_helpers")
11
+ end
12
+ end
13
+ end
14
+
15
+ RegApi2::Console.run!
@@ -0,0 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reg_api2'
3
+
4
+ include RegApi2
5
+
6
+ # Try to load defaults from ~/.regapi2
7
+ def try_lo_load_defaults
8
+ filename = "#{ENV['HOME']}/.regapi2"
9
+ username = 'test'
10
+ password = 'test'
11
+
12
+ if File.readable?(filename)
13
+ IO.read(filename).split("\n").each do |line|
14
+ username = $1 if line.strip =~ /^\s*username\s*\=(.+)\s*$/;
15
+ password = $1 if line.strip =~ /^\s*password\s*\=(.+)\s*$/;
16
+ end
17
+ end
18
+
19
+ RegApi2.username = username
20
+ RegApi2.password = password
21
+ puts "Your default username: \"#{username}\", and You can change it with \"#{filename}\"."
22
+ end
23
+
24
+ try_lo_load_defaults
@@ -0,0 +1,96 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # REG.API domain category
4
+ module Domain
5
+
6
+ include RegApi2::Builder
7
+
8
+ category :domain
9
+
10
+ # @!method nop(opts = {})
11
+ # @param [Hash] opts
12
+ # @option opts [String] :dname Domain name to check.
13
+ # For testing purposes. Also, with the help of this function you can check accessibility of a domain and get its ID. For this, pass username+password+dname.
14
+ # @return [NilClass or String] nil or Domain identifier, available only when the domain name is passed in the field domain_name/dname.
15
+ define :nop
16
+
17
+ # @!method get_prices(opts = {})
18
+ # @param [Hash] opts
19
+ # @option opts [Fixnum] :show_renew_data With this flag enabled the System will return the price of registration renewal (1/0). Optional field.
20
+ # @option opts [Fixnum] :show_update_data Флаг возврата цен для обновления домена (1/0). Необязательное поле.
21
+ # @option opts [String] :currency Identifier of the currency in which the prices will be quoted: RUR (default), UAH, USD, EUR. Optional field.
22
+ # Get domain registration/renewal prices in all zones available.
23
+ # @return [Hash(currency, price_group, prices)] Prices sorted by domain zones. The prices are quoted for the period of 1 year. For some of the zones the minimum registration period exceeds 1 year. If a zone allows Cyrillic domains and the price for them differ from the price for domains in Latin characters, for such a zone the system will return an additional record with the prefix '__idn.'.
24
+ # @note Accessibility: everyone
25
+ # @note Support of service lists: no
26
+ define :get_prices
27
+
28
+ # @!method get_suggest(opts = {})
29
+ define :get_suggest
30
+
31
+ # @!method get_premium(opts = {})
32
+ define :get_premium
33
+
34
+ # @!method check(opts = {})
35
+ define :check
36
+
37
+ # @!method create(opts = {})
38
+ define :create
39
+
40
+ # @!method transfer(opts = {})
41
+ define :transfer
42
+
43
+ # @!method get_rereg_data(opts = {})
44
+ define :get_rereg_data
45
+
46
+ # @!method set_rereg_bids(opts = {})
47
+ define :set_rereg_bids
48
+
49
+ # @!method get_user_rereg_bids(opts = {})
50
+ define :get_user_rereg_bids
51
+
52
+ # @!method get_docs_upload_uri(opts = {})
53
+ define :get_docs_upload_uri
54
+
55
+ # @!method update_contacts(opts = {})
56
+ define :update_contacts
57
+
58
+ # @!method update_private_person_flag(opts = {})
59
+ define :update_private_person_flag
60
+
61
+ # @!method register_ns(opts = {})
62
+ define :register_ns
63
+
64
+ # @!method delete_ns(opts = {})
65
+ define :delete_ns
66
+
67
+ # @!method get_nss(opts = {})
68
+ define :get_nss
69
+
70
+ # @!method update_nss(opts = {})
71
+ define :update_nss
72
+
73
+ # @!method delegate(opts = {})
74
+ define :delegate
75
+
76
+ # @!method undelegate(opts = {})
77
+ define :undelegate
78
+
79
+ # @!method transfer_to_another_account(opts = {})
80
+ define :transfer_to_another_account
81
+
82
+ # @!method look_at_entering_list(opts = {})
83
+ define :look_at_entering_list
84
+
85
+ # @!method accept_or_refuse_entering_list(opts = {})
86
+ define :accept_or_refuse_entering_list
87
+
88
+ # @!method cancel_transfer(opts = {})
89
+ define :cancel_transfer
90
+
91
+ # @!method request_to_transfer(opts = {})
92
+ define :request_to_transfer
93
+
94
+ extend self
95
+ end
96
+ end
@@ -0,0 +1,87 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # REG.API folder category
4
+ module Folder
5
+
6
+ include RegApi2::Builder
7
+
8
+ category :folder
9
+
10
+ # @!method nop(opts = {})
11
+ # @param [Hash] opts
12
+ # @option opts [String] :folder_name Folder name to check.
13
+ # @option opts [String] :folder_id Folder id to check.
14
+ # You can use this test function to check the availability of folders.
15
+ # @return [Hash(id, name)] Folder data.
16
+ # @note Support of service lists: no
17
+ # @example Initialization with ID
18
+ # RegApi2.folder.nop folder_id: 123456
19
+ # @example Initialization with name
20
+ # RegApi2.folder.nop folder_name: "test_folder_name"
21
+ define :nop
22
+
23
+ # @!method create(opts = {})
24
+ # Creates a folder.
25
+ # @param [Hash] opts
26
+ # @option opts [String] :folder_name The name of the new folder.
27
+ # @return [nil] nil.
28
+ # @note Support of service lists: no
29
+ # @example Creation of folder
30
+ # RegApi2.folder.create folder_name: 'test_folder_name'
31
+ define :create, required: %w[ folder_name ]
32
+
33
+ # @!method remove(opts = {})
34
+ # Removes a folder.
35
+ # @param [Hash] opts
36
+ # @option opts [Fixnum] :folder_id Id of folder to remove.
37
+ # @option opts [String] :folder_name The name of folder to remove.
38
+ # @return [nil] nil.
39
+ # @note Support of service lists: no
40
+ # @example Removing of folder by id
41
+ # RegApi2.folder.remove folder_id: 123456
42
+ # @example Removing of folder by name
43
+ # RegApi2.folder.remove folder_name: 'test_folder_name'
44
+ define :remove
45
+
46
+ # @!method rename(opts = {})
47
+ # Renames a folder.
48
+ # @param [Hash] opts
49
+ # @option opts [Fixnum] :folder_id Id of folder to rename.
50
+ # @option opts [String] :folder_name The name of folder to rename.
51
+ # @option opts [String] :new_folder_name Defines the new name of folder.
52
+ # @return [Hash(folder_content)] Folder content.
53
+ # @note Support of service lists: no
54
+ # @example Renaming of folder by id
55
+ # RegApi2.folder.rename folder_id: 123456, new_folder_name: 'new_test_folder_name'
56
+ # @example Renaming of folder by name
57
+ # RegApi2.folder.rename folder_name: 'test_folder_name', new_folder_name: 'new_test_folder_name'
58
+ define :rename, required: %w[ new_folder_name ]
59
+
60
+ # @!method get_services(opts = {})
61
+ # Use this function to obtain the list of services available in the folder.
62
+ # @param [Hash] opts
63
+ define :get_services
64
+
65
+ # @!method add_services(opts = {})
66
+ # Use this function to add services to folders.
67
+ # @param [Hash] opts
68
+ define :add_services
69
+
70
+ # @!method remove_services(opts = {})
71
+ # Use this function to delete services from folders.
72
+ # @param [Hash] opts
73
+ define :remove_services
74
+
75
+ # @!method replace_services(opts = {})
76
+ # This function allows replacement of services already available in a folder with other services (deletes the service available in the folder and adds the services defined by the domain_name or service_id parameter).
77
+ # @param [Hash] opts
78
+ define :replace_services
79
+
80
+ # @!method move_services(opts = {})
81
+ # Use this function to move service between folders.
82
+ # @param [Hash] opts
83
+ define :move_services
84
+
85
+ extend self
86
+ end
87
+ end
data/lib/reg_api2/impl.rb CHANGED
@@ -3,15 +3,23 @@ require 'net/http'
3
3
  require 'net/https'
4
4
  require 'yajl'
5
5
 
6
- require 'reg_api2/util'
7
-
8
6
  module RegApi2
9
7
  # Networking Error
10
8
  class NetError < Exception
11
9
  end
10
+
12
11
  # API Contract Error
13
12
  class ContractError < Exception
13
+ # @!attribute [r] fields
14
+ # Wrong fields.
15
+ attr_reader :fields
16
+
17
+ def initialize message, fields = []
18
+ super message
19
+ @fields = fields
20
+ end
14
21
  end
22
+
15
23
  # API Error
16
24
  class ApiError < Exception
17
25
  # @!attribute [r] description
@@ -46,10 +54,6 @@ module RegApi2
46
54
  DEFAULT_IO_ENCODING = 'utf-8'
47
55
  # Default lang.
48
56
  DEFAULT_LANG = 'en'
49
- # Default API contract for requests
50
- DEFAULT_REQUEST_CONTRACT = RegApi2::RequestContract::Default
51
- # Default API contract for results
52
- DEFAULT_RESULT_CONTRACT = RegApi2::ResultContract::Default
53
57
 
54
58
  # REG.API base URI
55
59
  API_URI = URI.parse("https://api.reg.ru/api/regru2")
@@ -70,41 +74,16 @@ module RegApi2
70
74
  # Placeholder to inspect sent form
71
75
  # @param [String] path
72
76
  # @param [Hash] form
73
- # @return Doesn't matter
77
+ # @return void
74
78
  def form_to_be_sent(path, form)
75
79
  end
76
80
 
77
81
  # Placeholder to inspect got response.
78
82
  # @param [Net::HTTPResponse] response
79
- # @return Doesn't matter
83
+ # @return void
80
84
  def got_response(response)
81
85
  end
82
86
 
83
- # Gets {Class} by its name.
84
- # @param [Class] ancestor
85
- # @param [NilClass, Class, String] name
86
- # @param [Class] default_value
87
- # @return [Class] {RegApi2::RequestContract}
88
- def get_contract ancestor, name, default_value
89
- return default_value unless name
90
- return name if name.kind_of?(Class)
91
- ancestor.const_get(RegApi2::Util.constantize name)
92
- end
93
-
94
- # Gets {RegApi2::RequestContract} by its name.
95
- # @param [NilClass, Class, String] name
96
- # @return [Class] {RegApi2::RequestContract}
97
- def get_request_contract_by_name name
98
- get_contract(RegApi2::RequestContract, name, DEFAULT_REQUEST_CONTRACT)
99
- end
100
-
101
- # Gets {RegApi2::ResultContract} by its name.
102
- # @param [NilClass, Class, String] name
103
- # @return [Class] {RegApi2::ResultContract}
104
- def get_result_contract_by_name name
105
- get_contract(RegApi2::ResultContract, name, DEFAULT_RESULT_CONTRACT)
106
- end
107
-
108
87
  # Gets form data for POST request
109
88
  # @param [Hash] defopts
110
89
  # @param [Hash] opts
@@ -114,7 +93,8 @@ module RegApi2
114
93
  # HACK: REG.API doesn't know about utf-8.
115
94
  io_encoding = 'utf8' if !io_encoding || io_encoding == DEFAULT_IO_ENCODING
116
95
  opts = opts.to_hash if opts.respond_to?(:to_hash)
117
- get_request_contract_by_name(defopts[:request]).new(defopts).validate(opts)
96
+ opts = RegApi2::RequestContract.new(defopts).validate(opts)
97
+
118
98
  form = {
119
99
  'username' => username,
120
100
  'password' => password,
@@ -125,6 +105,7 @@ module RegApi2
125
105
  'show_input_params' => 0,
126
106
  'input_data' => Yajl::Encoder.encode(opts)
127
107
  }
108
+
128
109
  form
129
110
  end
130
111
 
@@ -145,7 +126,8 @@ module RegApi2
145
126
  json['error_params']
146
127
  ) if json['result'] == 'error'
147
128
 
148
- get_result_contract_by_name(defopts[:result]).new(defopts).handle_result(json)
129
+ res_contract = RegApi2::ResultContract.new(defopts)
130
+ res_contract.handle_result(json)
149
131
  end
150
132
 
151
133
  # Do actual call to REG.API using POST/JSON convention.
@@ -171,5 +153,5 @@ module RegApi2
171
153
  handle_response(defopts, res)
172
154
  end
173
155
 
174
- end
175
156
  end
157
+ end