moo_moo 0.1.0
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.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rvmrc +59 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +63 -0
- data/Rakefile +55 -0
- data/lib/cacert.pem +3910 -0
- data/lib/moo_moo/config.rb +13 -0
- data/lib/moo_moo/opensrs/args.rb +109 -0
- data/lib/moo_moo/opensrs/base.rb +75 -0
- data/lib/moo_moo/opensrs/command.rb +190 -0
- data/lib/moo_moo/opensrs/cookie_commands.rb +52 -0
- data/lib/moo_moo/opensrs/lookup_commands.rb +195 -0
- data/lib/moo_moo/opensrs/nameserver_commands.rb +70 -0
- data/lib/moo_moo/opensrs/opensrsexception.rb +6 -0
- data/lib/moo_moo/opensrs/provisioning_commands.rb +167 -0
- data/lib/moo_moo/opensrs/response.rb +41 -0
- data/lib/moo_moo/opensrs/transfer_commands.rb +83 -0
- data/lib/moo_moo/opensrs/utils.rb +13 -0
- data/lib/moo_moo/opensrs.rb +8 -0
- data/lib/moo_moo/version.rb +3 -0
- data/lib/moo_moo.rb +16 -0
- data/moo_moo.gemspec +33 -0
- data/spec/moo_moo_spec.rb +17 -0
- data/spec/opensrs/args_spec.rb +179 -0
- data/spec/opensrs/cookie_spec.rb +78 -0
- data/spec/opensrs/lookup_spec.rb +212 -0
- data/spec/opensrs/nameserver_spec.rb +124 -0
- data/spec/opensrs/opensrs_spec.rb +35 -0
- data/spec/opensrs/provisioning_spec.rb +271 -0
- data/spec/opensrs/transfer_spec.rb +197 -0
- data/spec/opensrs/utils_spec.rb +12 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/vcr_cassettes/cookie/delete_cookie.yml +219 -0
- data/spec/vcr_cassettes/cookie/quit_session.yml +97 -0
- data/spec/vcr_cassettes/cookie/set_cookie.yml +123 -0
- data/spec/vcr_cassettes/cookie/set_cookie_fail.yml +54 -0
- data/spec/vcr_cassettes/cookie/update_cookie.yml +239 -0
- data/spec/vcr_cassettes/lookup/belongs_to_rsp.yml +54 -0
- data/spec/vcr_cassettes/lookup/belongs_to_rsp_negative.yml +55 -0
- data/spec/vcr_cassettes/lookup/get_balance.yml +55 -0
- data/spec/vcr_cassettes/lookup/get_deleted_domains.yml +80 -0
- data/spec/vcr_cassettes/lookup/get_domain.yml +211 -0
- data/spec/vcr_cassettes/lookup/get_domain_fail.yml +269 -0
- data/spec/vcr_cassettes/lookup/get_domains_by_expiredate.yml +76 -0
- data/spec/vcr_cassettes/lookup/get_domains_contacts.yml +129 -0
- data/spec/vcr_cassettes/lookup/get_domains_contacts_fail.yml +58 -0
- data/spec/vcr_cassettes/lookup/get_notes_for_domain.yml +85 -0
- data/spec/vcr_cassettes/lookup/get_notes_for_order.yml +61 -0
- data/spec/vcr_cassettes/lookup/get_notes_for_transfer.yml +61 -0
- data/spec/vcr_cassettes/lookup/get_order_info.yml +139 -0
- data/spec/vcr_cassettes/lookup/get_orders_by_domain.yml +76 -0
- data/spec/vcr_cassettes/lookup/get_price.yml +54 -0
- data/spec/vcr_cassettes/lookup/get_product_info.yml +49 -0
- data/spec/vcr_cassettes/lookup/lookup_domain_available.yml +55 -0
- data/spec/vcr_cassettes/lookup/lookup_domain_registered.yml +55 -0
- data/spec/vcr_cassettes/lookup/name_suggest.yml +396 -0
- data/spec/vcr_cassettes/nameserver/create.yml +49 -0
- data/spec/vcr_cassettes/nameserver/delete.yml +49 -0
- data/spec/vcr_cassettes/nameserver/get.yml +71 -0
- data/spec/vcr_cassettes/nameserver/modify.yml +49 -0
- data/spec/vcr_cassettes/provisioning/cancel_order.yml +56 -0
- data/spec/vcr_cassettes/provisioning/cancel_order_invalid.yml +49 -0
- data/spec/vcr_cassettes/provisioning/cancel_pending_orders.yml +58 -0
- data/spec/vcr_cassettes/provisioning/modify_all_domains.yml +49 -0
- data/spec/vcr_cassettes/provisioning/modify_domain.yml +49 -0
- data/spec/vcr_cassettes/provisioning/process_pending.yml +57 -0
- data/spec/vcr_cassettes/provisioning/register_domain.yml +57 -0
- data/spec/vcr_cassettes/provisioning/register_pending_domain.yml +55 -0
- data/spec/vcr_cassettes/provisioning/register_taken_domain.yml +55 -0
- data/spec/vcr_cassettes/provisioning/renew_domain.yml +58 -0
- data/spec/vcr_cassettes/provisioning/revoke_domain.yml +55 -0
- data/spec/vcr_cassettes/provisioning/trust_service.yml +60 -0
- data/spec/vcr_cassettes/provisioning/update_contacts.yml +66 -0
- data/spec/vcr_cassettes/transfer/cancel_transfer.yml +49 -0
- data/spec/vcr_cassettes/transfer/cancel_trasnfer_order.yml +49 -0
- data/spec/vcr_cassettes/transfer/check_transfer.yml +56 -0
- data/spec/vcr_cassettes/transfer/check_transfer_exists.yml +57 -0
- data/spec/vcr_cassettes/transfer/get_transfers_away.yml +60 -0
- data/spec/vcr_cassettes/transfer/get_transfers_in.yml +80 -0
- data/spec/vcr_cassettes/transfer/process_transfer.yml +49 -0
- data/spec/vcr_cassettes/transfer/process_transfer_unsuccessful.yml +49 -0
- data/spec/vcr_cassettes/transfer/rsp2rsp_push_transfer.yml +49 -0
- data/spec/vcr_cassettes/transfer/send_password.yml +49 -0
- data/spec/vcr_cassettes/transfer/transfer.yml +58 -0
- metadata +280 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
module MooMoo
|
|
2
|
+
module OpenSRS
|
|
3
|
+
module ProvisioningCommands
|
|
4
|
+
# Cancels a Trust Service order
|
|
5
|
+
#
|
|
6
|
+
# ==== Required
|
|
7
|
+
# * <tt>:order_id</tt> - ID of the order
|
|
8
|
+
def cancel_order(order_id)
|
|
9
|
+
run_command :cancel_order, :trust_service, {
|
|
10
|
+
:order_id => order_id,
|
|
11
|
+
:key => 'attributes'
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Cancels pending or declined orders
|
|
16
|
+
#
|
|
17
|
+
# ==== Required
|
|
18
|
+
# * <tt>:to_date</tt> - date before which to cancel orders
|
|
19
|
+
def cancel_pending_orders(to_date)
|
|
20
|
+
run_command :cancel_pending_orders, :order, {
|
|
21
|
+
:to_date => to_date,
|
|
22
|
+
:key => 'attributes'
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Changes information associated with a domain
|
|
27
|
+
#
|
|
28
|
+
# ==== Required
|
|
29
|
+
# * <tt>:type</tt> - type of data to modify
|
|
30
|
+
# * <tt>:params</tt> - new parameter values to set
|
|
31
|
+
#
|
|
32
|
+
# ==== Optional
|
|
33
|
+
# * <tt>:cookie</tt> - cookie for the domain
|
|
34
|
+
def modify(params)
|
|
35
|
+
cookie = params.delete :cookie
|
|
36
|
+
|
|
37
|
+
run_command :modify, :domain, params, cookie
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Processes or cancels a pending order
|
|
41
|
+
#
|
|
42
|
+
# ==== Required
|
|
43
|
+
# * <tt>:order_id</tt> - ID of the pending order to process
|
|
44
|
+
def process_pending(order_id)
|
|
45
|
+
run_command :process_pending, :domain, {
|
|
46
|
+
:order_id => order_id,
|
|
47
|
+
:key => 'attributes'
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Renews a domain name
|
|
52
|
+
#
|
|
53
|
+
# ==== Required
|
|
54
|
+
# * <tt>:domain</tt> - domain name to renew
|
|
55
|
+
# * <tt>:term</tt> - number of years to renew for
|
|
56
|
+
# * <tt>:current_expiration_year</tt> - current expiration year in YYYY format
|
|
57
|
+
def renew_domain(attribs)
|
|
58
|
+
Args.new(attribs) do |c|
|
|
59
|
+
c.requires :domain, :term, :current_expiration_year
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
attribs[:handle] = 'process' unless attribs[:handle]
|
|
63
|
+
attribs[:key] = 'attributes'
|
|
64
|
+
|
|
65
|
+
run_command :renew, :domain, attribs
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Removes the domain at the registry
|
|
69
|
+
#
|
|
70
|
+
# ==== Required
|
|
71
|
+
# * <tt>:domain</tt> - domain name to remove
|
|
72
|
+
# * <tt>:reseller</tt> - username of the reseller
|
|
73
|
+
def revoke(params)
|
|
74
|
+
params[:key] = 'attributes'
|
|
75
|
+
|
|
76
|
+
run_command :revoke, :domain, params
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Submits a domain contact information update
|
|
80
|
+
#
|
|
81
|
+
# ==== Required
|
|
82
|
+
# * <tt>:domain</tt> - domain name to update the contacts of
|
|
83
|
+
# * <tt>:contacts</tt> - contact set with updated values
|
|
84
|
+
# * <tt>:types</tt> - list of contact types that are to be updated
|
|
85
|
+
def update_contacts(params)
|
|
86
|
+
params[:types] = index_array(params[:types])
|
|
87
|
+
|
|
88
|
+
params[:contact_set] = params.delete :contacts
|
|
89
|
+
params[:key] = 'attributes'
|
|
90
|
+
|
|
91
|
+
run_command :update_contacts, :domain, params
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Submits a new registration request or transfer order
|
|
95
|
+
#
|
|
96
|
+
# ==== Required
|
|
97
|
+
# * <tt>:domain</tt> - domain name to register
|
|
98
|
+
# * <tt>:contacts</tt> - contact set for the domain
|
|
99
|
+
# * <tt>:nameservers</tt> - array of nameservers
|
|
100
|
+
#
|
|
101
|
+
# ==== Optional
|
|
102
|
+
# * <tt>:term</tt> - number of years to register the domain for
|
|
103
|
+
# * <tt>:options</tt> - additional attributes to set
|
|
104
|
+
def register_domain(attribs)
|
|
105
|
+
Args.new(attribs) do |c|
|
|
106
|
+
c.requires :domain, :contacts, :nameservers
|
|
107
|
+
c.optionals :term, :options
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
attribs[:term] = 1 unless attribs[:term]
|
|
111
|
+
nameservers = format_nameservers(attribs[:nameservers])
|
|
112
|
+
|
|
113
|
+
attributes = {
|
|
114
|
+
:contact_set => attribs[:contacts],
|
|
115
|
+
:custom_nameservers => 1,
|
|
116
|
+
:custom_tech_contact => 1,
|
|
117
|
+
:domain => attribs[:domain],
|
|
118
|
+
:nameserver_list => nameservers,
|
|
119
|
+
:period => attribs[:term],
|
|
120
|
+
:reg_username => @user,
|
|
121
|
+
:reg_password => @password
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
attributes[:reg_type] = :new unless attribs[:options] && attribs[:options][:reg_type]
|
|
125
|
+
attributes.merge!(attribs[:options]) if attribs[:options]
|
|
126
|
+
attributes[:key] = 'attributes'
|
|
127
|
+
|
|
128
|
+
res = run_command :sw_register, :domain, attributes
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Submits a new registration request or transfer order
|
|
132
|
+
#
|
|
133
|
+
# ==== Required
|
|
134
|
+
# * <tt>:csr</tt> - certificate signing request
|
|
135
|
+
# * <tt>:contacts</tt> - contact set for the trust service
|
|
136
|
+
#
|
|
137
|
+
# ==== Optional
|
|
138
|
+
# * <tt>:attribs</tt> - additional attributes to set
|
|
139
|
+
# * <tt>:term</tt> - number of years to register the trust service for
|
|
140
|
+
def register_trust_service(params)
|
|
141
|
+
params[:period] = params.delete :term
|
|
142
|
+
params[:period] = 1 unless params[:period]
|
|
143
|
+
params[:reg_type] = 'new' unless params[:reg_type]
|
|
144
|
+
params[:handle] = 'process' unless params[:handle]
|
|
145
|
+
params[:contact_set] = params.delete :contacts
|
|
146
|
+
params[:key] = 'attributes'
|
|
147
|
+
|
|
148
|
+
run_command :sw_register, :trust_service, params
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
private
|
|
152
|
+
|
|
153
|
+
def format_nameservers(nameservers)
|
|
154
|
+
[
|
|
155
|
+
"0".to_sym => {
|
|
156
|
+
:sortorder => 1,
|
|
157
|
+
:name => nameservers.first
|
|
158
|
+
},
|
|
159
|
+
"1".to_sym => {
|
|
160
|
+
:sortorder => 2,
|
|
161
|
+
:name => nameservers.size == 2 ? nameservers[1] : nameservers.first
|
|
162
|
+
},
|
|
163
|
+
]
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module MooMoo
|
|
2
|
+
module OpenSRS
|
|
3
|
+
class Response
|
|
4
|
+
# Constructor
|
|
5
|
+
#
|
|
6
|
+
# ==== Required
|
|
7
|
+
# * <tt>:hash</tt> - hash of the response
|
|
8
|
+
#
|
|
9
|
+
# ==== Optional
|
|
10
|
+
# * <tt>:key</tt> - primary key to use when indexing the hash
|
|
11
|
+
def initialize(hash, key = nil)
|
|
12
|
+
@hash = hash
|
|
13
|
+
@key = key
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns whether or not the command executed was successful
|
|
17
|
+
#
|
|
18
|
+
def success?
|
|
19
|
+
@hash['is_success'].nil? ? true : @hash['is_success'].to_i == 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns the error message if one is present
|
|
23
|
+
#
|
|
24
|
+
def error_msg
|
|
25
|
+
@hash['response_text']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the response code if one is present
|
|
29
|
+
#
|
|
30
|
+
def error_code
|
|
31
|
+
@hash['response_code'].to_i
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the result hash
|
|
35
|
+
#
|
|
36
|
+
def result
|
|
37
|
+
@key.nil? ? @hash : @hash[@key]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module MooMoo
|
|
2
|
+
module OpenSRS
|
|
3
|
+
module TransferCommands
|
|
4
|
+
# Cancels a transfer that is pending owner approval
|
|
5
|
+
#
|
|
6
|
+
# ==== Required
|
|
7
|
+
# * <tt>:domain</tt> - domain name that is being transferred
|
|
8
|
+
# * <tt>:reseller</tt> - username of the reseller
|
|
9
|
+
def cancel_transfer(params)
|
|
10
|
+
run_command :cancel_transfer, :transfer, params
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Cancels a transfer that is pending owner approval by order ID
|
|
14
|
+
#
|
|
15
|
+
# ==== Required
|
|
16
|
+
# * <tt>:order_id</tt> - ID of the order
|
|
17
|
+
# * <tt>:reseller</tt> - username of the reseller
|
|
18
|
+
def cancel_transfer_for_order(params)
|
|
19
|
+
run_command :cancel_transfer, :transfer, params
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Checks to see if the given domain can be transferred
|
|
23
|
+
#
|
|
24
|
+
# ==== Required
|
|
25
|
+
# * <tt>:domain</tt> - domain name to check
|
|
26
|
+
def check_transfer(domain)
|
|
27
|
+
run_command :check_transfer, :domain, {
|
|
28
|
+
:domain => domain,
|
|
29
|
+
:key => 'attributes'
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Lists all domains that have been transferred away
|
|
34
|
+
#
|
|
35
|
+
def get_transfers_away
|
|
36
|
+
run_command :get_transfers_away, :domain, {
|
|
37
|
+
:key => 'attributes'
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Lists all domains that have been transferred in
|
|
42
|
+
def get_transfers_in
|
|
43
|
+
run_command :get_transfers_in, :domain, {
|
|
44
|
+
:key => 'attributes'
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Creates a new order with the same data as a cancelled order
|
|
49
|
+
#
|
|
50
|
+
# ==== Required
|
|
51
|
+
# * <tt>:order_id</tt> - ID of the cancelled order
|
|
52
|
+
# * <tt>:reseller</tt> - username of the reseller
|
|
53
|
+
def process_transfer(params)
|
|
54
|
+
params[:key] = 'attributes'
|
|
55
|
+
|
|
56
|
+
run_command :process_transfer, :transfer, params
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Resends an e-mail to the admin contact for the transfer that is in 'pending owner approval' state
|
|
60
|
+
#
|
|
61
|
+
# ==== Required
|
|
62
|
+
# * <tt>:domain</tt> - domain name being transferred
|
|
63
|
+
def send_password(domain)
|
|
64
|
+
run_command :send_password, :transfer, {
|
|
65
|
+
:domain_name => domain
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Transfers a domain name from one reseller to another
|
|
70
|
+
#
|
|
71
|
+
# ==== Required
|
|
72
|
+
# * <tt>:domain</tt> - domain name to transfer
|
|
73
|
+
# * <tt>:username</tt> - username of the registrant
|
|
74
|
+
# * <tt>:password</tt> - password of the registrant
|
|
75
|
+
# * <tt>:reseller</tt> - name of the gaining reseller
|
|
76
|
+
def push_transfer(params)
|
|
77
|
+
params[:grsp] = params.delete :reseller
|
|
78
|
+
|
|
79
|
+
run_command :rsp2rsp_push_transfer, nil, params
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/moo_moo.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module MooMoo
|
|
2
|
+
autoload :Version, 'moo_moo/version'
|
|
3
|
+
autoload :Config, 'moo_moo/config'
|
|
4
|
+
autoload :OpenSRS, 'moo_moo/opensrs'
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
attr_accessor :config
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.configure
|
|
11
|
+
yield config if block_given?
|
|
12
|
+
config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
self.config = Config.new
|
|
16
|
+
end
|
data/moo_moo.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require 'moo_moo/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "moo_moo"
|
|
7
|
+
s.version = MooMoo::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Tim Parkin"]
|
|
10
|
+
s.email = ["tparkin@site5.com"]
|
|
11
|
+
s.homepage = ""
|
|
12
|
+
s.summary = %q{Implements OpenSRS XML API}
|
|
13
|
+
s.description = %q{Implements OpenSRS XML API}
|
|
14
|
+
|
|
15
|
+
s.rubyforge_project = "opensrs"
|
|
16
|
+
|
|
17
|
+
s.add_runtime_dependency('jruby-openssl', '~> 0.7.3') if RUBY_PLATFORM == 'java'
|
|
18
|
+
s.add_development_dependency 'rake', '~> 0.8.7'
|
|
19
|
+
s.add_development_dependency 'rspec', '~> 2.5.0'
|
|
20
|
+
s.add_development_dependency 'fakeweb', '~> 1.3.0'
|
|
21
|
+
s.add_development_dependency 'vcr', '~> 1.9.0'
|
|
22
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'rbx'
|
|
23
|
+
s.add_development_dependency 'rcov', '>= 0.9.9'
|
|
24
|
+
s.add_development_dependency 'metric_fu', '>= 2.1.1'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
s.add_dependency 'extlib'
|
|
28
|
+
|
|
29
|
+
s.files = `git ls-files`.split("\n")
|
|
30
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
31
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
32
|
+
s.require_paths = ["lib"]
|
|
33
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe MooMoo do
|
|
4
|
+
describe "::Version" do
|
|
5
|
+
it "has a valid version" do
|
|
6
|
+
MooMoo::Version.should match /\d+\.\d+\.\d+/
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "::configure" do
|
|
11
|
+
it { MooMoo.configure.should be_a MooMoo::Config }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "::config" do
|
|
15
|
+
it { MooMoo.should have_attr_accessor :config }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'moo_moo/opensrs/args'
|
|
3
|
+
|
|
4
|
+
module MooMoo
|
|
5
|
+
describe MooMoo::Args do
|
|
6
|
+
context "required_parms" do
|
|
7
|
+
it "raises an error when missing" do
|
|
8
|
+
options = {:arg1 => true}
|
|
9
|
+
args = lambda {
|
|
10
|
+
MooMoo::Args.new(options) do |c|
|
|
11
|
+
c.requires :arg2
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /Missing required parameter: arg2/)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "does not raise an error with valid params" do
|
|
18
|
+
options = {:arg1 => true}
|
|
19
|
+
args = MooMoo::Args.new(options) { |c|
|
|
20
|
+
c.requires :arg1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
args.required_params.should have(1).value
|
|
24
|
+
args.required_params.should include(:arg1)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "sets optional_params" do
|
|
28
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
29
|
+
args = MooMoo::Args.new(options) { |c|
|
|
30
|
+
c.requires :arg1, :arg2
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
args.optional_params.should have(2).values
|
|
34
|
+
args.required_params.should have(2).values
|
|
35
|
+
|
|
36
|
+
args.optional_params.should include(*args.required_params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "does not set boolean_params" do
|
|
40
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
41
|
+
args = MooMoo::Args.new(options) { |c|
|
|
42
|
+
c.requires :arg1, :arg2
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
args.boolean_params.should be_empty
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "boolean_params" do
|
|
50
|
+
it "raises an error when the param is not boolean" do
|
|
51
|
+
options = {:arg1 => 'string'}
|
|
52
|
+
args = lambda {
|
|
53
|
+
MooMoo::Args.new(options) do |c|
|
|
54
|
+
c.booleans :arg1
|
|
55
|
+
end
|
|
56
|
+
}
|
|
57
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /Boolean parameter must be.*: arg1/)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "raises an error with boolean params" do
|
|
61
|
+
options = {:arg1 => true}
|
|
62
|
+
args = MooMoo::Args.new(options) { |c|
|
|
63
|
+
c.booleans :arg1
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
args.boolean_params.should have(1).value
|
|
67
|
+
args.boolean_params.should include(:arg1)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "sets optional_params" do
|
|
71
|
+
options = {:arg1 => true, :arg2 => false}
|
|
72
|
+
args = MooMoo::Args.new(options) { |c|
|
|
73
|
+
c.booleans :arg1, :arg2
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
args.optional_params.should have(2).values
|
|
77
|
+
args.boolean_params.should have(2).values
|
|
78
|
+
|
|
79
|
+
args.optional_params.should include(:arg1, :arg2)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "sets required_params" do
|
|
83
|
+
options = {:arg1 => true, :arg2 => false}
|
|
84
|
+
args = MooMoo::Args.new(options) { |c|
|
|
85
|
+
c.booleans :arg1, :arg2
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
args.required_params.should be_empty
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "optional_params" do
|
|
93
|
+
it "raises an error with unknown params" do
|
|
94
|
+
options = {:arg1 => true}
|
|
95
|
+
args = lambda {
|
|
96
|
+
MooMoo::Args.new(options) do |c|
|
|
97
|
+
c.optionals :arg2
|
|
98
|
+
end
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /Not a valid parameter: arg1/)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "does not raise an error with known params" do
|
|
105
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
106
|
+
args = MooMoo::Args.new(options) { |c|
|
|
107
|
+
c.optionals :arg1, :arg2
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
args.optional_params.should have(2).values
|
|
111
|
+
args.optional_params.should include(:arg1, :arg2)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "does not set required_params" do
|
|
115
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
116
|
+
args = MooMoo::Args.new(options) { |c|
|
|
117
|
+
c.optionals :arg1, :arg2
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
args.required_params.should be_empty
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "does not set boolean_params" do
|
|
124
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
125
|
+
args = MooMoo::Args.new(options) { |c|
|
|
126
|
+
c.optionals :arg1, :arg2
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
args.boolean_params.should be_empty
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "one_of" do
|
|
134
|
+
it "allows one arg" do
|
|
135
|
+
options = {:arg1 => true}
|
|
136
|
+
args = lambda {
|
|
137
|
+
MooMoo::Args.new(options) do |c|
|
|
138
|
+
c.one_of :arg1
|
|
139
|
+
end
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /One of requires two or more items/)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "allows two or more args" do
|
|
146
|
+
options = {:arg1 => true}
|
|
147
|
+
|
|
148
|
+
args = MooMoo::Args.new(options) do |c|
|
|
149
|
+
c.one_of :arg1, :arg2
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
args.one_of_params.should have(2).values
|
|
153
|
+
args.one_of_params.should include(:arg1, :arg2)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "does not allow 0 params" do
|
|
157
|
+
options = {}
|
|
158
|
+
args = lambda {
|
|
159
|
+
MooMoo::Args.new(options) do |c|
|
|
160
|
+
c.one_of :arg1, :arg2
|
|
161
|
+
end
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /The parameters may include only one of 'arg1, arg2'/)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "does not allow both args" do
|
|
168
|
+
options = {:arg1 => true, :arg2 => 2}
|
|
169
|
+
args = lambda {
|
|
170
|
+
MooMoo::Args.new(options) do |c|
|
|
171
|
+
c.one_of :arg1, :arg2
|
|
172
|
+
end
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
expect { args.call }.to raise_error(MooMooArgumentError, /The parameters may include only one of 'arg1, arg2'/)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'moo_moo/opensrs'
|
|
3
|
+
|
|
4
|
+
module MooMoo
|
|
5
|
+
|
|
6
|
+
describe OpenSRS do
|
|
7
|
+
before(:each) do
|
|
8
|
+
def random_domain
|
|
9
|
+
"domainthatsnottaken#{Time.now.to_i}.com"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@opensrs = OpenSRS::Base.new
|
|
13
|
+
@registered_domain = "domainthatsnottaken1302209138.com"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "CookieCommands" do
|
|
17
|
+
describe "#set_cookie" do
|
|
18
|
+
it "sets the cookie" do
|
|
19
|
+
VCR.use_cassette("cookie/set_cookie") do
|
|
20
|
+
res = @opensrs.set_cookie(:username => MooMoo.config.user,
|
|
21
|
+
:password => MooMoo.config.pass,
|
|
22
|
+
:domain => @registered_domain)
|
|
23
|
+
res.success?.should be_true
|
|
24
|
+
res.result['cookie'].should == "0000000000000000:000000:00000"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "fails to set the cookie" do
|
|
29
|
+
VCR.use_cassette("cookie/set_cookie_fail") do
|
|
30
|
+
res = @opensrs.set_cookie(:username => MooMoo.config.user,
|
|
31
|
+
:password => 'password',
|
|
32
|
+
:domain => 'example.com')
|
|
33
|
+
res.success?.should be_false
|
|
34
|
+
res.error_code.should == 415
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "#delete_cookie" do
|
|
40
|
+
use_vcr_cassette "cookie/delete_cookie"
|
|
41
|
+
|
|
42
|
+
it "destroys the cookie" do
|
|
43
|
+
res = @opensrs.set_cookie(:username => MooMoo.config.user,
|
|
44
|
+
:password => MooMoo.config.pass,
|
|
45
|
+
:domain => @registered_domain)
|
|
46
|
+
res = @opensrs.delete_cookie(res.result['cookie'])
|
|
47
|
+
res.success?.should be_true
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#update_cookie" do
|
|
52
|
+
use_vcr_cassette "cookie/update_cookie"
|
|
53
|
+
|
|
54
|
+
it "updates the cookie's domain" do
|
|
55
|
+
res = @opensrs.set_cookie(:username => MooMoo.config.user,
|
|
56
|
+
:password => MooMoo.config.pass,
|
|
57
|
+
:domain => @registered_domain)
|
|
58
|
+
res = @opensrs.update_cookie(
|
|
59
|
+
:old_domain => @registered_domain,
|
|
60
|
+
:new_domain => @registered_domain,
|
|
61
|
+
:cookie => res.result['cookie'])
|
|
62
|
+
res.success?.should be_true
|
|
63
|
+
res.result['domain_count'].to_i.should == 1
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "#quit_session" do
|
|
68
|
+
use_vcr_cassette "cookie/quit_session"
|
|
69
|
+
|
|
70
|
+
it "quits the session" do
|
|
71
|
+
res = @opensrs.quit_session
|
|
72
|
+
res.success?.should be_true
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|