gandirb 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +1 -0
  2. data/LICENSE +19 -0
  3. data/README +35 -0
  4. data/Rakefile +32 -0
  5. data/gandirb.gemspec +34 -0
  6. data/lib/gandi/base.rb +121 -0
  7. data/lib/gandi/domain.rb +134 -0
  8. data/lib/gandi/domain_modules/contact.rb +36 -0
  9. data/lib/gandi/domain_modules/host.rb +29 -0
  10. data/lib/gandi/domain_modules/mail.rb +80 -0
  11. data/lib/gandi/domain_modules/name_servers.rb +28 -0
  12. data/lib/gandi/domain_modules/operations.rb +30 -0
  13. data/lib/gandi/domain_modules/redirection.rb +25 -0
  14. data/lib/gandi.rb +9 -0
  15. data/rdoc/classes/Gandi/Base.html +397 -0
  16. data/rdoc/classes/Gandi/DataError.html +111 -0
  17. data/rdoc/classes/Gandi/Domain.html +623 -0
  18. data/rdoc/classes/Gandi/DomainModules/Contact.html +246 -0
  19. data/rdoc/classes/Gandi/DomainModules/Host.html +227 -0
  20. data/rdoc/classes/Gandi/DomainModules/NameServers.html +226 -0
  21. data/rdoc/classes/Gandi/DomainModules/Operations.html +229 -0
  22. data/rdoc/classes/Gandi/DomainModules/Redirection.html +215 -0
  23. data/rdoc/classes/Gandi/DomainModules.html +136 -0
  24. data/rdoc/classes/Gandi/ServerError.html +111 -0
  25. data/rdoc/classes/Gandi.html +153 -0
  26. data/rdoc/created.rid +1 -0
  27. data/rdoc/files/README.html +162 -0
  28. data/rdoc/files/lib/gandi/base_rb.html +109 -0
  29. data/rdoc/files/lib/gandi/domain_modules/contact_rb.html +101 -0
  30. data/rdoc/files/lib/gandi/domain_modules/host_rb.html +101 -0
  31. data/rdoc/files/lib/gandi/domain_modules/name_servers_rb.html +101 -0
  32. data/rdoc/files/lib/gandi/domain_modules/operations_rb.html +101 -0
  33. data/rdoc/files/lib/gandi/domain_modules/redirection_rb.html +101 -0
  34. data/rdoc/files/lib/gandi/domain_rb.html +101 -0
  35. data/rdoc/files/lib/gandi_rb.html +101 -0
  36. data/rdoc/fr_class_index.html +38 -0
  37. data/rdoc/fr_file_index.html +36 -0
  38. data/rdoc/fr_method_index.html +83 -0
  39. data/rdoc/index.html +24 -0
  40. data/rdoc/rdoc-style.css +208 -0
  41. data/test/gandi/base_test.rb +188 -0
  42. data/test/gandi/domain_test.rb +302 -0
  43. data/test/gandi_test.rb +9 -0
  44. data/test/test_helper.rb +9 -0
  45. metadata +124 -0
@@ -0,0 +1,302 @@
1
+ require 'test_helper'
2
+
3
+ class DomainTest < ActiveSupport::TestCase
4
+ def setup
5
+ @login = 'XX000-Gandi'
6
+ @password = 'dummy'
7
+ @uri = Gandi::Domain::TEST_URL
8
+
9
+ @session_id = "session id"
10
+ @sample_domain_name = "mydomain.com"
11
+ end
12
+
13
+ context "a new logged in Gandi::Domain instance" do
14
+ setup do
15
+ XMLRPC::Client.any_instance.expects(:call).at_least_once.with("login", @login, @password, false).returns(@session_id)
16
+ @gandi_domain = Gandi::Domain.login @login, @password, @uri
17
+ end
18
+
19
+ should "get domain list" do
20
+ @gandi_domain.handler.expects(:call).with("domain_list", @session_id).returns(["mydomain.com"])
21
+
22
+ assert @gandi_domain.domain_list.is_a? Array
23
+ end
24
+
25
+ context "mocking domain_available calls" do
26
+ setup do
27
+ @gandi_domain.handler.expects(:call).with("domain_available", @session_id, ['testdomain.com']).returns({"testdomain.com" => false})
28
+ end
29
+
30
+ should "return a hash when providing an array" do
31
+ assert_equal false, @gandi_domain.domain_available('testdomain.com')
32
+ end
33
+
34
+ should "return a boolean when providing a single domain" do
35
+ assert_equal({"testdomain.com" => false}, @gandi_domain.domain_available(['testdomain.com']))
36
+ end
37
+ end
38
+
39
+ context "with an existing domain" do
40
+ should "lock a domain" do
41
+ @gandi_domain.handler.expects(:call).with("domain_lock", @session_id, @sample_domain_name).returns(rand(9000))
42
+
43
+ assert @gandi_domain.domain_lock(@sample_domain_name).is_a? Integer
44
+ end
45
+
46
+ should "unlock a domain" do
47
+ @gandi_domain.handler.expects(:call).with("domain_unlock", @session_id, @sample_domain_name).returns(rand(9000))
48
+
49
+ assert @gandi_domain.domain_unlock(@sample_domain_name).is_a? Integer
50
+ end
51
+
52
+ #TODO: better test (use a hash similar to a real api call result)
53
+ should "get infos on a domain" do
54
+ @gandi_domain.handler.expects(:call).with("domain_info", @session_id, @sample_domain_name).returns({})
55
+
56
+ assert @gandi_domain.domain_info(@sample_domain_name).is_a? Hash
57
+ end
58
+
59
+ should "renew a domain for 8 years" do
60
+ @gandi_domain.handler.expects(:call).with("domain_renew", @session_id, @sample_domain_name, 8).returns(rand(9000))
61
+
62
+ assert @gandi_domain.domain_renew(@sample_domain_name, 8).is_a? Integer
63
+ end
64
+
65
+ should "not renew a domain for 11 years" do
66
+ assert_raise ArgumentError do
67
+ @gandi_domain.domain_renew(@sample_domain_name, 11)
68
+ end
69
+ end
70
+
71
+ should "restore a domain" do
72
+ @gandi_domain.handler.expects(:call).with("domain_restore", @session_id, @sample_domain_name).returns(rand(9000))
73
+
74
+ assert @gandi_domain.domain_restore(@sample_domain_name).is_a? Integer
75
+ end
76
+
77
+ should "not delete a domain" do
78
+ assert_raise NoMethodError do
79
+ @gandi_domain.domain_del(@sample_domain_name)
80
+ end
81
+ end
82
+
83
+ should "check if domain can be transferred" do
84
+ @gandi_domain.handler.expects(:call).with("domain_transfer_in_available", @session_id, @sample_domain_name).twice.returns(true)
85
+
86
+ available = @gandi_domain.domain_transfer_in_available(@sample_domain_name)
87
+ assert_equal true, available
88
+
89
+ assert_equal available, @gandi_domain.domain_transfer_in_available?(@sample_domain_name)
90
+ end
91
+
92
+ should "transfer a domain in" do
93
+ owner_handle, admin_handle, tech_handle, billing_handle = 'owner_handle', "admin_handle", 'tech_handle', 'billing_handle'
94
+ nameservers = ['127.0.0.1']
95
+ @gandi_domain.handler.expects(:call).with("domain_transfer_in", @session_id, @sample_domain_name, owner_handle, admin_handle, tech_handle, billing_handle, nameservers).returns(rand(9000))
96
+
97
+ assert @gandi_domain.domain_transfer_in(@sample_domain_name, owner_handle, admin_handle, tech_handle, billing_handle, nameservers).is_a? Integer
98
+ end
99
+
100
+ should "not transfer a domain out" do
101
+ assert_raise NoMethodError do
102
+ @gandi_domain.domain_transfer_out(@sample_domain_name, true)
103
+ end
104
+ end
105
+
106
+ should "not trade a domain" do
107
+ assert_raise NoMethodError do
108
+ @gandi_domain.domain_trade(@sample_domain_name, 'owner_handle', 'admin_handle', 'tech_handle', 'billing_handle')
109
+ end
110
+ end
111
+
112
+ should "not change owner of a domain" do
113
+ assert_raise NoMethodError do
114
+ @gandi_domain.domain_change_owner(@sample_domain_name, 'new_owner')
115
+ end
116
+ end
117
+
118
+ should "change contact for a domain" do
119
+ @gandi_domain.handler.expects(:call).with("domain_change_contact", @session_id, @sample_domain_name, 'admin', 'new-handle').returns(rand(9000))
120
+
121
+ assert @gandi_domain.domain_change_contact(@sample_domain_name, 'admin', 'new-handle').is_a? Integer
122
+ end
123
+ end
124
+
125
+ should "create a domain" do
126
+ domain, period, owner_handle, admin_handle, tech_handle, billing_handle = 'mynewdomain.com', 7, 'owner_handle', "admin_handle", 'tech_handle', 'billing_handle'
127
+ nameservers = ['127.0.0.1']
128
+ @gandi_domain.handler.expects(:call).with("domain_create", @session_id, domain, period, owner_handle, admin_handle, tech_handle, billing_handle, nameservers).returns(rand(9000))
129
+
130
+ assert @gandi_domain.domain_create(domain, period, owner_handle, admin_handle, tech_handle, billing_handle, nameservers).is_a? Integer
131
+ end
132
+
133
+ should "get domains list" do
134
+ tlds = ["info", "be", "eu", "name", "biz", "us", "org", "com", "net", "mobi", "ch", "li", "at", "asia", "de", "nu", "cz", "tw", "es", "lu", "pl", "pro", "me", "in"]
135
+
136
+ @gandi_domain.handler.expects(:call).with("tld_list", @session_id).returns(tlds)
137
+
138
+ assert_equal tlds, @gandi_domain.tld_list
139
+ end
140
+
141
+
142
+ should "list name servers for a domain" do
143
+ @gandi_domain.handler.expects(:call).with("domain_ns_list", @session_id, @sample_domain_name).returns([])
144
+
145
+ assert @gandi_domain.domain_ns_list(@sample_domain_name).is_a? Array
146
+ end
147
+
148
+ should "add name servers for a domain" do
149
+ @gandi_domain.handler.expects(:call).with("domain_ns_add", @session_id, @sample_domain_name, ['127.0.0.1']).returns(rand(9000))
150
+
151
+ assert @gandi_domain.domain_ns_add(@sample_domain_name, ['127.0.0.1']).is_a? Integer
152
+ end
153
+
154
+ should "remove name servers for a domain" do
155
+ @gandi_domain.handler.expects(:call).with("domain_ns_del", @session_id, @sample_domain_name, ['127.0.0.1']).returns(rand(9000))
156
+
157
+ assert @gandi_domain.domain_ns_del(@sample_domain_name, ['127.0.0.1']).is_a? Integer
158
+ end
159
+
160
+ should "set name servers for a domain" do
161
+ @gandi_domain.handler.expects(:call).with("domain_ns_set", @session_id, @sample_domain_name, ['127.0.0.1']).returns(rand(9000))
162
+
163
+ assert @gandi_domain.domain_ns_set(@sample_domain_name, ['127.0.0.1']).is_a? Integer
164
+ end
165
+
166
+
167
+ should "list hosts for a domain" do
168
+ @gandi_domain.handler.expects(:call).with("host_list", @session_id, @sample_domain_name).returns([])
169
+
170
+ assert @gandi_domain.host_list(@sample_domain_name).is_a? Array
171
+ end
172
+
173
+ should "get IPs for a domain" do
174
+ ips = ['127.0.0.1']
175
+ @gandi_domain.handler.expects(:call).with("host_info", @session_id, @sample_domain_name).returns(ips)
176
+
177
+ assert @gandi_domain.host_info(@sample_domain_name).is_a? Array
178
+ end
179
+
180
+ should "create a glue record for a host when providing multiple IPs" do
181
+ ip_list = ["1.2.3.4", "1.2.3.5"]
182
+ @gandi_domain.handler.expects(:call).with("host_create", @session_id, @sample_domain_name, ip_list).returns(rand(9000))
183
+
184
+ assert @gandi_domain.host_create(@sample_domain_name, ip_list).is_a? Integer
185
+ end
186
+
187
+ should "create a glue record for a host when providing an unique IP" do
188
+ ip = "1.2.3.4"
189
+ @gandi_domain.handler.expects(:call).with("host_create", @session_id, @sample_domain_name, [ip]).returns(rand(9000))
190
+
191
+ assert @gandi_domain.host_create(@sample_domain_name, ip).is_a? Integer
192
+ end
193
+
194
+ should "delete a host" do
195
+ @gandi_domain.handler.expects(:call).with("host_delete", @session_id, @sample_domain_name).returns(rand(9000))
196
+
197
+ assert @gandi_domain.host_delete(@sample_domain_name).is_a? Integer
198
+ end
199
+
200
+
201
+ should "list redirections for a domain" do
202
+ redirections = [{"type" => "http302", "from" => "w3.example.net", "to" => "http://www.example.net"}]
203
+ @gandi_domain.handler.expects(:call).with("domain_web_redir_list", @session_id, @sample_domain_name).returns(redirections)
204
+
205
+ assert_equal redirections, @gandi_domain.domain_web_redir_list(@sample_domain_name)
206
+ end
207
+
208
+ should "check redirection type when adding a redirection for a domain" do
209
+ fqdn = "w3.example.net"
210
+ destination_url = "http://www.example.net"
211
+
212
+ calls = states('calls').starts_as('none')
213
+ @gandi_domain.handler.expects(:call).with("domain_web_redir_add", @session_id, @sample_domain_name, fqdn, destination_url, 'http302').returns(rand(9000)).when(calls.is('none')).then(calls.is('first'))
214
+ @gandi_domain.handler.expects(:call).with("domain_web_redir_add", @session_id, @sample_domain_name, fqdn, destination_url, 'http301').returns(rand(9000)).when(calls.is('first')).then(calls.is('second'))
215
+ @gandi_domain.handler.expects(:call).with("domain_web_redir_add", @session_id, @sample_domain_name, fqdn, destination_url, 'cloak').returns(rand(9000)).when(calls.is('second'))
216
+
217
+ Gandi::DomainModules::Redirection::DOMAIN_WEB_REDIR_REDIRECTION_TYPES.each do |type|
218
+ assert @gandi_domain.domain_web_redir_add(@sample_domain_name, fqdn, destination_url, type).is_a? Integer
219
+ end
220
+
221
+ assert_raise ArgumentError do
222
+ @gandi_domain.domain_web_redir_add(@sample_domain_name, fqdn, destination_url, 'bad')
223
+ end
224
+ end
225
+
226
+ should "delete the redirection on a fqdn" do
227
+ @gandi_domain.handler.expects(:call).with("domain_web_redir_del", @session_id, 'w3.example.net').returns(rand(9000))
228
+
229
+ assert @gandi_domain.domain_web_redir_del('w3.example.net').is_a? Integer
230
+ end
231
+
232
+
233
+ should "create a contact" do
234
+ contact_class, firstname, lastname, address, zipcode, city, country, phone, email = 'individual', 'John', 'Doe', '24 Rue du Pont', '13000', 'Mars', 'France', '+33491909090', 'john@doe.com'
235
+ @gandi_domain.handler.expects(:call).with("contact_create", @session_id, contact_class, firstname, lastname, address, zipcode, city, country, phone, email).returns('XXXZZ-Gandi')
236
+
237
+ assert_match /.+-Gandi/, @gandi_domain.contact_create(contact_class, firstname, lastname, address, zipcode, city, country, phone, email)
238
+ end
239
+
240
+ should "update a contact" do
241
+ handle = 'XXXYY-Gandi'
242
+ params = {}
243
+ @gandi_domain.handler.expects(:call).with("contact_update", @session_id, handle, params).returns(rand(9000))
244
+
245
+ assert @gandi_domain.contact_update(handle, params).is_a? Integer
246
+ end
247
+
248
+ should "delete a contact" do
249
+ handle = 'XXXYY-Gandi'
250
+ @gandi_domain.handler.expects(:call).with("contact_del", @session_id, handle).returns(rand(9000))
251
+
252
+ assert @gandi_domain.contact_del(handle).is_a? Integer
253
+ end
254
+
255
+ should "retrieve infos on a contact" do
256
+ handle = 'XXXYY-Gandi'
257
+ infos = {}
258
+ @gandi_domain.handler.expects(:call).with("contact_info", @session_id, handle).returns(infos)
259
+
260
+ assert @gandi_domain.contact_info(handle).is_a? Hash
261
+ end
262
+
263
+
264
+ should "list operations" do
265
+ operations = [5555, 5642, 6213]
266
+ @gandi_domain.handler.expects(:call).with("operation_list", @session_id).returns(operations)
267
+
268
+ assert_equal operations, @gandi_domain.operation_list()
269
+ end
270
+
271
+ should "list pending operations with a filter" do
272
+ operations = [5555]
273
+ filter = {'state' => 'PENDING'}
274
+ @gandi_domain.handler.expects(:call).with("operation_list", @session_id, filter).returns(operations)
275
+
276
+ assert_equal operations, @gandi_domain.operation_list(filter)
277
+ end
278
+
279
+ should "get operation details" do
280
+ opid = 5555
281
+ details = {}
282
+ @gandi_domain.handler.expects(:call).with("operation_details", @session_id, opid).returns(details)
283
+
284
+ assert @gandi_domain.operation_details(opid).is_a? Hash
285
+ end
286
+
287
+ should "relaunch an operation" do
288
+ opid = 5555
289
+ param = {'authcode' => 'xxxyyyzzz'}
290
+ @gandi_domain.handler.expects(:call).with("operation_relaunch", @session_id, opid, param).returns(true)
291
+
292
+ assert @gandi_domain.operation_relaunch(opid, param)
293
+ end
294
+
295
+ should "cancel an operation" do
296
+ opid = 5555
297
+ @gandi_domain.handler.expects(:call).with("operation_cancel", @session_id, opid).returns(true)
298
+
299
+ assert @gandi_domain.operation_cancel(opid)
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class GandiTest < ActiveSupport::TestCase
4
+
5
+ should "define custom errors mapping Gandi error codes" do
6
+ assert Gandi::DataError.ancestors.include? ArgumentError
7
+ assert Gandi::ServerError.ancestors.include? RuntimeError
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ require 'shoulda'
7
+ require 'mocha'
8
+
9
+ require 'gandi'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gandirb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Pickabee
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-04-30 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: " This is a ruby library for using Gandi XML-RPC API.\n It should only support the domain and mail API, but may be extensible enough to add hosting in the future.\n"
21
+ email: ""
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - CHANGELOG
28
+ - LICENSE
29
+ - README
30
+ - lib/gandi.rb
31
+ - lib/gandi/base.rb
32
+ - lib/gandi/domain.rb
33
+ - lib/gandi/domain_modules/contact.rb
34
+ - lib/gandi/domain_modules/host.rb
35
+ - lib/gandi/domain_modules/mail.rb
36
+ - lib/gandi/domain_modules/name_servers.rb
37
+ - lib/gandi/domain_modules/operations.rb
38
+ - lib/gandi/domain_modules/redirection.rb
39
+ files:
40
+ - CHANGELOG
41
+ - LICENSE
42
+ - README
43
+ - Rakefile
44
+ - lib/gandi.rb
45
+ - lib/gandi/base.rb
46
+ - lib/gandi/domain.rb
47
+ - lib/gandi/domain_modules/contact.rb
48
+ - lib/gandi/domain_modules/host.rb
49
+ - lib/gandi/domain_modules/mail.rb
50
+ - lib/gandi/domain_modules/name_servers.rb
51
+ - lib/gandi/domain_modules/operations.rb
52
+ - lib/gandi/domain_modules/redirection.rb
53
+ - rdoc/classes/Gandi.html
54
+ - rdoc/classes/Gandi/Base.html
55
+ - rdoc/classes/Gandi/DataError.html
56
+ - rdoc/classes/Gandi/Domain.html
57
+ - rdoc/classes/Gandi/DomainModules.html
58
+ - rdoc/classes/Gandi/DomainModules/Contact.html
59
+ - rdoc/classes/Gandi/DomainModules/Host.html
60
+ - rdoc/classes/Gandi/DomainModules/NameServers.html
61
+ - rdoc/classes/Gandi/DomainModules/Operations.html
62
+ - rdoc/classes/Gandi/DomainModules/Redirection.html
63
+ - rdoc/classes/Gandi/ServerError.html
64
+ - rdoc/created.rid
65
+ - rdoc/files/README.html
66
+ - rdoc/files/lib/gandi/base_rb.html
67
+ - rdoc/files/lib/gandi/domain_modules/contact_rb.html
68
+ - rdoc/files/lib/gandi/domain_modules/host_rb.html
69
+ - rdoc/files/lib/gandi/domain_modules/name_servers_rb.html
70
+ - rdoc/files/lib/gandi/domain_modules/operations_rb.html
71
+ - rdoc/files/lib/gandi/domain_modules/redirection_rb.html
72
+ - rdoc/files/lib/gandi/domain_rb.html
73
+ - rdoc/files/lib/gandi_rb.html
74
+ - rdoc/fr_class_index.html
75
+ - rdoc/fr_file_index.html
76
+ - rdoc/fr_method_index.html
77
+ - rdoc/index.html
78
+ - rdoc/rdoc-style.css
79
+ - test/gandi/base_test.rb
80
+ - test/gandi/domain_test.rb
81
+ - test/gandi_test.rb
82
+ - test/test_helper.rb
83
+ - gandirb.gemspec
84
+ has_rdoc: true
85
+ homepage: http://github.com/pickabee/gandirb
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --line-numbers
91
+ - --inline-source
92
+ - --title
93
+ - Gandirb
94
+ - --main
95
+ - README
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 1
111
+ - 2
112
+ version: "1.2"
113
+ requirements: []
114
+
115
+ rubyforge_project: gandirb
116
+ rubygems_version: 1.3.6
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Ruby library for using Gandi XML-RPC API
120
+ test_files:
121
+ - test/gandi/domain_test.rb
122
+ - test/gandi/base_test.rb
123
+ - test/gandi_test.rb
124
+ - test/test_helper.rb