moo_moo 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.travis.yml +9 -3
  2. data/LICENSE +1 -1
  3. data/README.md +16 -5
  4. data/Rakefile +21 -0
  5. data/lib/moo_moo/base.rb +93 -0
  6. data/lib/moo_moo/command.rb +36 -0
  7. data/lib/moo_moo/config.rb +26 -1
  8. data/lib/moo_moo/cookie.rb +28 -0
  9. data/lib/moo_moo/dns_zone.rb +45 -0
  10. data/lib/moo_moo/exceptions.rb +1 -1
  11. data/lib/moo_moo/lookup.rb +97 -0
  12. data/lib/moo_moo/middleware/open_srs_errors.rb +12 -0
  13. data/lib/moo_moo/middleware/open_srs_xml_builder.rb +101 -0
  14. data/lib/moo_moo/middleware/parse_open_srs.rb +58 -0
  15. data/lib/moo_moo/nameserver.rb +29 -0
  16. data/lib/moo_moo/provisioning.rb +62 -0
  17. data/lib/moo_moo/response.rb +39 -0
  18. data/lib/moo_moo/transfer.rb +60 -0
  19. data/lib/moo_moo/version.rb +1 -1
  20. data/lib/moo_moo.rb +18 -3
  21. data/moo_moo.gemspec +7 -5
  22. data/spec/fixtures/success_response.xml +14 -0
  23. data/spec/integration_spec.rb +15 -0
  24. data/spec/moo_moo/base_spec.rb +77 -0
  25. data/spec/moo_moo/command_spec.rb +42 -0
  26. data/spec/moo_moo/config_spec.rb +38 -0
  27. data/spec/moo_moo/cookie_spec.rb +8 -0
  28. data/spec/moo_moo/dns_zone_spec.rb +11 -0
  29. data/spec/moo_moo/lookup_spec.rb +18 -0
  30. data/spec/moo_moo/middleware/open_srs_xml_builder_spec.rb +53 -0
  31. data/spec/moo_moo/nameserver_spec.rb +8 -0
  32. data/spec/moo_moo/provisioning_spec.rb +14 -0
  33. data/spec/moo_moo/transfer_spec.rb +12 -0
  34. data/spec/moo_moo_spec.rb +1 -1
  35. data/spec/spec_helper.rb +35 -23
  36. data/spec/vcr_cassettes/integration/lookup.yml +44 -0
  37. metadata +117 -153
  38. data/lib/cacert.pem +0 -3910
  39. data/lib/moo_moo/opensrs/args.rb +0 -109
  40. data/lib/moo_moo/opensrs/base.rb +0 -73
  41. data/lib/moo_moo/opensrs/command.rb +0 -190
  42. data/lib/moo_moo/opensrs/cookie_commands.rb +0 -52
  43. data/lib/moo_moo/opensrs/lookup_commands.rb +0 -195
  44. data/lib/moo_moo/opensrs/nameserver_commands.rb +0 -70
  45. data/lib/moo_moo/opensrs/provisioning_commands.rb +0 -167
  46. data/lib/moo_moo/opensrs/response.rb +0 -41
  47. data/lib/moo_moo/opensrs/transfer_commands.rb +0 -83
  48. data/lib/moo_moo/opensrs.rb +0 -13
  49. data/spec/moo_moo/opensrs/args_spec.rb +0 -176
  50. data/spec/moo_moo/opensrs/base_spec.rb +0 -22
  51. data/spec/moo_moo/opensrs/cookie_spec.rb +0 -76
  52. data/spec/moo_moo/opensrs/lookup_spec.rb +0 -208
  53. data/spec/moo_moo/opensrs/nameserver_spec.rb +0 -136
  54. data/spec/moo_moo/opensrs/provisioning_spec.rb +0 -198
  55. data/spec/moo_moo/opensrs/transfer_spec.rb +0 -124
  56. data/spec/vcr_cassettes/cookie/delete_cookie.yml +0 -219
  57. data/spec/vcr_cassettes/cookie/quit_session.yml +0 -97
  58. data/spec/vcr_cassettes/cookie/set_cookie.yml +0 -123
  59. data/spec/vcr_cassettes/cookie/set_cookie_fail.yml +0 -54
  60. data/spec/vcr_cassettes/cookie/update_cookie.yml +0 -239
  61. data/spec/vcr_cassettes/lookup/belongs_to_rsp.yml +0 -54
  62. data/spec/vcr_cassettes/lookup/belongs_to_rsp_negative.yml +0 -55
  63. data/spec/vcr_cassettes/lookup/get_balance.yml +0 -55
  64. data/spec/vcr_cassettes/lookup/get_deleted_domains.yml +0 -80
  65. data/spec/vcr_cassettes/lookup/get_domain.yml +0 -211
  66. data/spec/vcr_cassettes/lookup/get_domain_fail.yml +0 -269
  67. data/spec/vcr_cassettes/lookup/get_domains_by_expiredate.yml +0 -76
  68. data/spec/vcr_cassettes/lookup/get_domains_contacts.yml +0 -129
  69. data/spec/vcr_cassettes/lookup/get_domains_contacts_fail.yml +0 -58
  70. data/spec/vcr_cassettes/lookup/get_notes_for_domain.yml +0 -85
  71. data/spec/vcr_cassettes/lookup/get_notes_for_order.yml +0 -61
  72. data/spec/vcr_cassettes/lookup/get_notes_for_transfer.yml +0 -61
  73. data/spec/vcr_cassettes/lookup/get_order_info.yml +0 -139
  74. data/spec/vcr_cassettes/lookup/get_orders_by_domain.yml +0 -76
  75. data/spec/vcr_cassettes/lookup/get_price.yml +0 -54
  76. data/spec/vcr_cassettes/lookup/get_product_info.yml +0 -49
  77. data/spec/vcr_cassettes/lookup/lookup_domain_available.yml +0 -55
  78. data/spec/vcr_cassettes/lookup/lookup_domain_registered.yml +0 -55
  79. data/spec/vcr_cassettes/lookup/name_suggest.yml +0 -396
  80. data/spec/vcr_cassettes/nameserver/create.yml +0 -49
  81. data/spec/vcr_cassettes/nameserver/delete.yml +0 -49
  82. data/spec/vcr_cassettes/nameserver/get.yml +0 -71
  83. data/spec/vcr_cassettes/nameserver/modify.yml +0 -49
  84. data/spec/vcr_cassettes/provisioning/cancel_order.yml +0 -56
  85. data/spec/vcr_cassettes/provisioning/cancel_order_invalid.yml +0 -49
  86. data/spec/vcr_cassettes/provisioning/cancel_pending_orders.yml +0 -58
  87. data/spec/vcr_cassettes/provisioning/modify_all_domains.yml +0 -49
  88. data/spec/vcr_cassettes/provisioning/modify_domain.yml +0 -49
  89. data/spec/vcr_cassettes/provisioning/process_pending.yml +0 -57
  90. data/spec/vcr_cassettes/provisioning/register_domain.yml +0 -57
  91. data/spec/vcr_cassettes/provisioning/register_pending_domain.yml +0 -55
  92. data/spec/vcr_cassettes/provisioning/register_taken_domain.yml +0 -55
  93. data/spec/vcr_cassettes/provisioning/renew_domain.yml +0 -58
  94. data/spec/vcr_cassettes/provisioning/revoke_domain.yml +0 -55
  95. data/spec/vcr_cassettes/provisioning/trust_service.yml +0 -60
  96. data/spec/vcr_cassettes/provisioning/update_contacts.yml +0 -66
  97. data/spec/vcr_cassettes/transfer/cancel_transfer.yml +0 -49
  98. data/spec/vcr_cassettes/transfer/cancel_trasnfer_order.yml +0 -49
  99. data/spec/vcr_cassettes/transfer/check_transfer.yml +0 -56
  100. data/spec/vcr_cassettes/transfer/check_transfer_exists.yml +0 -57
  101. data/spec/vcr_cassettes/transfer/get_transfers_away.yml +0 -60
  102. data/spec/vcr_cassettes/transfer/get_transfers_in.yml +0 -80
  103. data/spec/vcr_cassettes/transfer/process_transfer.yml +0 -49
  104. data/spec/vcr_cassettes/transfer/process_transfer_unsuccessful.yml +0 -49
  105. data/spec/vcr_cassettes/transfer/rsp2rsp_push_transfer.yml +0 -49
  106. data/spec/vcr_cassettes/transfer/send_password.yml +0 -49
  107. data/spec/vcr_cassettes/transfer/transfer.yml +0 -58
@@ -0,0 +1,62 @@
1
+ module MooMoo
2
+ class Provisioning < Base
3
+
4
+ ##
5
+ # Cancels a Trust Service order
6
+ register_service :cancel_order, :trust_service
7
+
8
+ ##
9
+ # Cancels orders with a status of pending or declined.
10
+ #
11
+ # http://www.opensrs.com/docs/apidomains/cancel_pending_orders.htm
12
+ register_service :cancel_pending_orders, :order
13
+
14
+ ##
15
+ # Changes information associated with a domain, such as contact info. The action request message
16
+ # is different depending on the type of modification being made, and is shown separately for each
17
+ # type.
18
+ #
19
+ # http://www.opensrs.com/docs/apidomains/modify_domain.htm
20
+ register_service :modify, :domain
21
+
22
+ ##
23
+ # Processes or cancels pending orders; also applicable to any order that is declined. The order
24
+ # is cancelled and a new order is created. Can also be used to process cancelled orders, provided
25
+ # the cancelled order was a new order or a transfer.
26
+ #
27
+ # http://www.opensrs.com/docs/apidomains/process_pending.htm
28
+ register_service :process_pending, :domain
29
+
30
+ ##
31
+ # Renews a domain and allows you to set the auto-renewal flag on a domain.
32
+ #
33
+ # http://www.opensrs.com/docs/apidomains/renew_domain.htm
34
+ register_service :renew_domain, :domain, :renew
35
+
36
+ ##
37
+ # Removes the domain at the registry. Use this command to request a refund for a domain purchase.
38
+ # This call can refund/revoke only one domain at the time.
39
+ #
40
+ # http://www.opensrs.com/docs/apidomains/revoke_domain.htm
41
+ register_service :revoke, :domain
42
+
43
+ ##
44
+ # Submits a domain-contact information update to the OpenSRS system. Each contact object is
45
+ # submitted as a whole to OpenSRS, and changes are parsed against the existing information.
46
+ #
47
+ # http://www.opensrs.com/docs/apidomains/update_contacts.htm
48
+ register_service :update_contacts, :domain
49
+
50
+ ##
51
+ # Submits a new domain registration or transfer order that obeys the Reseller's 'process
52
+ # immediately' flag setting.
53
+ #
54
+ # http://www.opensrs.com/docs/apidomains/sw_register.htm
55
+ # Note: Requirements vary depending on TLD
56
+ register_service :register_domain, :domain, :sw_register
57
+
58
+ ##
59
+ # Submits a new registration request or transfer order
60
+ register_service :register_trust_service, :trust_service
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ module MooMoo
2
+ class Response
3
+ # Constructor
4
+ #
5
+ # ==== Required
6
+ # * <tt>:hash</tt> - hash of the response
7
+ #
8
+ # ==== Optional
9
+ # * <tt>:key</tt> - primary key to use when indexing the hash
10
+ def initialize(hash, key = nil)
11
+ @hash = hash
12
+ @key = key
13
+ end
14
+
15
+ # Returns whether or not the command executed was successful
16
+ #
17
+ def success?
18
+ @hash['is_success'].nil? ? true : @hash['is_success'].to_i == 1
19
+ end
20
+
21
+ # Returns the error message if one is present
22
+ #
23
+ def error_msg
24
+ @hash['response_text']
25
+ end
26
+
27
+ # Returns the response code if one is present
28
+ #
29
+ def error_code
30
+ @hash['response_code'].to_i
31
+ end
32
+
33
+ # Returns the result hash
34
+ #
35
+ def result
36
+ @key.nil? ? @hash : @hash[@key]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ module MooMoo
2
+ class Transfer < Base
3
+
4
+ ##
5
+ # Cancels transfers that are pending owner approval.
6
+ #
7
+ # http://www.opensrs.com/docs/apidomains/cancel_transfer.htm
8
+ register_service :cancel_transfer, :transfer
9
+
10
+ ##
11
+ # Cancels a transfer that is pending owner approval by order ID
12
+ #
13
+ # Note: This method may be deprecated
14
+ register_service :cancel_transfer_for_order, :transfer
15
+
16
+ ##
17
+ # Checks to see if the specified domain can be transferred in to OpenSRS, or transferred from one
18
+ # OpenSRS Reseller to another. This call can also be used to check the status of the last transfer
19
+ # request on a given domain name.
20
+ #
21
+ # http://www.opensrs.com/docs/apidomains/check_transfer.htm
22
+ register_service :check_transfer, :domain
23
+
24
+ ##
25
+ # Lists domains that have been transferred away. This command applies to all domains in a
26
+ # Reseller's profile.
27
+ #
28
+ # http://www.opensrs.com/docs/apidomains/get_transfers_away.htm
29
+ register_service :get_transfers_away, :domain
30
+
31
+ ##
32
+ # Lists domains that have been transferred in. This command applies to all domains in a Reseller's
33
+ # profile.
34
+ #
35
+ # http://www.opensrs.com/docs/apidomains/get_transfers_in.htm
36
+ register_service :get_transfers_in, :domain
37
+
38
+ ##
39
+ # Creates a new order with the same data as a cancelled order; the existing cancelled order is
40
+ # not modified. This command is only available for failed transfers with the status of 'cancelled'.
41
+ #
42
+ # http://www.opensrs.com/docs/apidomains/process_transfer.htm
43
+ register_service :process_transfer, :transfer
44
+
45
+ ##
46
+ # Resends an email message for a transfer that is in 'pending owner approval' state, to the admin
47
+ # contact listed for the domain at the time that the transfer request was submitted. If a transfer
48
+ # is currently in progress, but in a different state, an error is returned.
49
+ #
50
+ # http://www.opensrs.com/docs/apidomains/send_password_transfer.htm
51
+ register_service :send_password, :transfer
52
+
53
+ ##
54
+ # Transfer a domain from one Reseller to another Reseller. The domain is not renewed when it is
55
+ # transferred and so no charges are incurred.
56
+ #
57
+ # http://www.opensrs.com/docs/apidomains/rsp2rsp_push_transfer.htm
58
+ register_service :push_transfer, :domain, :rsp2rsp_push_transfer
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module MooMoo
2
- VERSION = Version = "0.1.1"
2
+ VERSION = Version = "0.2.0"
3
3
  end
data/lib/moo_moo.rb CHANGED
@@ -1,9 +1,21 @@
1
1
  require 'moo_moo/exceptions'
2
+ require 'faraday'
2
3
 
3
4
  module MooMoo
4
- autoload :Version, 'moo_moo/version'
5
- autoload :Config, 'moo_moo/config'
6
- autoload :OpenSRS, 'moo_moo/opensrs'
5
+ autoload :Version, 'moo_moo/version'
6
+ autoload :Config, 'moo_moo/config'
7
+ autoload :Command, 'moo_moo/command'
8
+ autoload :Response, 'moo_moo/response'
9
+ autoload :Base, 'moo_moo/base'
10
+ autoload :Lookup, 'moo_moo/lookup'
11
+ autoload :Nameserver, 'moo_moo/nameserver'
12
+ autoload :Provisioning, 'moo_moo/provisioning'
13
+ autoload :Transfer, 'moo_moo/transfer'
14
+ autoload :DnsZone, 'moo_moo/dns_zone'
15
+ autoload :Cookie, 'moo_moo/cookie'
16
+ autoload :OpenSRSErrors, 'moo_moo/middleware/open_srs_errors'
17
+ autoload :ParseOpenSRS, 'moo_moo/middleware/parse_open_srs'
18
+ autoload :OpenSRSXMLBuilder, 'moo_moo/middleware/open_srs_xml_builder'
7
19
 
8
20
  class << self
9
21
  attr_accessor :config
@@ -16,3 +28,6 @@ module MooMoo
16
28
 
17
29
  self.config = Config.new
18
30
  end
31
+
32
+ Faraday.register_middleware :request, :open_srs_xml_builder => MooMoo::OpenSRSXMLBuilder
33
+ Faraday.register_middleware :response, :open_srs_errors => MooMoo::OpenSRSErrors, :parse_open_srs => MooMoo::ParseOpenSRS
data/moo_moo.gemspec CHANGED
@@ -14,14 +14,16 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "opensrs"
16
16
 
17
- s.add_runtime_dependency('jruby-openssl', '~> 0.7.3') if RUBY_PLATFORM == 'java'
17
+ s.add_runtime_dependency 'extlib', '~> 0.9.15'
18
+ s.add_runtime_dependency 'faraday', '~> 0.8.0.rc2'
19
+ s.add_runtime_dependency 'jruby-openssl', '~> 0.7.3' if RUBY_PLATFORM == 'java'
20
+
18
21
  s.add_development_dependency 'rake', '~> 0.9.2.2'
19
- s.add_development_dependency 'rspec', '~> 2.8.0'
20
- s.add_development_dependency 'fakeweb', '~> 1.3.0'
22
+ s.add_development_dependency 'rspec', '~> 2.10.0'
23
+ s.add_development_dependency 'rdoc', '~> 3.12'
24
+ s.add_development_dependency 'webmock', '~> 1.8.7'
21
25
  s.add_development_dependency 'vcr', '~> 1.11.3'
22
26
 
23
- s.add_dependency 'extlib'
24
-
25
27
  s.files = `git ls-files`.split("\n")
26
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
29
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,14 @@
1
+ <?xml version='1.0' encoding="UTF-8" standalone="no" ?>
2
+ <!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
3
+ <OPS_envelope>
4
+ <header>
5
+ <version>0.9</version>
6
+ </header>
7
+ <body>
8
+ <data_block>
9
+ <dt_assoc>
10
+ <item key="response_text">Command Successful</item>
11
+ </dt_assoc>
12
+ </data_block>
13
+ </body>
14
+ </OPS_envelope>
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Real World integration" do
4
+
5
+ it "Lookup should work" do
6
+ lookup = MooMoo::Lookup.new
7
+
8
+ VCR.use_cassette("integration/lookup") do
9
+ response = lookup.lookup_domain(:domain => "opensrs.net")
10
+ pp response
11
+ response.result["status"].should == "taken"
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ class SampleService < MooMoo::Base
4
+ register_service :service1, :object1
5
+ register_service :service2, :object2, :action2
6
+ register_service :service3, :object3 do |params|
7
+ params[:example] = "theexample"
8
+ end
9
+ end
10
+
11
+ describe MooMoo::Base do
12
+
13
+ before :each do
14
+ @service = SampleService.new("thehost", "thekey", "theuser", "thepass", "theport")
15
+ end
16
+
17
+ describe "class methods" do
18
+ describe "#register_service" do
19
+ context "calls the services with the given parameters" do
20
+ it "service1" do
21
+ params = {:the => :params, :cookie => "thecookie"}
22
+
23
+ @service.should_receive(:run_command).
24
+ with(:service1, :object1, params, "thecookie").
25
+ and_return("theresult")
26
+
27
+ @service.service1(params).should == "theresult"
28
+ end
29
+
30
+ it "service2" do
31
+ params = {:the => :params, :cookie => "thecookie"}
32
+
33
+ @service.should_receive(:run_command).
34
+ with(:action2, :object2, params, "thecookie").
35
+ and_return("theresult")
36
+
37
+ @service.service2(params).should == "theresult"
38
+ end
39
+
40
+ it "service3" do
41
+ params = {:the => :params, :cookie => "thecookie"}
42
+ expected_params = {:the => :params, :key => "attributes", :example => "theexample"}
43
+
44
+ @service.should_receive(:run_command).
45
+ with(:service3, :object3, expected_params, "thecookie").
46
+ and_return("theresult")
47
+
48
+ @service.service3(params).should == "theresult"
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#run_command" do
55
+ it "should encapsulate response" do
56
+ result = {:the => :result}
57
+ command = stub()
58
+ command.should_receive(:run).with("thehost", "thekey", "theuser", "theport").and_return(result)
59
+ MooMoo::Command.should_receive(:new).
60
+ with("theaction", "theobject", {}, "thecookie").
61
+ and_return(command)
62
+
63
+ response = @service.run_command("theaction", "theobject", {}, "thecookie")
64
+ response.result.should == result
65
+ end
66
+ end
67
+
68
+ describe "#try_opensrs" do
69
+ it "raises an OpenSRSException" do
70
+ expect do
71
+ MooMoo::Base.new.instance_eval do
72
+ try_opensrs { raise "Exception message" }
73
+ end
74
+ end.to raise_error MooMoo::OpenSRSException
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe MooMoo::Command do
4
+
5
+ let(:action) { "theaction" }
6
+ let(:object) { "theobject" }
7
+ let(:params) { {
8
+ :string => "stringparam",
9
+ :hash => {:the => "hashparam"},
10
+ :array => [{:param => "arrayvalue1"}, {:param => "arrayvalue2"}],
11
+ :array_list => ["arrayvalue1", "arrayvalue2"]
12
+ } }
13
+ let(:cookie) { "thecookie" }
14
+
15
+ let(:command) { MooMoo::Command.new(action, object, params, cookie) }
16
+
17
+ describe "#run" do
18
+ describe "success response" do
19
+ let(:xml) { "xmlcontent" }
20
+ let(:response) { {:status => 200, :body => File.open("spec/fixtures/success_response.xml")} }
21
+
22
+ before :each do
23
+ @request = stub_request(:post, "https://thehost.com:12345/").to_return(response)
24
+ @response = command.run("thehost.com", "thekey", "theuser", "12345")
25
+ end
26
+
27
+ it "posts with correct parameters" do
28
+ @request.should have_been_made
29
+ end
30
+
31
+ it "returns the response" do
32
+ @response["response_text"].should == "Command Successful"
33
+ end
34
+ end
35
+
36
+ it "raises exception on invalid http status" do
37
+ stub_request(:post, "https://thehost:12345/").to_return(:status => ["401", "Unauthorized"])
38
+ lambda { command.run("thehost", "thekey", "theuser", "12345") }.should raise_error(MooMoo::OpenSRSException, "Bad HTTP Status: 401")
39
+ end
40
+ end
41
+
42
+ end
@@ -9,4 +9,42 @@ describe MooMoo::Config do
9
9
  it { @config.should have_attr_accessor :key }
10
10
  it { @config.should have_attr_accessor :user }
11
11
  it { @config.should have_attr_accessor :pass }
12
+ it { @config.should have_attr_accessor :port }
13
+
14
+ describe "default configuration" do
15
+ before :each do
16
+ File.should_receive(:exists?).with(".moomoo.yml").and_return(true)
17
+ File.should_receive(:open).with(".moomoo.yml").and_return(
18
+ "
19
+ host: thehost
20
+ key: thekey
21
+ user: theuser
22
+ pass: thepass
23
+ port: theport
24
+ "
25
+ )
26
+
27
+ @config = MooMoo::Config.new
28
+ end
29
+
30
+ it "should set default host from default options file" do
31
+ @config.host.should == "thehost"
32
+ end
33
+
34
+ it "should set default key from default options file" do
35
+ @config.key.should == "thekey"
36
+ end
37
+
38
+ it "should set default user from default options file" do
39
+ @config.user.should == "theuser"
40
+ end
41
+
42
+ it "should set default pass from default options file" do
43
+ @config.pass.should == "thepass"
44
+ end
45
+
46
+ it "should set default port from default options file" do
47
+ @config.port.should == "theport"
48
+ end
49
+ end
12
50
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe MooMoo::Cookie do
4
+ it { should have_registered_service(:set, :cookie) }
5
+ it { should have_registered_service(:delete, :cookie) }
6
+ it { should have_registered_service(:update, :cookie) }
7
+ it { should have_registered_service(:quit_session, :session, :quit) }
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ describe MooMoo::DnsZone do
5
+ it { should have_registered_service(:create_dns_zone, :domain) }
6
+ it { should have_registered_service(:delete_dns_zone, :domain) }
7
+ it { should have_registered_service(:force_dns_nameservers, :domain) }
8
+ it { should have_registered_service(:get_dns_zone, :domain) }
9
+ it { should have_registered_service(:reset_dns_zone, :domain) }
10
+ it { should have_registered_service(:set_dns_zone, :domain) }
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ describe MooMoo::Lookup do
5
+ it { should have_registered_service(:belongs_to_rsp, :domain) }
6
+ it { should have_registered_service(:get_balance, :balance) }
7
+ it { should have_registered_service(:get_deleted_domains, :domain) }
8
+ it { should have_registered_service(:get_domain, :domain, :get) }
9
+ it { should have_registered_service(:get_domains_contacts, :domain) }
10
+ it { should have_registered_service(:get_domains_by_expiredate, :domain) }
11
+ it { should have_registered_service(:get_notes, :domain) }
12
+ it { should have_registered_service(:get_order_info, :domain) }
13
+ it { should have_registered_service(:get_orders_by_domain, :domain) }
14
+ it { should have_registered_service(:get_price, :domain) }
15
+ it { should have_registered_service(:get_product_info, :trust_service) }
16
+ it { should have_registered_service(:lookup_domain, :domain, :lookup) }
17
+ it { should have_registered_service(:name_suggest, :domain) }
18
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe MooMoo::OpenSRSXMLBuilder do
4
+
5
+ describe "#build_command" do
6
+ before :each do
7
+ params = {
8
+ :string => "stringparam",
9
+ :hash => {:the => "hashparam"},
10
+ :array => [{:param => "arrayvalue1"}, {:param => "arrayvalue2"}],
11
+ :array_list => ["arrayvalue1", "arrayvalue2"]
12
+ }
13
+
14
+ middleware = described_class.new(lambda{|env| env}, "theaction", "theobject", "thecookie", params, "key")
15
+ env = {:body => nil, :request_headers => Faraday::Utils::Headers.new}
16
+ result = middleware.call(env)
17
+ @body = REXML::Document.new(result[:body])
18
+ end
19
+
20
+ it "should set the action" do
21
+ @body.root.elements["body/data_block/dt_assoc/item[@key='action']"].text.should == "theaction"
22
+ end
23
+
24
+ it "should set the object" do
25
+ @body.root.elements["body/data_block/dt_assoc/item[@key='object']"].text.should == "theobject"
26
+ end
27
+
28
+ it "should set the the cookie" do
29
+ @body.root.elements["body/data_block/dt_assoc/item[@key='cookie']"].text.should == "thecookie"
30
+ end
31
+
32
+ describe "attributes" do
33
+ it "should set string params" do
34
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='string']"].text.should == "stringparam"
35
+ end
36
+
37
+ it "should set hash params" do
38
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='hash']/dt_assoc/item[@key='the']"].text.should == "hashparam"
39
+ end
40
+
41
+ it "should set array params" do
42
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='array']/dt_array/item[@key='0']/dt_assoc/item[@key='param']"].text.should == "arrayvalue1"
43
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='array']/dt_array/item[@key='1']/dt_assoc/item[@key='param']"].text.should == "arrayvalue2"
44
+ end
45
+
46
+ it "should set array list params" do
47
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='array_list']/dt_array/item[@key='0']"].text.should == "arrayvalue1"
48
+ @body.root.elements["body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='array_list']/dt_array/item[@key='1']"].text.should == "arrayvalue2"
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe MooMoo::Nameserver do
4
+ it { should have_registered_service(:create, :nameserver) }
5
+ it { should have_registered_service(:delete, :nameserver) }
6
+ it { should have_registered_service(:get, :nameserver) }
7
+ it { should have_registered_service(:modify, :nameserver) }
8
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ describe MooMoo::Provisioning do
5
+ it { should have_registered_service(:cancel_order, :trust_service) }
6
+ it { should have_registered_service(:cancel_pending_orders, :order) }
7
+ it { should have_registered_service(:modify, :domain) }
8
+ it { should have_registered_service(:process_pending, :domain) }
9
+ it { should have_registered_service(:renew_domain, :domain, :renew) }
10
+ it { should have_registered_service(:revoke, :domain) }
11
+ it { should have_registered_service(:update_contacts, :domain) }
12
+ it { should have_registered_service(:register_domain, :domain, :sw_register) }
13
+ it { should have_registered_service(:register_trust_service, :trust_service) }
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe MooMoo::Transfer do
4
+ it { should have_registered_service(:cancel_transfer, :transfer) }
5
+ it { should have_registered_service(:cancel_transfer_for_order, :transfer) }
6
+ it { should have_registered_service(:check_transfer, :domain) }
7
+ it { should have_registered_service(:get_transfers_away, :domain) }
8
+ it { should have_registered_service(:get_transfers_in, :domain) }
9
+ it { should have_registered_service(:process_transfer, :transfer) }
10
+ it { should have_registered_service(:send_password, :transfer) }
11
+ it { should have_registered_service(:push_transfer, :domain, :rsp2rsp_push_transfer) }
12
+ end
data/spec/moo_moo_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe MooMoo do
18
18
  config.pass = 'secret2'
19
19
  end
20
20
 
21
- opensrs = MooMoo::OpenSRS::Base.new
21
+ opensrs = MooMoo::Base.new
22
22
 
23
23
  opensrs.host.should == 'host.com'
24
24
  opensrs.key.should == 'secret'
data/spec/spec_helper.rb CHANGED
@@ -1,24 +1,18 @@
1
1
  require 'rspec'
2
2
  require 'moo_moo'
3
+ require 'webmock/rspec'
3
4
  require 'vcr'
4
5
  require 'extlib'
5
6
 
6
- MooMoo.configure do |config|
7
- config.host = ENV['OPENSRS_TEST_URL']
8
- config.key = ENV['OPENSRS_TEST_KEY']
9
- config.user = ENV['OPENSRS_TEST_USER']
10
- config.pass = ENV['OPENSRS_TEST_PASS']
11
- end
12
-
13
7
  VCR.config do |c|
14
8
  c.cassette_library_dir = 'spec/vcr_cassettes'
15
- c.stub_with :fakeweb
9
+ c.stub_with :webmock
16
10
 
17
- c.default_cassette_options = {:record => :new_episodes, :match_requests_on => [:uri]}
11
+ c.default_cassette_options = {:record => :none, :match_requests_on => [:uri]}
18
12
  end
19
13
 
20
14
  def requires_attr(attr, &block)
21
- expect { block.call }.to raise_error(MooMoo::MooMooArgumentError, /Missing required parameter: #{attr}/i)
15
+ expect { block.call }.to raise_error(MooMoo::ArgumentError, /Missing required parameter: #{attr}/i)
22
16
  end
23
17
 
24
18
  def live_test?
@@ -59,19 +53,17 @@ end
59
53
  RSpec.configure do |c|
60
54
  c.extend VCR::RSpec::Macros
61
55
  c.before(:each) do
62
- if live_test?
63
- MooMoo.configure do |config|
64
- config.host = ENV['OPENSRS_TEST_URL']
65
- config.key = ENV['OPENSRS_TEST_KEY']
66
- config.user = ENV['OPENSRS_TEST_USER']
67
- config.pass = ENV['OPENSRS_TEST_PASS']
68
- end
69
- else
70
- MooMoo.configure do |config|
71
- config.host = 'server.com'
72
- config.key = '123key'
73
- config.user = 'opensrs_user'
74
- config.pass = 'password'
56
+ MooMoo.configure do |config|
57
+ if live_test?
58
+ config.host = ENV['OPENSRS_TEST_URL'] if ENV['OPENSRS_TEST_URL']
59
+ config.key = ENV['OPENSRS_TEST_KEY'] || raise(ArgumentError, "OPENSRS_TEST_KEY is required")
60
+ config.user = ENV['OPENSRS_TEST_USER'] || raise(ArgumentError, "OPENSRS_TEST_USER is required")
61
+ config.pass = ENV['OPENSRS_TEST_PASS'] || raise(ArgumentError, "OPENSRS_TEST_PASS is required")
62
+ else
63
+ config.host = "testhost.com"
64
+ config.key = "testkey"
65
+ config.user = "testuser"
66
+ config.pass = "testpass"
75
67
  end
76
68
  end
77
69
  end
@@ -86,3 +78,23 @@ RSpec::Matchers.define :have_attr_accessor do |attribute|
86
78
  "have attr_accessor :#{attribute}"
87
79
  end
88
80
  end
81
+
82
+ RSpec::Matchers.define(:have_registered_service) do |*args|
83
+ method_name = args[0]
84
+ object_name = args[1]
85
+ action_name = args[2] || method_name
86
+
87
+ match do |object|
88
+ parameters = {:the => :params, :cookie => "thecookie"}
89
+ object.should_receive(:run_command).
90
+ with(action_name, object_name, parameters, "thecookie").
91
+ and_return("theresult")
92
+
93
+
94
+ object.send(method_name, parameters) == "theresult"
95
+ end
96
+
97
+ description do
98
+ "have registered service :#{method_name} delegating to action :#{action_name} and object :#{object_name}"
99
+ end
100
+ end