reg.api2 0.0.1

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.
@@ -0,0 +1,52 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'reg_api2/entity/user'
4
+
5
+ module RegApi2
6
+ # REG.API user category
7
+ module User
8
+
9
+ include RegApi2::Builder
10
+
11
+ category :user
12
+
13
+ # @!method nop
14
+ # @param None
15
+ # Accessibility testing.
16
+ # @return [NilClass] nil
17
+ define :nop
18
+
19
+ # @!method create(opts = {})
20
+ # @param opts Opts or {RegApi2::Entity::User}
21
+ # @option opts [String] :user_login Login of the new user in the REG.API system. Allowed symbols: Latin lower-case letters (a-z), digits (0 -9) and the symbols "-" and "_".
22
+ # @option opts [String] :user_password Password of the new user.
23
+ # @option opts [String] :user_email E-mail of the new user.
24
+ # @option opts [String] :user_country_code Two-letter ISO code of the country of residence of the new user, for example, 'RU'.
25
+ # @return [String] user_id of new user.
26
+ # @note Accessability: partners
27
+ # New user registration.
28
+ define :create, required: %w[ user_login user_password user_email user_country_code ], field: 'user_id', result: :single_field
29
+
30
+ # @!method get_statistics(opts = {})
31
+ # @param opts Opts
32
+ # @option opts [String] :date_from This field sets the statistics start date (optional).
33
+ # @option opts [String] :date_till This field sets the statistics end date (optional).
34
+ # @note Accessability: clients
35
+ # @note Support of service lists: no
36
+ # Get user statistics.
37
+ # @return [Hash(costs_for_period, active_domains_cnt, active_domains_get_ctrl_cnt, renew_domains_cnt, ...)] User statistics
38
+ define :get_statistics, optional: %w[ date_till date_from ]
39
+
40
+ # @!method get_balance(opts = {})
41
+ # @param opts Opts
42
+ # @option opts [String] :currency Define the currency in which the balance is presented. Conversion is performed automatically in accordance with the current exchange rates. Available options: RUR (default), USD, EUR, UAH.
43
+ # @note Accessability: clients
44
+ # @note Support of service lists: no
45
+ # View current balance.
46
+ # @return [Hash(currency, prepay, blocked, credit)] User balance
47
+ define :get_balance, required: %w[ currency ]
48
+
49
+ extend self
50
+ end
51
+ end
52
+
@@ -0,0 +1,13 @@
1
+ module RegApi2
2
+ # Internal utilities
3
+ module Util
4
+ # Constantizes specified str
5
+ # @param [String] str String to constantize.
6
+ # @return [String] Constantized string.
7
+ def constantize str
8
+ str.to_s.split('_').map { |w| w.capitalize }.join('')
9
+ end
10
+
11
+ extend self
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RegApi2
3
+ # Gem version.
4
+ VERSION = "0.0.1"
5
+ end
data/lib/reg_api2.rb ADDED
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "reg_api2/version"
3
+
4
+ require "reg_api2/request_contract/default"
5
+ require "reg_api2/result_contract/default"
6
+
7
+ require "reg_api2/impl"
8
+ require 'reg_api2/builder'
9
+
10
+ require 'reg_api2/common'
11
+ require 'reg_api2/domains'
12
+ require 'reg_api2/clients'
13
+ require 'reg_api2/user'
14
+ require 'reg_api2/service'
15
+
16
+ # REG.API v2
17
+ # @example List of services by specified identifiers
18
+ # RegApi2.service.nop(services: [
19
+ # { dname:"test.ru" },
20
+ # { dname: "test.su", servtype: "srv_hosting_ispmgr" },
21
+ # { service_id: 111111 },
22
+ # { service_id: "22bug22" },
23
+ # { surprise: "surprise.ru" }
24
+ # ])
25
+
26
+ module RegApi2
27
+
28
+ # Shortcut for {RegApi2::Common} methods
29
+ # @return [Module]
30
+ def common; RegApi2::Common; end
31
+ module_function :common
32
+
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
42
+
43
+ # Shortcut for {RegApi2::User} methods.
44
+ # @return [Module]
45
+ def user; RegApi2::User; end
46
+ module_function :user
47
+
48
+ # Shortcut for {RegApi2::Service} methods.
49
+ # @return [Module]
50
+ def service; RegApi2::Service; end
51
+ module_function :service
52
+
53
+ end
data/reg.api2.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reg_api2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reg.api2"
8
+ spec.version = RegApi2::VERSION
9
+ spec.authors = ["Akzhan Abdulin"]
10
+ spec.email = ["akzhan.abdulin@gmail.com"]
11
+ spec.description = %q{REG.API v2 Implementation}
12
+ spec.summary = %q{REG.API v2 Implementation}
13
+ spec.homepage = "https://github.com/regru/reg_api2-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "yajl-ruby", "~> 1.0"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec-core"
25
+ spec.add_development_dependency "rspec-expectations"
26
+ spec.add_development_dependency "rr"
27
+ spec.add_development_dependency "faker"
28
+ spec.add_development_dependency "machinist"
29
+ spec.add_development_dependency "yard"
30
+ spec.add_development_dependency "redcarpet"
31
+ end
@@ -0,0 +1,39 @@
1
+ require 'reg_api2/entity/user'
2
+
3
+ RegApi2::Entity::User.blueprint(:bad_login) do
4
+ user_login { nil }
5
+ user_password { Faker::Internet.password }
6
+ user_email { Faker::Internet.email }
7
+ user_country_code { 'RU' }
8
+ end
9
+
10
+ RegApi2::Entity::User.blueprint(:bad_password) do
11
+ user_login { Faker::Name.first_name }
12
+ user_password { nil }
13
+ user_email { Faker::Internet.email }
14
+ user_country_code { 'RU' }
15
+ end
16
+
17
+ RegApi2::Entity::User.blueprint(:bad_email) do
18
+ user_login { Faker::Name.first_name }
19
+ user_password { Faker::Internet.password }
20
+ user_email { nil }
21
+ user_country_code { 'RU' }
22
+ end
23
+
24
+ RegApi2::Entity::User.blueprint(:bad_country_code) do
25
+ user_login { Faker::Name.first_name }
26
+ user_password { Faker::Internet.password }
27
+ user_email { Faker::Internet.email }
28
+ user_country_code { nil }
29
+ end
30
+
31
+ RegApi2::Entity::User.blueprint(:good_user) do
32
+ user_login { 'autotestlogin4532' }
33
+ user_password { Faker::Internet.password }
34
+ user_email { Faker::Name.first_name + '@mail.ru' }
35
+ user_country_code { 'RU' }
36
+ user_first_name { Faker::Name.first_name }
37
+ user_last_name { Faker::Name.last_name }
38
+ check_only { 1 }
39
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2 do
3
+
4
+ describe :nop do
5
+ it "should raise NO_SUCH_COMMAND" do
6
+ lambda { RegApi2.clients.nop }.should raise_error RegApi2::ApiError
7
+ lambda { RegApi2.clients.nop }.should raise_error /NO_SUCH_COMMAND/
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2 do
3
+
4
+ describe :nop do
5
+ it "should raise nothing" do
6
+ lambda { RegApi2.common.nop }.should_not raise_error
7
+ end
8
+ it "should return login" do
9
+ RegApi2.common.nop['login'].should == RegApi2.username
10
+ end
11
+ end
12
+
13
+ describe :reseller_nop do
14
+ it "should raise nothing" do
15
+ lambda { RegApi2.common.reseller_nop }.should_not raise_error
16
+ end
17
+ it "should return login" do
18
+ RegApi2.common.reseller_nop['login'].should == RegApi2.username
19
+ end
20
+ end
21
+
22
+ describe :get_user_id do
23
+ it "should raise nothing" do
24
+ lambda { RegApi2.common.get_user_id }.should_not raise_error
25
+ end
26
+ it "should return user id" do
27
+ RegApi2.common.get_user_id.should be_kind_of(Fixnum)
28
+ end
29
+ end
30
+
31
+ describe :get_service_id do
32
+ it "should raise nothing" do
33
+ lambda { RegApi2.common.get_service_id(service_id: 123456) }.should_not raise_error
34
+ end
35
+ it "should return user id" do
36
+ RegApi2.common.get_service_id(service_id: 123456) == 123456
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2 do
3
+ describe :nop do
4
+ it "should raise NO_SUCH_COMMAND" do
5
+ lambda { RegApi2::Domains.nop }.should raise_error RegApi2::ApiError
6
+ lambda { RegApi2.domains.nop }.should raise_error /NO_SUCH_COMMAND/
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Testplate < RegApi2::Entity::EntityBase
4
+ attr_accessor :a, :b
5
+ end
6
+
7
+ describe Testplate do
8
+ let!(:plate) { Testplate.new(a: 4, b: 5) }
9
+
10
+ it "should be initialized with hash" do
11
+ plate.a.should == 4
12
+ plate.b.should == 5
13
+ end
14
+
15
+ it "should return the hash" do
16
+ plate.to_hash.should == { a: 4, b: 5 }
17
+ end
18
+
19
+ it "should return json" do
20
+ plate.to_json.should =~ /^{.?"a":4/
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2::RequestContract::Default do
3
+
4
+ let!(:contract) {
5
+ RegApi2::RequestContract::Default.new(
6
+ required: %w[ a b ],
7
+ optional: %w[ c d ]
8
+ )
9
+ }
10
+
11
+ describe :initialize do
12
+ it "should assign opts" do
13
+ contract.opts.should == {
14
+ required: %w[ a b ],
15
+ optional: %w[ c d ]
16
+ }
17
+ end
18
+ end
19
+
20
+ # TODO: specs
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2::ResultContract::Default do
3
+
4
+ let!(:contract) { RegApi2::ResultContract::Default.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
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2::ResultContract::SingleField do
3
+
4
+ let!(:contract) { RegApi2::ResultContract::SingleField.new(field: 'one') }
5
+
6
+ describe :initialize do
7
+ it "should assign opts" do
8
+ contract.opts.should == { field: 'one' }
9
+ end
10
+ end
11
+
12
+ describe :handle_answer do
13
+ it "should return field value if exists" do
14
+ contract.handle_answer({ "one" => "FX" }).should == "FX"
15
+ end
16
+
17
+ it "should raise ContractError on field unless exists" do
18
+ lambda { contract.handle_answer({}) }.should raise_error RegApi2::ContractError
19
+ lambda { contract.handle_answer({}) }.should raise_error /one/
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ describe RegApi2 do
3
+ before(:all) do
4
+ RegApi2.username = 'test'
5
+ RegApi2.password = 'test'
6
+ RegApi2.lang = 'ru'
7
+ end
8
+
9
+ describe :nop do
10
+ it "should return list of services if requested" do
11
+ answer = RegApi2.service.nop(services: [
12
+ { dname:"test.ru" },
13
+ { dname: "test.su", servtype: "srv_hosting_ispmgr" },
14
+ { service_id: 111111 },
15
+ { service_id: "22bug22" },
16
+ { surprise: "surprise.ru" }
17
+ ])
18
+ answer['services'].map do |rec|
19
+ rec['result'] == 'success' ? rec['dname'] : rec['error_code']
20
+ end.sort.should == %w[ INVALID_SERVICE_ID NO_DOMAIN test.ru test.su test12347.ru ]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'blueprints/user'
4
+
5
+ describe RegApi2 do
6
+ describe :nop do
7
+ it "should raise nothing" do
8
+ lambda { RegApi2.user.nop }.should_not raise_error
9
+ end
10
+
11
+ it "should return nil" do
12
+ RegApi2.user.nop.should be_nil
13
+ end
14
+ end
15
+
16
+ describe :create do
17
+ it "should raise ContractError unless user_login provided." do
18
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_login)) }.should raise_error RegApi2::ContractError
19
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_login)) }.should raise_error /user_login/
20
+ end
21
+
22
+ it "should raise ContractError unless user_password provided." do
23
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_password)) }.should raise_error RegApi2::ContractError
24
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_password)) }.should raise_error /user_password/
25
+ end
26
+
27
+ it "should raise ContractError unless user_email provided." do
28
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_email)) }.should raise_error RegApi2::ContractError
29
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_email)) }.should raise_error /user_email/
30
+ end
31
+
32
+ it "should raise ContractError unless user_country_code provided." do
33
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_country_code)) }.should raise_error RegApi2::ContractError
34
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:bad_country_code)) }.should raise_error /user_country_code/
35
+ end
36
+
37
+ it "should create user with valid data." do
38
+ lambda { RegApi2.user.create(RegApi2::Entity::User.make(:good_user)) }.should_not raise_error
39
+ RegApi2.user.create(RegApi2::Entity::User.make(:good_user)).should == "777"
40
+ end
41
+ end
42
+
43
+ describe :get_statistics do
44
+ it "should return user statistics" do
45
+ RegApi2.user.get_statistics.keys.sort.should == %w[
46
+ active_domains_cnt
47
+ active_domains_get_ctrl_cnt
48
+ balance_total
49
+ domain_folders_cnt
50
+ renew_domains_cnt
51
+ renew_domains_get_ctrl_cnt
52
+ undelegated_domains_cnt
53
+ ]
54
+ end
55
+ end
56
+
57
+ describe :get_balance do
58
+ it "should return user balance" do
59
+ RegApi2.user.get_balance(currency: "USD").keys.sort.should == %w[
60
+ currency
61
+ prepay
62
+ ]
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+
9
+ require 'rubygems'
10
+ require 'coveralls'
11
+ Coveralls.wear!
12
+
13
+ require 'faker'
14
+ require 'machinist'
15
+ require 'rspec/core'
16
+
17
+ require 'reg_api2'
18
+
19
+ class RegApi2::Entity::EntityBase
20
+ extend Machinist::Machinable
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.treat_symbols_as_metadata_keys_with_true_values = true
25
+ config.run_all_when_everything_filtered = true
26
+ config.filter_run :focus
27
+ config.mock_with :rr
28
+
29
+ # Run specs in random order to surface order dependencies. If you find an
30
+ # order dependency and want to debug it, you can fix the order by providing
31
+ # the seed, which is printed after each run.
32
+ # --seed 1234
33
+ config.order = 'random'
34
+
35
+ config.before(:all) do
36
+ RegApi2.username = 'test'
37
+ RegApi2.password = 'test'
38
+ RegApi2.lang = 'ru'
39
+ end
40
+ end