linode 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +2 -0
- data/MIT-LICENSE +20 -0
- data/README +138 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/lib/linode.rb +79 -0
- data/lib/linode/avail.rb +3 -0
- data/lib/linode/domain.rb +4 -0
- data/lib/linode/domain/resource.rb +3 -0
- data/lib/linode/linode.rb +4 -0
- data/lib/linode/linode/config.rb +3 -0
- data/lib/linode/linode/disk.rb +3 -0
- data/lib/linode/linode/ip.rb +3 -0
- data/lib/linode/linode/job.rb +3 -0
- data/lib/linode/test.rb +3 -0
- data/lib/linode/user.rb +3 -0
- data/linode.gemspec +84 -0
- data/spec/linode/avail_spec.rb +45 -0
- data/spec/linode/domain/resource_spec.rb +44 -0
- data/spec/linode/domain_spec.rb +82 -0
- data/spec/linode/linode/config_spec.rb +44 -0
- data/spec/linode/linode/disk_spec.rb +44 -0
- data/spec/linode/linode/ip_spec.rb +44 -0
- data/spec/linode/linode/job_spec.rb +44 -0
- data/spec/linode/linode_spec.rb +196 -0
- data/spec/linode/test_spec.rb +45 -0
- data/spec/linode/user_spec.rb +45 -0
- data/spec/linode_spec.rb +350 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +22 -0
- metadata +105 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode::Test do
|
5
|
+
before :each do
|
6
|
+
@api_key = 'foo'
|
7
|
+
@linode = Linode::Test.new(:api_key => @api_key)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be a Linode instance' do
|
11
|
+
@linode.class.should < Linode
|
12
|
+
end
|
13
|
+
|
14
|
+
["echo"].each do |action|
|
15
|
+
|
16
|
+
it "should allow accessing the #{action} API" do
|
17
|
+
@linode.should respond_to(action.to_sym)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "when accessing the #{action} API" do
|
21
|
+
it 'should allow a data hash' do
|
22
|
+
lambda { @linode.send(action.to_sym, {}) }.should_not raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not require arguments' do
|
26
|
+
lambda { @linode.send(action.to_sym) }.should_not raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should request the test.#{action} action" do
|
30
|
+
@linode.expects(:send_request).with {|api_action, data| api_action == "test.#{action}" }
|
31
|
+
@linode.send(action.to_sym)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should provide the data hash when making its request' do
|
35
|
+
@linode.expects(:send_request).with {|api_action, data| data = { :foo => :bar } }
|
36
|
+
@linode.send(action.to_sym, {:foo => :bar})
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return the result of the request' do
|
40
|
+
@linode.expects(:send_request).returns(:bar => :baz)
|
41
|
+
@linode.send(action.to_sym).should == { :bar => :baz }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode::User do
|
5
|
+
before :each do
|
6
|
+
@api_key = 'foo'
|
7
|
+
@linode = Linode::User.new(:api_key => @api_key)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be a Linode instance' do
|
11
|
+
@linode.class.should < Linode
|
12
|
+
end
|
13
|
+
|
14
|
+
%w(getapikey).each do |action|
|
15
|
+
it "should allow accessing the #{action} API" do
|
16
|
+
@linode.should respond_to(action.to_sym)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when accessing the #{action} API" do
|
20
|
+
it 'should allow a data hash' do
|
21
|
+
lambda { @linode.send(action.to_sym, {}) }.should_not raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should not require arguments' do
|
25
|
+
lambda { @linode.send(action.to_sym) }.should_not raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should request the user.#{action} action" do
|
29
|
+
@linode.expects(:send_request).with {|api_action, data| api_action == "user.#{action}" }
|
30
|
+
@linode.send(action.to_sym)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should provide the data hash when making its request' do
|
34
|
+
@linode.expects(:send_request).with {|api_action, data| data = { :foo => :bar } }
|
35
|
+
@linode.send(action.to_sym, {:foo => :bar})
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return the result of the request' do
|
39
|
+
@linode.expects(:send_request).returns(:bar => :baz)
|
40
|
+
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/spec/linode_spec.rb
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode do
|
5
|
+
describe 'as a class' do
|
6
|
+
it 'should be able to create a new Linode instance' do
|
7
|
+
Linode.should respond_to(:new)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating a new Linode instance' do
|
11
|
+
it 'should accept an arguments hash' do
|
12
|
+
lambda { Linode.new(:api_key => 'foo') }.should_not raise_error(ArgumentError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should require an arguments hash' do
|
16
|
+
lambda { Linode.new }.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should fail if no API key is given' do
|
20
|
+
lambda { Linode.new({}) }.should raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return a Linode instance' do
|
24
|
+
Linode.new(:api_key => 'foo').class.should == Linode
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'Linode' do
|
31
|
+
before :each do
|
32
|
+
@api_key = 'foo'
|
33
|
+
@api_url = 'https://fake.linode.com/'
|
34
|
+
@linode = Linode.new(:api_key => @api_key, :api_url => @api_url)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should be able to return the API key provided at creation time' do
|
38
|
+
@linode.api_key.should == 'foo'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should be able to return the current API URL' do
|
42
|
+
@linode.should respond_to(:api_url)
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'when returning the current API URL' do
|
46
|
+
it 'should return the API URL provided at creation time if one was provided' do
|
47
|
+
@linode = Linode.new(:api_key => @api_key, :api_url => 'https://fake.linode.com/')
|
48
|
+
@linode.api_url.should == 'https://fake.linode.com/'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return the stock linode API URL if none was provided at creation time' do
|
52
|
+
@linode = Linode.new(:api_key => @api_key)
|
53
|
+
@linode.api_url.should == 'https://api.linode.com/'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should be able to submit a request via the API' do
|
58
|
+
@linode.should respond_to(:send_request)
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'when submitting a request via the API' do
|
62
|
+
before :each do
|
63
|
+
@json = %Q!{
|
64
|
+
"ERRORARRAY":[],
|
65
|
+
"ACTION":"test.echo",
|
66
|
+
"DATA":{"FOO":"bar"}
|
67
|
+
}!
|
68
|
+
HTTParty.stubs(:get).returns(@json)
|
69
|
+
@linode.stubs(:api_url).returns('https://fake.linode.com/')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should allow a request name and a data hash' do
|
73
|
+
lambda { @linode.send_request('test.echo', {}) }.should_not raise_error(ArgumentError)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should require a request name and a data hash' do
|
77
|
+
lambda { @linode.send_request('test.echo') }.should raise_error(ArgumentError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should make a request to the API url' do
|
81
|
+
@linode.stubs(:api_url).returns('https://fake.linode.com/')
|
82
|
+
HTTParty.expects(:get).with { |path, args|
|
83
|
+
path == 'https://fake.linode.com/'
|
84
|
+
}.returns(@json)
|
85
|
+
@linode.send_request('test.echo', { })
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should provide the API key when making its request' do
|
89
|
+
HTTParty.expects(:get).with { |path, args|
|
90
|
+
args[:query][:api_key] == @api_key
|
91
|
+
}.returns(@json)
|
92
|
+
@linode.send_request('test.echo', { })
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should set the designated request method as the HTTP API action' do
|
96
|
+
HTTParty.expects(:get).with { |path, args|
|
97
|
+
args[:query][:api_action] == 'test.echo'
|
98
|
+
}.returns(@json)
|
99
|
+
@linode.send_request('test.echo', { })
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should set the response format to JSON' do
|
103
|
+
HTTParty.expects(:get).with { |path, args|
|
104
|
+
args[:query][:api_responseFormat] == 'json'
|
105
|
+
}.returns(@json)
|
106
|
+
@linode.send_request('test.echo', { })
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should provide the data hash to the HTTP API request' do
|
110
|
+
HTTParty.expects(:get).with { |path, args|
|
111
|
+
args[:query]['foo'] == 'bar'
|
112
|
+
}.returns(@json)
|
113
|
+
@linode.send_request('test.echo', { 'foo' => 'bar' })
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should not allow overriding the API key via the data hash' do
|
117
|
+
HTTParty.expects(:get).with { |path, args|
|
118
|
+
args[:query][:api_key] == @api_key
|
119
|
+
}.returns(@json)
|
120
|
+
@linode.send_request('test.echo', { :api_key => 'h4x0r' })
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should not allow overriding the API action via the data hash' do
|
124
|
+
HTTParty.expects(:get).with { |path, args|
|
125
|
+
args[:query][:api_action] == 'test.echo'
|
126
|
+
}.returns(@json)
|
127
|
+
@linode.send_request('test.echo', { :api_action => 'h4x0r' })
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should not allow overriding the API response format via the data hash' do
|
131
|
+
HTTParty.expects(:get).with { |path, args|
|
132
|
+
args[:query][:api_responseFormat] == 'json'
|
133
|
+
}.returns(@json)
|
134
|
+
@linode.send_request('test.echo', { :api_responseFormat => 'h4x0r' })
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should fail when the request submission fails' do
|
138
|
+
HTTParty.stubs(:get).returns(%Q!{
|
139
|
+
"ERRORARRAY":["failure"],
|
140
|
+
"ACTION":"test.echo",
|
141
|
+
"DATA":{"foo":"bar"}
|
142
|
+
}!)
|
143
|
+
lambda { @linode.send_request('test.echo', { :api_action => 'failure' }) }.should raise_error
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'when the result is a list of hashes' do
|
147
|
+
it 'should return a list of objects with lower-cased methods for the data fields' do
|
148
|
+
HTTParty.stubs(:get).returns(%Q!{
|
149
|
+
"ERRORARRAY":[],
|
150
|
+
"ACTION":"test.echo",
|
151
|
+
"DATA":[{"FOO":"bar"},{"BAR":"baz"}]
|
152
|
+
}!)
|
153
|
+
@linode.send_request('test.echo', {}).first.foo.should == 'bar'
|
154
|
+
@linode.send_request('test.echo', {}).last.bar.should == 'baz'
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should return a list of objects which do not respond to upper-case URLs for the data fields' do
|
158
|
+
HTTParty.stubs(:get).returns(%Q!{
|
159
|
+
"ERRORARRAY":[],
|
160
|
+
"ACTION":"test.echo",
|
161
|
+
"DATA":[{"FOO":"bar"},{"BAR":"baz"}]
|
162
|
+
}!)
|
163
|
+
@linode.send_request('test.echo', {}).first.should_not respond_to(:FOO)
|
164
|
+
@linode.send_request('test.echo', {}).last.should_not respond_to(:BAR)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'when the result is a hash' do
|
169
|
+
it 'should return an object with lower-cased methods for the data fields' do
|
170
|
+
@linode.send_request('test.echo', {}).foo.should == 'bar'
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should return an object which does not respond to upper-case URLs for the data fields' do
|
174
|
+
@linode.send_request('test.echo', {}).should_not respond_to(:FOO)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe 'when the result is neither a list nor a hash' do
|
179
|
+
it 'should return the result unchanged' do
|
180
|
+
HTTParty.stubs(:get).returns(%Q!{
|
181
|
+
"ERRORARRAY":[],
|
182
|
+
"ACTION":"test.echo",
|
183
|
+
"DATA":"thingie"
|
184
|
+
}!)
|
185
|
+
@linode.send_request('test.echo', {}).should == "thingie"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should be able to provide access to the Linode Test API' do
|
191
|
+
@linode.should respond_to(:test)
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'when providing access to the Linode Test API' do
|
195
|
+
it 'should allow no arguments' do
|
196
|
+
lambda { @linode.test }.should_not raise_error(ArgumentError)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should require no arguments' do
|
200
|
+
lambda { @linode.test(:foo) }.should raise_error(ArgumentError)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should return a Linode::Test instance' do
|
204
|
+
@linode.test.class.should == Linode::Test
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should set the API key on the Linode::Test instance to be our API key' do
|
208
|
+
@linode.test.api_key.should == @api_key
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should set the API URL on the Linode::Test instance to be our API URL' do
|
212
|
+
@linode.test.api_url.should == @api_url
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should return the same Linode::Test instance when called again' do
|
216
|
+
linode = Linode.new(:api_key => @api_key)
|
217
|
+
result = linode.test
|
218
|
+
linode.test.should == result
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should be able to provide access to the Linode Avail API' do
|
223
|
+
@linode.should respond_to(:avail)
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'when providing access to the Linode Avail API' do
|
227
|
+
it 'should allow no arguments' do
|
228
|
+
lambda { @linode.avail }.should_not raise_error(ArgumentError)
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should require no arguments' do
|
232
|
+
lambda { @linode.avail(:foo) }.should raise_error(ArgumentError)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should return a Linode::Avail instance' do
|
236
|
+
@linode.avail.class.should == Linode::Avail
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should set the API key on the Linode::Avail instance to be our API key' do
|
240
|
+
@linode.avail.api_key.should == @api_key
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should set the API url on the Linode::Avail instance to be our API url' do
|
244
|
+
@linode.avail.api_url.should == @api_url
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should return the same Linode::Avail instance when called again' do
|
248
|
+
linode = Linode.new(:api_key => @api_key)
|
249
|
+
result = linode.avail
|
250
|
+
linode.avail.should == result
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should be able to provide access to the Linode User API' do
|
255
|
+
@linode.should respond_to(:user)
|
256
|
+
end
|
257
|
+
|
258
|
+
describe 'when providing access to the Linode User API' do
|
259
|
+
it 'should allow no arguments' do
|
260
|
+
lambda { @linode.user }.should_not raise_error(ArgumentError)
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should require no arguments' do
|
264
|
+
lambda { @linode.user(:foo) }.should raise_error(ArgumentError)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should return a Linode::User instance' do
|
268
|
+
@linode.user.class.should == Linode::User
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should set the API key on the Linode::User instance to be our API key' do
|
272
|
+
@linode.user.api_key.should == @api_key
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should set the API url on the Linode::User instance to be our API url' do
|
276
|
+
@linode.user.api_url.should == @api_url
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'should return the same Linode::User instance when called again' do
|
280
|
+
linode = Linode.new(:api_key => @api_key)
|
281
|
+
result = linode.user
|
282
|
+
linode.user.should == result
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should be able to provide access to the Linode Domain API' do
|
287
|
+
@linode.should respond_to(:domain)
|
288
|
+
end
|
289
|
+
|
290
|
+
describe 'when providing access to the Linode Domain API' do
|
291
|
+
it 'should allow no arguments' do
|
292
|
+
lambda { @linode.domain }.should_not raise_error(ArgumentError)
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'should require no arguments' do
|
296
|
+
lambda { @linode.domain(:foo) }.should raise_error(ArgumentError)
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'should return a Linode::Domain instance' do
|
300
|
+
@linode.domain.class.should == Linode::Domain
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should set the API key on the Linode::Domain instance to be our API key' do
|
304
|
+
@linode.domain.api_key.should == @api_key
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should set the API url on the Linode::Domain instance to be our API url' do
|
308
|
+
@linode.domain.api_url.should == @api_url
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'should return the same Linode::Domain instance when called again' do
|
312
|
+
linode = Linode.new(:api_key => @api_key)
|
313
|
+
result = linode.domain
|
314
|
+
linode.domain.should == result
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should be able to provide access to the Linode Linode API' do
|
319
|
+
@linode.should respond_to(:linode)
|
320
|
+
end
|
321
|
+
|
322
|
+
describe 'when providing access to the Linode Linode API' do
|
323
|
+
it 'should allow no arguments' do
|
324
|
+
lambda { @linode.linode }.should_not raise_error(ArgumentError)
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should require no arguments' do
|
328
|
+
lambda { @linode.linode(:foo) }.should raise_error(ArgumentError)
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'should return a Linode::Linode instance' do
|
332
|
+
@linode.linode.class.should == Linode::Linode
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should set the API key on the Linode::Linode instance to be our API key' do
|
336
|
+
@linode.linode.api_key.should == @api_key
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'should set the API url on the Linode::Linode instance to be our API url' do
|
340
|
+
@linode.linode.api_url.should == @api_url
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should return the same Linode::Linode instance when called again' do
|
344
|
+
linode = Linode.new(:api_key => @api_key)
|
345
|
+
result = linode.linode
|
346
|
+
linode.linode.should == result
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|