moo_moo 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -6
- data/lib/moo_moo/{base.rb → base_command.rb} +48 -18
- data/lib/moo_moo/middleware/parse_open_srs.rb +1 -3
- data/lib/moo_moo/services/cookie.rb +2 -2
- data/lib/moo_moo/services/dns_zone.rb +4 -4
- data/lib/moo_moo/services/lookup.rb +40 -5
- data/lib/moo_moo/services/nameserver.rb +1 -1
- data/lib/moo_moo/services/provisioning.rb +47 -3
- data/lib/moo_moo/services/transfer.rb +2 -2
- data/lib/moo_moo/version.rb +1 -1
- data/lib/moo_moo.rb +1 -3
- data/spec/integration_spec.rb +2 -2
- data/spec/moo_moo/base_command_spec.rb +79 -0
- data/spec/moo_moo/services/cookie_spec.rb +1 -1
- data/spec/moo_moo/services/lookup_spec.rb +53 -3
- data/spec/moo_moo/services/provisioning_spec.rb +86 -2
- data/spec/moo_moo/services/transfer_spec.rb +1 -1
- data/spec/moo_moo_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -4
- metadata +7 -13
- data/lib/moo_moo/command.rb +0 -32
- data/lib/moo_moo/response.rb +0 -34
- data/spec/moo_moo/base_spec.rb +0 -68
- data/spec/moo_moo/command_spec.rb +0 -41
- data/spec/moo_moo/response_spec.rb +0 -43
data/README.md
CHANGED
@@ -51,15 +51,18 @@ configuration for the library to use.
|
|
51
51
|
Now you can call a variety of commands to deal with domains, nameservers, etc.
|
52
52
|
Here's how to check the availability of a domain name:
|
53
53
|
|
54
|
-
|
55
|
-
p
|
54
|
+
lookup.api_lookup(:attributes => { :domain => 'example.com' })
|
55
|
+
p lookup.successful?
|
56
56
|
|
57
57
|
true
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
After calling the service method, you can use the following methods to access
|
60
|
+
the response:
|
61
|
+
|
62
|
+
response - the http response
|
63
|
+
message - the "response_text"
|
64
|
+
attributes - the "attributes" hash with relevant data
|
65
|
+
successful? - wheater the request was successful or not
|
63
66
|
|
64
67
|
Currently, there is support for the following services:
|
65
68
|
|
@@ -69,6 +72,14 @@ Currently, there is support for the following services:
|
|
69
72
|
* Provisioning
|
70
73
|
* Transfer
|
71
74
|
|
75
|
+
API services are namespaced with api. For example, for the Lookup "get" api method,
|
76
|
+
it will be named "api_get".
|
77
|
+
|
78
|
+
MooMoo provides custom methods that should make it easier to deal with the OpenSRS
|
79
|
+
api (e.g. Lookup :domain_contacts). This custom methods are not namespaced.
|
80
|
+
Check their documentation to see what parameters does it expect and what responses
|
81
|
+
does it return.
|
82
|
+
|
72
83
|
Note on Patches/Pull Requests
|
73
84
|
-----------------------------
|
74
85
|
|
@@ -1,28 +1,33 @@
|
|
1
1
|
module MooMoo
|
2
|
-
|
3
|
-
|
2
|
+
# Defines the basic command structure.
|
3
|
+
#
|
4
|
+
# For OpenSRS api methods, create them like this, using the proper api action
|
5
|
+
# name and object:
|
6
|
+
#
|
7
|
+
# register_service :action_one, :object_one
|
8
|
+
#
|
9
|
+
# If you need customized responses, create a custom method:
|
10
|
+
#
|
11
|
+
# def custom_action(parameter)
|
12
|
+
# api_action_one(... custom parameter ...)
|
13
|
+
# ... custom response processing ...
|
14
|
+
# end
|
15
|
+
class BaseCommand
|
16
|
+
attr_reader :host, :key, :username, :password, :port, :response
|
4
17
|
|
5
18
|
# Register an api service for the current class.
|
6
19
|
#
|
7
20
|
# register_service :action_one, :object_one
|
8
21
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# def action_one(params)
|
12
|
-
# run_command :action_one, :object_one, params, cookie
|
13
|
-
# end
|
22
|
+
# A method called "api_action_one" will then be created.
|
14
23
|
#
|
15
24
|
# === Parameters
|
16
25
|
#
|
17
|
-
# * <tt>
|
26
|
+
# * <tt>action_name</tt> - the api action to be called
|
18
27
|
# * <tt>object</tt> - the object
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
params = args.first || {}
|
23
|
-
|
24
|
-
instance_exec(params, &block) if block
|
25
|
-
run_command action_name, object, params
|
28
|
+
def self.register_service(action_name, object)
|
29
|
+
define_method("api_#{action_name}") do |*args|
|
30
|
+
perform(action_name, object, args.first || {})
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
@@ -44,6 +49,23 @@ module MooMoo
|
|
44
49
|
@port = params[:port] || MooMoo.config.port || 55443
|
45
50
|
end
|
46
51
|
|
52
|
+
# Returns whether or not the command executed was successful
|
53
|
+
def successful?
|
54
|
+
response.body['is_success'].to_i == 1
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the response message if one is present
|
58
|
+
def message
|
59
|
+
response.body['response_text']
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the response attributes.
|
63
|
+
def attributes
|
64
|
+
response.body['attributes']
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
47
69
|
# Runs a command
|
48
70
|
#
|
49
71
|
# === Required
|
@@ -52,11 +74,19 @@ module MooMoo
|
|
52
74
|
#
|
53
75
|
# === Optional
|
54
76
|
# * <tt>:params</tt> - parameters for the command
|
55
|
-
def
|
56
|
-
|
77
|
+
def perform(action, object, params = {})
|
78
|
+
(@response = faraday_request(action, object, params)) && attributes
|
57
79
|
end
|
58
80
|
|
59
|
-
|
81
|
+
# Performs the Faraday request.
|
82
|
+
def faraday_request(action, object, params)
|
83
|
+
Faraday.new(:url => "https://#{host}:#{port}", :ssl => {:verify => true}) do |c|
|
84
|
+
c.request :open_srs_xml_builder, action, object, params, key, username
|
85
|
+
c.response :parse_open_srs
|
86
|
+
c.response :open_srs_errors
|
87
|
+
c.adapter :net_http
|
88
|
+
end.post
|
89
|
+
end
|
60
90
|
|
61
91
|
# Indexes an array by building a hash with numeric keys
|
62
92
|
#
|
@@ -21,8 +21,6 @@ module MooMoo
|
|
21
21
|
def parse_response(data)
|
22
22
|
doc = REXML::Document.new(data)
|
23
23
|
|
24
|
-
values = {}
|
25
|
-
|
26
24
|
elements = doc.elements["/OPS_envelope/body/data_block/dt_assoc"].select { |item|
|
27
25
|
item.is_a? REXML::Element
|
28
26
|
}
|
@@ -55,4 +53,4 @@ module MooMoo
|
|
55
53
|
end
|
56
54
|
|
57
55
|
end
|
58
|
-
end
|
56
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module MooMoo
|
2
|
-
class Cookie <
|
2
|
+
class Cookie < BaseCommand
|
3
3
|
|
4
4
|
##
|
5
5
|
# Creates a cookie for use in commands where a cookie is required to access OpenSRS.
|
@@ -23,6 +23,6 @@ module MooMoo
|
|
23
23
|
# Cleanly terminates the connection.
|
24
24
|
#
|
25
25
|
# http://www.opensrs.com/docs/apidomains/quit_session.htm
|
26
|
-
register_service :
|
26
|
+
register_service :quit, :session
|
27
27
|
end
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module MooMoo
|
2
|
-
class DnsZone <
|
2
|
+
class DnsZone < BaseCommand
|
3
3
|
|
4
4
|
##
|
5
5
|
# Creates a custom DNS zone for managed DNS service.
|
@@ -14,7 +14,7 @@ module MooMoo
|
|
14
14
|
register_service :delete_dns_zone, :domain
|
15
15
|
|
16
16
|
##
|
17
|
-
# Changes the nameservers on your domain to use the
|
17
|
+
# Changes the nameservers on your domain to use the
|
18
18
|
# nameservers for managed DNS service.
|
19
19
|
#
|
20
20
|
# http://www.opensrs.com/docs/apidomains/Request_parameters_for_force_dns_nameservers.htm
|
@@ -28,8 +28,8 @@ module MooMoo
|
|
28
28
|
|
29
29
|
##
|
30
30
|
# Sets the DNS zone to the values in the specified template.
|
31
|
-
# If a template is not specified in the command, the records
|
32
|
-
# are set to what was in the template that was used to enable
|
31
|
+
# If a template is not specified in the command, the records
|
32
|
+
# are set to what was in the template that was used to enable
|
33
33
|
# the DNS service.
|
34
34
|
#
|
35
35
|
# http://www.opensrs.com/docs/apidomains/reset_dns_zone_request.htm
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module MooMoo
|
2
|
-
class Lookup <
|
3
|
-
|
2
|
+
class Lookup < BaseCommand
|
4
3
|
##
|
5
4
|
# Determines whether the domain belongs to the RSP who issued the command.
|
6
5
|
#
|
@@ -30,9 +29,8 @@ module MooMoo
|
|
30
29
|
# returns the nameservers currently acting as DNS servers for the domain.
|
31
30
|
#
|
32
31
|
# http://www.opensrs.com/docs/apidomains/get_domain.htm
|
33
|
-
register_service :
|
32
|
+
register_service :get, :domain
|
34
33
|
|
35
|
-
##
|
36
34
|
# Queries contact information for a list of domains.
|
37
35
|
#
|
38
36
|
# http://www.opensrs.com/docs/apidomains/get_domains_contacts.htm
|
@@ -84,7 +82,7 @@ module MooMoo
|
|
84
82
|
# Determines the availability of a specified domain name.
|
85
83
|
#
|
86
84
|
# http://www.opensrs.com/docs/apidomains/lookup_domain.htm
|
87
|
-
register_service :
|
85
|
+
register_service :lookup, :domain
|
88
86
|
|
89
87
|
##
|
90
88
|
# Checks whether a specified name, word, or phrase is available for registration in gTLDs and
|
@@ -93,5 +91,42 @@ module MooMoo
|
|
93
91
|
#
|
94
92
|
# http://www.opensrs.com/docs/apidomains/name_suggest_domain.htm
|
95
93
|
register_service :name_suggest, :domain
|
94
|
+
|
95
|
+
##
|
96
|
+
# Queries contact information for a domain using get_domains_contacts.
|
97
|
+
#
|
98
|
+
# * <tt>:domain</tt> - the domain to query for. E.g.: "domain1.com"
|
99
|
+
#
|
100
|
+
# Returns an array like:
|
101
|
+
# [
|
102
|
+
# {
|
103
|
+
# :type => "type", # admin, billing, etc
|
104
|
+
# :first_name => "first_name",
|
105
|
+
# :last_name => "last_name"
|
106
|
+
# ... other attributes ...
|
107
|
+
# }
|
108
|
+
# ]
|
109
|
+
def domain_contacts(domain)
|
110
|
+
api_get_domains_contacts({ :attributes => { :domain_list => [domain] }})
|
111
|
+
|
112
|
+
attributes[domain]["contact_set"].map do |(type, attributes)|
|
113
|
+
{
|
114
|
+
:type => type,
|
115
|
+
:first_name => attributes["first_name"],
|
116
|
+
:last_name => attributes["last_name"],
|
117
|
+
:org_name => attributes["org_name"],
|
118
|
+
:address1 => attributes["address1"],
|
119
|
+
:address2 => attributes["address2"],
|
120
|
+
:address3 => attributes["address3"],
|
121
|
+
:city => attributes["city"],
|
122
|
+
:state => attributes["state"],
|
123
|
+
:country => attributes["country"],
|
124
|
+
:postal_code =>attributes["postal_code"],
|
125
|
+
:phone => attributes["phone"],
|
126
|
+
:fax => attributes["fax"],
|
127
|
+
:email => attributes["email"]
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
96
131
|
end
|
97
132
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module MooMoo
|
2
|
-
class Provisioning <
|
2
|
+
class Provisioning < BaseCommand
|
3
3
|
|
4
4
|
##
|
5
5
|
# Cancels a Trust Service order
|
@@ -31,7 +31,7 @@ module MooMoo
|
|
31
31
|
# Renews a domain and allows you to set the auto-renewal flag on a domain.
|
32
32
|
#
|
33
33
|
# http://www.opensrs.com/docs/apidomains/renew_domain.htm
|
34
|
-
register_service :
|
34
|
+
register_service :renew, :domain
|
35
35
|
|
36
36
|
##
|
37
37
|
# Removes the domain at the registry. Use this command to request a refund for a domain purchase.
|
@@ -53,10 +53,54 @@ module MooMoo
|
|
53
53
|
#
|
54
54
|
# http://www.opensrs.com/docs/apidomains/sw_register.htm
|
55
55
|
# Note: Requirements vary depending on TLD
|
56
|
-
register_service :
|
56
|
+
register_service :sw_register, :domain
|
57
57
|
|
58
58
|
##
|
59
59
|
# Submits a new registration request or transfer order
|
60
60
|
register_service :register_trust_service, :trust_service
|
61
|
+
|
62
|
+
##
|
63
|
+
# Updates contact information for a domain using modify.
|
64
|
+
#
|
65
|
+
# * <tt>:domain</tt> - the domain to update for. E.g.: "domain1.com"
|
66
|
+
# * <tt>:attributes</tt> - a contact attributes hash like:
|
67
|
+
# {
|
68
|
+
# type: "type", # admin, billing, etc
|
69
|
+
# first_name: "first_name",
|
70
|
+
# last_name: "last_name"
|
71
|
+
# ... other attributes ...
|
72
|
+
# }
|
73
|
+
#
|
74
|
+
# In case of errors, an errors array like this will be returned:
|
75
|
+
#
|
76
|
+
# ["Error1", "Error2"]
|
77
|
+
def update_contact(domain, contact_attributes)
|
78
|
+
contact_set = {
|
79
|
+
contact_attributes[:type] => contact_attributes
|
80
|
+
}
|
81
|
+
|
82
|
+
# Removes the type key from contact_attributes
|
83
|
+
contact_set[contact_attributes[:type]].delete(:type)
|
84
|
+
|
85
|
+
response = api_modify(params_with_domain(domain).merge({
|
86
|
+
:attributes => {
|
87
|
+
:affect_domains => "0",
|
88
|
+
:data => "contact_info",
|
89
|
+
:contact_set => contact_set
|
90
|
+
}
|
91
|
+
}))
|
92
|
+
|
93
|
+
if successful?
|
94
|
+
response
|
95
|
+
else
|
96
|
+
attributes["details"][domain]["response_text"].split("\n")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def params_with_domain(domain)
|
103
|
+
{ :domain => domain }
|
104
|
+
end
|
61
105
|
end
|
62
106
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module MooMoo
|
2
|
-
class Transfer <
|
2
|
+
class Transfer < BaseCommand
|
3
3
|
|
4
4
|
##
|
5
5
|
# Cancels transfers that are pending owner approval.
|
@@ -55,6 +55,6 @@ module MooMoo
|
|
55
55
|
# transferred and so no charges are incurred.
|
56
56
|
#
|
57
57
|
# http://www.opensrs.com/docs/apidomains/rsp2rsp_push_transfer.htm
|
58
|
-
register_service :
|
58
|
+
register_service :rsp2rsp_push_transfer, :domain
|
59
59
|
end
|
60
60
|
end
|
data/lib/moo_moo/version.rb
CHANGED
data/lib/moo_moo.rb
CHANGED
@@ -2,9 +2,7 @@ require 'moo_moo/exceptions'
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'moo_moo/version'
|
4
4
|
require 'moo_moo/config'
|
5
|
-
require 'moo_moo/
|
6
|
-
require 'moo_moo/response'
|
7
|
-
require 'moo_moo/base'
|
5
|
+
require 'moo_moo/base_command'
|
8
6
|
require 'moo_moo/middleware/open_srs_errors'
|
9
7
|
require 'moo_moo/middleware/parse_open_srs'
|
10
8
|
require 'moo_moo/middleware/open_srs_xml_builder'
|
data/spec/integration_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe "Real World integration" do
|
|
6
6
|
lookup = MooMoo::Lookup.new
|
7
7
|
|
8
8
|
VCR.use_cassette("integration/lookup") do
|
9
|
-
|
10
|
-
|
9
|
+
lookup.api_lookup(:domain => "opensrs.net")
|
10
|
+
lookup.attributes["status"].should == "taken"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SampleService < MooMoo::BaseCommand
|
4
|
+
register_service :service1, :object1
|
5
|
+
end
|
6
|
+
|
7
|
+
describe MooMoo::BaseCommand do
|
8
|
+
|
9
|
+
subject { SampleService.new(:host => "thehost.com", :key => "thekey",
|
10
|
+
:username => "theuser", :password => "thepass", :port => "12345") }
|
11
|
+
|
12
|
+
let(:response) { double("Response", :body => {"attributes" => { :the => :attrs }})}
|
13
|
+
|
14
|
+
describe "class methods" do
|
15
|
+
describe "#register_service" do
|
16
|
+
let(:request_params) { {:the => :params, :cookie => "thecookie"} }
|
17
|
+
|
18
|
+
it "service1" do
|
19
|
+
subject.should_receive(:faraday_request).
|
20
|
+
with(:service1, :object1, request_params).
|
21
|
+
and_return(response)
|
22
|
+
|
23
|
+
subject.api_service1(request_params).should == {:the => :attrs}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#successful?" do
|
29
|
+
it "is successful" do
|
30
|
+
subject.instance_variable_set("@response",
|
31
|
+
double("Response", :body => { "is_success" => "1" }))
|
32
|
+
|
33
|
+
subject.should be_successful
|
34
|
+
end
|
35
|
+
|
36
|
+
it "is not successful" do
|
37
|
+
subject.instance_variable_set("@response",
|
38
|
+
double("Response", :body => { "is_success" => "0" }))
|
39
|
+
|
40
|
+
subject.should_not be_successful
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#message" do
|
45
|
+
it "retrives the response text" do
|
46
|
+
subject.instance_variable_set("@response",
|
47
|
+
double("Response", :body => { "response_text" => "thetext" }))
|
48
|
+
|
49
|
+
subject.message.should == "thetext"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#response_attributes" do
|
54
|
+
it "retrives the response attributes" do
|
55
|
+
subject.instance_variable_set("@response",
|
56
|
+
double("Response", :body => { "attributes" => { :the => :attributes } }))
|
57
|
+
|
58
|
+
subject.attributes.should == { :the => :attributes }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#perform" do
|
63
|
+
let(:xml) { "xmlcontent" }
|
64
|
+
let(:response) { {:status => 200, :body => File.open("spec/fixtures/success_response.xml")} }
|
65
|
+
|
66
|
+
before :each do
|
67
|
+
@request = stub_request(:post, "https://thehost.com:12345/").to_return(response)
|
68
|
+
subject.send(:perform, :service1, :object1)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "posts with correct parameters" do
|
72
|
+
@request.should have_been_made
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns the response" do
|
76
|
+
subject.message.should == "Command Successful"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -4,5 +4,5 @@ describe MooMoo::Cookie do
|
|
4
4
|
it { should have_registered_service(:set, :cookie) }
|
5
5
|
it { should have_registered_service(:delete, :cookie) }
|
6
6
|
it { should have_registered_service(:update, :cookie) }
|
7
|
-
it { should have_registered_service(:
|
7
|
+
it { should have_registered_service(:quit, :session) }
|
8
8
|
end
|
@@ -2,17 +2,67 @@ require 'spec_helper'
|
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
describe MooMoo::Lookup do
|
5
|
+
subject { MooMoo::Lookup.new }
|
6
|
+
|
5
7
|
it { should have_registered_service(:belongs_to_rsp, :domain) }
|
6
8
|
it { should have_registered_service(:get_balance, :balance) }
|
7
9
|
it { should have_registered_service(:get_deleted_domains, :domain) }
|
8
|
-
it { should have_registered_service(:
|
9
|
-
it { should have_registered_service(:get_domains_contacts, :domain) }
|
10
|
+
it { should have_registered_service(:get, :domain) }
|
10
11
|
it { should have_registered_service(:get_domains_by_expiredate, :domain) }
|
12
|
+
it { should have_registered_service(:get_domains_contacts, :domain) }
|
11
13
|
it { should have_registered_service(:get_notes, :domain) }
|
12
14
|
it { should have_registered_service(:get_order_info, :domain) }
|
13
15
|
it { should have_registered_service(:get_orders_by_domain, :domain) }
|
14
16
|
it { should have_registered_service(:get_price, :domain) }
|
15
17
|
it { should have_registered_service(:get_product_info, :trust_service) }
|
16
|
-
it { should have_registered_service(:
|
18
|
+
it { should have_registered_service(:lookup, :domain) }
|
17
19
|
it { should have_registered_service(:name_suggest, :domain) }
|
20
|
+
|
21
|
+
describe "#get_domains_contacts" do
|
22
|
+
it "retrieves a list of a domain contacts" do
|
23
|
+
subject.should_receive(:faraday_request).with(:get_domains_contacts, :domain, { :attributes => { :domain_list => ["domain1.com"] }}).and_return(double("Response", :body => {
|
24
|
+
"attributes" => {
|
25
|
+
"domain1.com" => {
|
26
|
+
"contact_set" => {
|
27
|
+
"admin" => {
|
28
|
+
"first_name" => "FirstName",
|
29
|
+
"last_name" => "LastName",
|
30
|
+
"org_name" => "OrgName",
|
31
|
+
"address1" => "Address1",
|
32
|
+
"address2" => "Address2",
|
33
|
+
"address3" => "Address3",
|
34
|
+
"city" => "City",
|
35
|
+
"state" => "State",
|
36
|
+
"country" => "Country",
|
37
|
+
"postal_code" => "PostalCode",
|
38
|
+
"phone" => "Phone",
|
39
|
+
"fax" => "Fax",
|
40
|
+
"email" => "Email"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}))
|
46
|
+
|
47
|
+
subject.domain_contacts("domain1.com").should ==
|
48
|
+
[
|
49
|
+
{
|
50
|
+
:type => "admin",
|
51
|
+
:first_name => "FirstName",
|
52
|
+
:last_name => "LastName",
|
53
|
+
:org_name => "OrgName",
|
54
|
+
:address1 => "Address1",
|
55
|
+
:address2 => "Address2",
|
56
|
+
:address3 => "Address3",
|
57
|
+
:city => "City",
|
58
|
+
:state => "State",
|
59
|
+
:country => "Country",
|
60
|
+
:postal_code => "PostalCode",
|
61
|
+
:phone => "Phone",
|
62
|
+
:fax => "Fax",
|
63
|
+
:email => "Email"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
end
|
67
|
+
end
|
18
68
|
end
|
@@ -2,13 +2,97 @@ require 'spec_helper'
|
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
describe MooMoo::Provisioning do
|
5
|
+
subject { MooMoo::Provisioning.new }
|
6
|
+
|
7
|
+
let(:success_response) do
|
8
|
+
double("Response", :body => { "is_success" => "1" })
|
9
|
+
end
|
10
|
+
|
5
11
|
it { should have_registered_service(:cancel_order, :trust_service) }
|
6
12
|
it { should have_registered_service(:cancel_pending_orders, :order) }
|
7
13
|
it { should have_registered_service(:modify, :domain) }
|
8
14
|
it { should have_registered_service(:process_pending, :domain) }
|
9
|
-
it { should have_registered_service(:
|
15
|
+
it { should have_registered_service(:renew, :domain) }
|
10
16
|
it { should have_registered_service(:revoke, :domain) }
|
11
17
|
it { should have_registered_service(:update_contacts, :domain) }
|
12
|
-
it { should have_registered_service(:
|
18
|
+
it { should have_registered_service(:sw_register, :domain) }
|
13
19
|
it { should have_registered_service(:register_trust_service, :trust_service) }
|
20
|
+
|
21
|
+
describe "#update_contact" do
|
22
|
+
it "updates a domain contact" do
|
23
|
+
expected_params = {
|
24
|
+
:domain => "thedomain.com",
|
25
|
+
:attributes => {
|
26
|
+
:affect_domains => "0",
|
27
|
+
:data => "contact_info",
|
28
|
+
:contact_set => {
|
29
|
+
"admin" => {
|
30
|
+
:first_name => "AdminFirst",
|
31
|
+
:last_name => "AdminLast",
|
32
|
+
:org_name => "AdminOrg",
|
33
|
+
:address1 => "AdminAddress1",
|
34
|
+
:address2 => "AdminAddress2",
|
35
|
+
:address3 => "AdminAddress3",
|
36
|
+
:city => "AdminCity",
|
37
|
+
:state => "AdminState",
|
38
|
+
:country => "AdminCountry",
|
39
|
+
:postal_code => "AdminPostalCode",
|
40
|
+
:phone => "AdminPhone",
|
41
|
+
:fax => "AdminFax",
|
42
|
+
:email => "AdminEmail"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
params = {
|
49
|
+
:type => "admin",
|
50
|
+
:first_name => "AdminFirst",
|
51
|
+
:last_name => "AdminLast",
|
52
|
+
:org_name => "AdminOrg",
|
53
|
+
:address1 => "AdminAddress1",
|
54
|
+
:address2 => "AdminAddress2",
|
55
|
+
:address3 => "AdminAddress3",
|
56
|
+
:city => "AdminCity",
|
57
|
+
:state => "AdminState",
|
58
|
+
:country => "AdminCountry",
|
59
|
+
:postal_code => "AdminPostalCode",
|
60
|
+
:phone => "AdminPhone",
|
61
|
+
:fax => "AdminFax",
|
62
|
+
:email => "AdminEmail"
|
63
|
+
}
|
64
|
+
|
65
|
+
subject.should_receive(:faraday_request).with(:modify, :domain, expected_params).and_return(success_response)
|
66
|
+
subject.update_contact("thedomain.com", params)
|
67
|
+
|
68
|
+
subject.should be_successful
|
69
|
+
end
|
70
|
+
|
71
|
+
it "is unsuccessful when fails" do
|
72
|
+
expected_params = {
|
73
|
+
:domain => "thedomain.com",
|
74
|
+
:attributes => {
|
75
|
+
:affect_domains => "0",
|
76
|
+
:data => "contact_info",
|
77
|
+
:contact_set => { nil => {}}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
error_response = double("Response", :body => {
|
82
|
+
"attributes" => {
|
83
|
+
"details" => {
|
84
|
+
"thedomain.com" => {
|
85
|
+
"response_text" => "The error\nAnother error"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
})
|
90
|
+
|
91
|
+
subject.should_receive(:faraday_request).with(:modify, :domain, expected_params).and_return(error_response)
|
92
|
+
errors = subject.update_contact("thedomain.com", {})
|
93
|
+
|
94
|
+
subject.should_not be_successful
|
95
|
+
errors.should == ["The error", "Another error"]
|
96
|
+
end
|
97
|
+
end
|
14
98
|
end
|
@@ -8,5 +8,5 @@ describe MooMoo::Transfer do
|
|
8
8
|
it { should have_registered_service(:get_transfers_in, :domain) }
|
9
9
|
it { should have_registered_service(:process_transfer, :transfer) }
|
10
10
|
it { should have_registered_service(:send_password, :transfer) }
|
11
|
-
it { should have_registered_service(:
|
11
|
+
it { should have_registered_service(:rsp2rsp_push_transfer, :domain) }
|
12
12
|
end
|
data/spec/moo_moo_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -86,12 +86,13 @@ RSpec::Matchers.define(:have_registered_service) do |*args|
|
|
86
86
|
|
87
87
|
match do |object|
|
88
88
|
parameters = {:the => :params, :cookie => "thecookie"}
|
89
|
-
|
90
|
-
with(action_name, object_name, parameters).
|
91
|
-
and_return("theresult")
|
89
|
+
response = double("Response", :body => {"attributes" => { :the => :attrs }})
|
92
90
|
|
91
|
+
object.should_receive(:faraday_request).
|
92
|
+
with(action_name, object_name, parameters).
|
93
|
+
and_return(response)
|
93
94
|
|
94
|
-
object.send(method_name, parameters) ==
|
95
|
+
object.send("api_#{method_name}", parameters) == { :the => :attrs }
|
95
96
|
end
|
96
97
|
|
97
98
|
description do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moo_moo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: extlib
|
@@ -139,14 +139,12 @@ files:
|
|
139
139
|
- README.md
|
140
140
|
- Rakefile
|
141
141
|
- lib/moo_moo.rb
|
142
|
-
- lib/moo_moo/
|
143
|
-
- lib/moo_moo/command.rb
|
142
|
+
- lib/moo_moo/base_command.rb
|
144
143
|
- lib/moo_moo/config.rb
|
145
144
|
- lib/moo_moo/exceptions.rb
|
146
145
|
- lib/moo_moo/middleware/open_srs_errors.rb
|
147
146
|
- lib/moo_moo/middleware/open_srs_xml_builder.rb
|
148
147
|
- lib/moo_moo/middleware/parse_open_srs.rb
|
149
|
-
- lib/moo_moo/response.rb
|
150
148
|
- lib/moo_moo/services/cookie.rb
|
151
149
|
- lib/moo_moo/services/dns_zone.rb
|
152
150
|
- lib/moo_moo/services/lookup.rb
|
@@ -157,11 +155,9 @@ files:
|
|
157
155
|
- moo_moo.gemspec
|
158
156
|
- spec/fixtures/success_response.xml
|
159
157
|
- spec/integration_spec.rb
|
160
|
-
- spec/moo_moo/
|
161
|
-
- spec/moo_moo/command_spec.rb
|
158
|
+
- spec/moo_moo/base_command_spec.rb
|
162
159
|
- spec/moo_moo/config_spec.rb
|
163
160
|
- spec/moo_moo/middleware/open_srs_xml_builder_spec.rb
|
164
|
-
- spec/moo_moo/response_spec.rb
|
165
161
|
- spec/moo_moo/services/cookie_spec.rb
|
166
162
|
- spec/moo_moo/services/dns_zone_spec.rb
|
167
163
|
- spec/moo_moo/services/lookup_spec.rb
|
@@ -185,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
181
|
version: '0'
|
186
182
|
segments:
|
187
183
|
- 0
|
188
|
-
hash: -
|
184
|
+
hash: -848063552060590534
|
189
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
186
|
none: false
|
191
187
|
requirements:
|
@@ -194,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
190
|
version: '0'
|
195
191
|
segments:
|
196
192
|
- 0
|
197
|
-
hash: -
|
193
|
+
hash: -848063552060590534
|
198
194
|
requirements: []
|
199
195
|
rubyforge_project: opensrs
|
200
196
|
rubygems_version: 1.8.23
|
@@ -204,11 +200,9 @@ summary: Implements OpenSRS XML API
|
|
204
200
|
test_files:
|
205
201
|
- spec/fixtures/success_response.xml
|
206
202
|
- spec/integration_spec.rb
|
207
|
-
- spec/moo_moo/
|
208
|
-
- spec/moo_moo/command_spec.rb
|
203
|
+
- spec/moo_moo/base_command_spec.rb
|
209
204
|
- spec/moo_moo/config_spec.rb
|
210
205
|
- spec/moo_moo/middleware/open_srs_xml_builder_spec.rb
|
211
|
-
- spec/moo_moo/response_spec.rb
|
212
206
|
- spec/moo_moo/services/cookie_spec.rb
|
213
207
|
- spec/moo_moo/services/dns_zone_spec.rb
|
214
208
|
- spec/moo_moo/services/lookup_spec.rb
|
data/lib/moo_moo/command.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module MooMoo
|
2
|
-
class Command
|
3
|
-
# Constructor
|
4
|
-
#
|
5
|
-
# ==== Required
|
6
|
-
# * <tt>:action</tt> - action of the command
|
7
|
-
# * <tt>:object</tt> - object the command operates on
|
8
|
-
# * <tt>:params</tt> - additional parameters for the command
|
9
|
-
def initialize(action, object, params = {})
|
10
|
-
@action = action
|
11
|
-
@object = object
|
12
|
-
@params = params
|
13
|
-
end
|
14
|
-
|
15
|
-
# Runs the command against OpenSRS server
|
16
|
-
#
|
17
|
-
# ==== Required
|
18
|
-
# * <tt>:host</tt> - host of the OpenSRS server
|
19
|
-
# * <tt>:key</tt> - private key for the account
|
20
|
-
# * <tt>:user</tt> - username for the account
|
21
|
-
# * <tt>:port</tt> - port to connect to
|
22
|
-
def run(host, key, user, port)
|
23
|
-
@returned_parameters = Faraday.new(:url => "https://#{host}:#{port}", :ssl => {:verify => true}) do |c|
|
24
|
-
c.request :open_srs_xml_builder, @action, @object, @params, key, user
|
25
|
-
c.response :parse_open_srs
|
26
|
-
c.response :open_srs_errors
|
27
|
-
c.adapter :net_http
|
28
|
-
end.post.body
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
data/lib/moo_moo/response.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module MooMoo
|
2
|
-
# Based on opensrs_xmlapi.pdf page 25.
|
3
|
-
class Response
|
4
|
-
attr_reader :hash
|
5
|
-
|
6
|
-
# Constructor
|
7
|
-
#
|
8
|
-
# ==== Required
|
9
|
-
# * <tt>:hash</tt> - response hash
|
10
|
-
def initialize(hash)
|
11
|
-
@hash = hash
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns whether or not the command executed was successful
|
15
|
-
def success?
|
16
|
-
@hash['is_success'].to_i == 1
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns the response code if one is present
|
20
|
-
def code
|
21
|
-
@hash['response_code'].to_i
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the response message if one is present
|
25
|
-
def text
|
26
|
-
@hash['response_text']
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns the response attributes.
|
30
|
-
def attributes
|
31
|
-
@hash['attributes']
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/spec/moo_moo/base_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
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(:host => "thehost", :key => "thekey",
|
15
|
-
:username => "theuser", :password => "thepass", :port => "theport")
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "class methods" do
|
19
|
-
describe "#register_service" do
|
20
|
-
context "calls the services with the given parameters" do
|
21
|
-
it "service1" do
|
22
|
-
params = {:the => :params, :cookie => "thecookie"}
|
23
|
-
|
24
|
-
@service.should_receive(:run_command).
|
25
|
-
with(:service1, :object1, params).
|
26
|
-
and_return("theresult")
|
27
|
-
|
28
|
-
@service.service1(params).should == "theresult"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "service2" do
|
32
|
-
params = {:the => :params, :cookie => "thecookie"}
|
33
|
-
|
34
|
-
@service.should_receive(:run_command).
|
35
|
-
with(:action2, :object2, params).
|
36
|
-
and_return("theresult")
|
37
|
-
|
38
|
-
@service.service2(params).should == "theresult"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "service3" do
|
42
|
-
params = {:the => :params, :cookie => "thecookie"}
|
43
|
-
expected_params = {:the => :params, :cookie => "thecookie", :example => "theexample"}
|
44
|
-
|
45
|
-
@service.should_receive(:run_command).
|
46
|
-
with(:service3, :object3, expected_params).
|
47
|
-
and_return("theresult")
|
48
|
-
|
49
|
-
@service.service3(params).should == "theresult"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#run_command" do
|
56
|
-
it "should encapsulate response" do
|
57
|
-
result = {:the => :result}
|
58
|
-
command = stub()
|
59
|
-
command.should_receive(:run).with("thehost", "thekey", "theuser", "theport").and_return(result)
|
60
|
-
MooMoo::Command.should_receive(:new).
|
61
|
-
with("theaction", "theobject", {"the" => "params"}).
|
62
|
-
and_return(command)
|
63
|
-
|
64
|
-
response = @service.run_command("theaction", "theobject", {"the" => "params"})
|
65
|
-
response.hash.should == result
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,41 +0,0 @@
|
|
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
|
-
|
14
|
-
let(:command) { MooMoo::Command.new(action, object, params) }
|
15
|
-
|
16
|
-
describe "#run" do
|
17
|
-
describe "success response" do
|
18
|
-
let(:xml) { "xmlcontent" }
|
19
|
-
let(:response) { {:status => 200, :body => File.open("spec/fixtures/success_response.xml")} }
|
20
|
-
|
21
|
-
before :each do
|
22
|
-
@request = stub_request(:post, "https://thehost.com:12345/").to_return(response)
|
23
|
-
@response = command.run("thehost.com", "thekey", "theuser", "12345")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "posts with correct parameters" do
|
27
|
-
@request.should have_been_made
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns the response" do
|
31
|
-
@response["response_text"].should == "Command Successful"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "raises exception on invalid http status" do
|
36
|
-
stub_request(:post, "https://thehost:12345/").to_return(:status => ["401", "Unauthorized"])
|
37
|
-
lambda { command.run("thehost", "thekey", "theuser", "12345") }.should raise_error(MooMoo::OpenSRSException, "Bad HTTP Status: 401")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
describe MooMoo::Response do
|
5
|
-
subject { MooMoo::Response.new(
|
6
|
-
"is_success" => "1", "response_code" => "100",
|
7
|
-
"response_text" => "The message", "attributes" => "The attributes") }
|
8
|
-
|
9
|
-
describe "#hash" do
|
10
|
-
it "retrieves the response hash" do
|
11
|
-
subject.hash.should == { "is_success" => "1", "response_code" => "100",
|
12
|
-
"response_text" => "The message", "attributes" => "The attributes" }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#success?" do
|
17
|
-
it "is true when 1" do
|
18
|
-
subject.success?.should be_true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "is false when not 1" do
|
22
|
-
MooMoo::Response.new("is_success" => "0").success?.should be_false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#code" do
|
27
|
-
it "retrieves response code" do
|
28
|
-
subject.code.should == 100
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#text" do
|
33
|
-
it "retrieves response text" do
|
34
|
-
subject.text.should == "The message"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#attributes" do
|
39
|
-
it "retrieves response attributes" do
|
40
|
-
subject.attributes.should == "The attributes"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|