linode 0.6.3 → 0.7.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/CHANGELOG +7 -0
- data/README +1 -0
- data/VERSION +1 -1
- data/lib/linode.rb +30 -7
- data/lib/linode/avail.rb +1 -0
- data/lib/linode/domain.rb +1 -0
- data/lib/linode/domain/resource.rb +1 -0
- data/lib/linode/linode.rb +1 -0
- data/lib/linode/linode/config.rb +1 -0
- data/lib/linode/linode/disk.rb +1 -0
- data/lib/linode/linode/ip.rb +1 -0
- data/lib/linode/linode/job.rb +1 -0
- data/lib/linode/nodebalancer.rb +5 -0
- data/lib/linode/nodebalancer/config.rb +4 -0
- data/lib/linode/nodebalancer/node.rb +4 -0
- data/lib/linode/stackscript.rb +1 -0
- data/lib/linode/test.rb +1 -0
- data/lib/linode/user.rb +2 -0
- data/linode.gemspec +11 -2
- data/spec/linode/avail_spec.rb +4 -1
- data/spec/linode/domain/resource_spec.rb +4 -0
- data/spec/linode/domain_spec.rb +4 -0
- data/spec/linode/linode/config_spec.rb +4 -0
- data/spec/linode/linode/disk_spec.rb +4 -0
- data/spec/linode/linode/ip_spec.rb +4 -0
- data/spec/linode/linode/job_spec.rb +4 -0
- data/spec/linode/linode_spec.rb +4 -0
- data/spec/linode/nodebalancer/config_spec.rb +48 -0
- data/spec/linode/nodebalancer/node_spec.rb +48 -0
- data/spec/linode/nodebalancer_spec.rb +124 -0
- data/spec/linode/stackscript_spec.rb +4 -0
- data/spec/linode/test_spec.rb +4 -0
- data/spec/linode/user_spec.rb +4 -0
- data/spec/linode_spec.rb +54 -22
- metadata +14 -5
data/CHANGELOG
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
|
2
|
+
0.7.0 / 2011-07-07
|
3
|
+
==================
|
4
|
+
* Added support for Nodebalancer API calls
|
5
|
+
* Changed HTTP GETs to HTTP POSTs to work around errors with large stackscripts (credit: Dan Hodos)
|
6
|
+
* Updated documentation references in error messages to match API documentation on Linode website
|
7
|
+
|
8
|
+
|
2
9
|
0.6.3 / 2010-11-23
|
3
10
|
==================
|
4
11
|
* Can now initialize w/ username/pass; also support for user.getapikey API call
|
data/README
CHANGED
@@ -140,4 +140,5 @@ Here is an annoyingly exhaustive IRB session where I play around with the API:
|
|
140
140
|
irb> ^D@ Wed Aug 05 01:50:52 rick@Yer-Moms-Computer
|
141
141
|
|
142
142
|
CREDITS:
|
143
|
+
- Thanks to Dan Hodos (github: danhodos) for diagnosing and fixing an issue with sending GET requests instead of POST request.
|
143
144
|
- Thanks to Aaron Hamid for updates for RSpec 2 and work on user.getapikey + username/password initialization.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/linode.rb
CHANGED
@@ -10,7 +10,7 @@ class Linode
|
|
10
10
|
define_method(action.to_sym) do |*data|
|
11
11
|
data = data.shift if data
|
12
12
|
data ||= {}
|
13
|
-
send_request(self.class.name
|
13
|
+
send_request(Linode.action_path(self.class.name, action), data)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -27,7 +27,30 @@ class Linode
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
has_namespace :test, :avail, :user, :domain, :linode
|
30
|
+
has_namespace :test, :avail, :user, :domain, :linode, :nodebalancer
|
31
|
+
|
32
|
+
@@documentation_category = {}
|
33
|
+
|
34
|
+
def self.documentation_category(category)
|
35
|
+
@@documentation_category[class_to_path(name)] = category
|
36
|
+
end
|
37
|
+
|
38
|
+
def documentation_categories
|
39
|
+
@@documentation_category
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.action_path(class_name, action)
|
43
|
+
Linode.class_to_path(class_name) + ".#{action}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.class_to_path(class_name)
|
47
|
+
class_name.downcase.sub(/^linode::/, '').gsub(/::/, '.')
|
48
|
+
end
|
49
|
+
|
50
|
+
def documentation_path(action)
|
51
|
+
hits = action.match(/^(.*)\.[^.]+$/)
|
52
|
+
"http://www.linode.com/api/" + @@documentation_category[hits[1]] + '/' + action
|
53
|
+
end
|
31
54
|
|
32
55
|
def initialize(args)
|
33
56
|
@api_url = args[:api_url] if args[:api_url]
|
@@ -52,7 +75,7 @@ class Linode
|
|
52
75
|
|
53
76
|
def send_request(action, data)
|
54
77
|
data.delete_if {|k,v| [:api_key, :api_action, :api_responseFormat].include?(k) }
|
55
|
-
response =
|
78
|
+
response = post({ :api_key => api_key, :api_action => action, :api_responseFormat => 'json' }.merge(data))
|
56
79
|
raise "Errors completing request [#{action}] @ [#{api_url}] with data [#{data.inspect}]:\n#{error_message(response, action)}" if error?(response)
|
57
80
|
reformat_response(response)
|
58
81
|
end
|
@@ -60,13 +83,13 @@ class Linode
|
|
60
83
|
protected
|
61
84
|
|
62
85
|
def fetch_api_key
|
63
|
-
response =
|
86
|
+
response = post(:api_action => 'user.getapikey', :api_responseFormat => 'json', :username => username, :password => password)
|
64
87
|
raise "Errors completing request [user.getapikey] @ [#{api_url}] for username [#{username}]:\n#{error_message(response, 'user.getapikey')}" if error?(response)
|
65
88
|
reformat_response(response).api_key
|
66
89
|
end
|
67
90
|
|
68
|
-
def
|
69
|
-
Crack::JSON.parse(HTTParty.
|
91
|
+
def post(data)
|
92
|
+
Crack::JSON.parse(HTTParty.post(api_url, :body => data))
|
70
93
|
end
|
71
94
|
|
72
95
|
def error?(response)
|
@@ -76,7 +99,7 @@ class Linode
|
|
76
99
|
def error_message(response, action)
|
77
100
|
response["ERRORARRAY"].collect { |err|
|
78
101
|
" - Error \##{err["ERRORCODE"]} - #{err["ERRORMESSAGE"]}. "+
|
79
|
-
"(Please consult
|
102
|
+
"(Please consult #{documentation_path(action)})"
|
80
103
|
}.join("\n")
|
81
104
|
end
|
82
105
|
|
data/lib/linode/avail.rb
CHANGED
data/lib/linode/domain.rb
CHANGED
data/lib/linode/linode.rb
CHANGED
data/lib/linode/linode/config.rb
CHANGED
data/lib/linode/linode/disk.rb
CHANGED
data/lib/linode/linode/ip.rb
CHANGED
data/lib/linode/linode/job.rb
CHANGED
data/lib/linode/stackscript.rb
CHANGED
data/lib/linode/test.rb
CHANGED
data/lib/linode/user.rb
CHANGED
data/linode.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{linode}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rick Bradley"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-07-07}
|
13
13
|
s.description = %q{This is a wrapper around Linode's automation facilities.}
|
14
14
|
s.email = %q{rick@rickbradley.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/linode/linode/disk.rb",
|
33
33
|
"lib/linode/linode/ip.rb",
|
34
34
|
"lib/linode/linode/job.rb",
|
35
|
+
"lib/linode/nodebalancer.rb",
|
36
|
+
"lib/linode/nodebalancer/config.rb",
|
37
|
+
"lib/linode/nodebalancer/node.rb",
|
35
38
|
"lib/linode/stackscript.rb",
|
36
39
|
"lib/linode/test.rb",
|
37
40
|
"lib/linode/user.rb",
|
@@ -44,6 +47,9 @@ Gem::Specification.new do |s|
|
|
44
47
|
"spec/linode/linode/ip_spec.rb",
|
45
48
|
"spec/linode/linode/job_spec.rb",
|
46
49
|
"spec/linode/linode_spec.rb",
|
50
|
+
"spec/linode/nodebalancer/config_spec.rb",
|
51
|
+
"spec/linode/nodebalancer/node_spec.rb",
|
52
|
+
"spec/linode/nodebalancer_spec.rb",
|
47
53
|
"spec/linode/stackscript_spec.rb",
|
48
54
|
"spec/linode/test_spec.rb",
|
49
55
|
"spec/linode/user_spec.rb",
|
@@ -63,6 +69,9 @@ Gem::Specification.new do |s|
|
|
63
69
|
"spec/linode/linode/ip_spec.rb",
|
64
70
|
"spec/linode/linode/job_spec.rb",
|
65
71
|
"spec/linode/linode_spec.rb",
|
72
|
+
"spec/linode/nodebalancer/config_spec.rb",
|
73
|
+
"spec/linode/nodebalancer/node_spec.rb",
|
74
|
+
"spec/linode/nodebalancer_spec.rb",
|
66
75
|
"spec/linode/stackscript_spec.rb",
|
67
76
|
"spec/linode/test_spec.rb",
|
68
77
|
"spec/linode/user_spec.rb",
|
data/spec/linode/avail_spec.rb
CHANGED
@@ -39,7 +39,10 @@ describe Linode::Avail do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/utility/avail.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/utility/avail.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
|
-
|
45
48
|
end
|
@@ -39,6 +39,10 @@ describe Linode::Domain::Resource do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/dns/domain.resource.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/dns/domain.resource.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
data/spec/linode/domain_spec.rb
CHANGED
@@ -39,6 +39,10 @@ describe Linode::Domain do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/dns/domain.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/dns/domain.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -39,6 +39,10 @@ describe Linode::Linode::Config do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.config.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/linode/linode.config.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -39,6 +39,10 @@ describe Linode::Linode::Disk do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.disk.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/linode/linode.disk.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -39,6 +39,10 @@ describe Linode::Linode::Ip do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.ip.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/linode/linode.ip.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -39,6 +39,10 @@ describe Linode::Linode::Job do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.job.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/linode/linode.job.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
data/spec/linode/linode_spec.rb
CHANGED
@@ -39,6 +39,10 @@ describe Linode::Linode do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/linode/linode.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode::Nodebalancer::Config do
|
5
|
+
before :each do
|
6
|
+
@api_key = 'foo'
|
7
|
+
@linode = Linode::Nodebalancer::Config.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(create delete update list).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 nodebalancer.config.#{action} action" do
|
29
|
+
@linode.expects(:send_request).with {|api_action, data| api_action == "nodebalancer.config.#{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
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/nodebalancer/nodebalancer.config.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/nodebalancer/nodebalancer.config.#{action}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode::Nodebalancer::Node do
|
5
|
+
before :each do
|
6
|
+
@api_key = 'foo'
|
7
|
+
@linode = Linode::Nodebalancer::Node.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(create delete update list).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 nodebalancer.node.#{action} action" do
|
29
|
+
@linode.expects(:send_request).with {|api_action, data| api_action == "nodebalancer.node.#{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
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/nodebalancer/nodebalancer.node.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/nodebalancer/nodebalancer.node.#{action}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
require 'linode'
|
3
|
+
|
4
|
+
describe Linode::Nodebalancer do
|
5
|
+
before :each do
|
6
|
+
@api_key = 'foo'
|
7
|
+
@linode = Linode::Nodebalancer.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(update create list delete).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 nodebalancer.#{action} action" do
|
29
|
+
@linode.expects(:send_request).with {|api_action, data| api_action == "nodebalancer.#{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
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/nodebalancer/nodebalancer.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/nodebalancer/nodebalancer.#{action}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should be able to provide access to the Linode Nodebalancer Config API' do
|
50
|
+
@linode.should respond_to(:config)
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'when providing access to the Linode Nodebalancer Config API' do
|
54
|
+
before :each do
|
55
|
+
@api_key = 'foo'
|
56
|
+
@api_url = 'https://fake.linode.com/'
|
57
|
+
@linode = Linode::Nodebalancer.new(:api_key => @api_key, :api_url => @api_url)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should allow no arguments' do
|
61
|
+
lambda { @linode.config }.should_not raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should require no arguments' do
|
65
|
+
lambda { @linode.config(:foo) }.should raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should return a Linode::Nodebalancer::Config instance' do
|
69
|
+
@linode.config.class.should == Linode::Nodebalancer::Config
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should set the API key on the Linode::Nodebalancer::Config instance to be our API key' do
|
73
|
+
@linode.config.api_key.should == @api_key
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set the API url on the Linode::Nodebalancer::Config instance to be our API url' do
|
77
|
+
@linode.config.api_url.should == @api_url
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return the same Linode::Nodebalancer::Config instance when called again' do
|
81
|
+
linode = Linode::Nodebalancer.new(:api_key => @api_key)
|
82
|
+
result = linode.config
|
83
|
+
linode.config.should == result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should be able to provide access to the Linode Nodebalancer Node API' do
|
88
|
+
@linode.should respond_to(:node)
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'when providing access to the Linode Nodebalancer Node API' do
|
92
|
+
before :each do
|
93
|
+
@api_key = 'foo'
|
94
|
+
@api_url = 'https://fake.linode.com/'
|
95
|
+
@linode = Linode::Nodebalancer.new(:api_key => @api_key, :api_url => @api_url)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should allow no arguments' do
|
99
|
+
lambda { @linode.node }.should_not raise_error(ArgumentError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should require no arguments' do
|
103
|
+
lambda { @linode.node(:foo) }.should raise_error(ArgumentError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return a Linode::Nodebalancer::Node instance' do
|
107
|
+
@linode.node.class.should == Linode::Nodebalancer::Node
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should set the API key on the Linode::Nodebalancer::Node instance to be our API key' do
|
111
|
+
@linode.node.api_key.should == @api_key
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should set the API url on the Linode::Nodebalancer::Node instance to be our API url' do
|
115
|
+
@linode.node.api_url.should == @api_url
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should return the same Linode::Nodebalancer::Node instance when called again' do
|
119
|
+
linode = Linode::Nodebalancer.new(:api_key => @api_key)
|
120
|
+
result = linode.node
|
121
|
+
linode.node.should == result
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -39,6 +39,10 @@ describe Linode::Stackscript do
|
|
39
39
|
@linode.expects(:send_request).returns(:bar => :baz)
|
40
40
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should consider the documentation to live at http://www.linode.com/api/stackscript/stackscript.#{action}" do
|
44
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/stackscript/stackscript.#{action}"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
data/spec/linode/test_spec.rb
CHANGED
@@ -40,6 +40,10 @@ describe Linode::Test do
|
|
40
40
|
@linode.expects(:send_request).returns(:bar => :baz)
|
41
41
|
@linode.send(action.to_sym).should == { :bar => :baz }
|
42
42
|
end
|
43
|
+
|
44
|
+
it "should consider the documentation to live at http://www.linode.com/api/linode/linode.#{action}" do
|
45
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, action)).should == "http://www.linode.com/api/utility/test.#{action}"
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
data/spec/linode/user_spec.rb
CHANGED
@@ -28,5 +28,9 @@ describe Linode::User do
|
|
28
28
|
@linode.stubs(:api_key).returns('foo')
|
29
29
|
@linode.getapikey.should == 'foo'
|
30
30
|
end
|
31
|
+
|
32
|
+
it "should consider the documentation to live at http://www.linode.com/api/utility/user.getapikey" do
|
33
|
+
@linode.documentation_path(Linode.action_path(@linode.class.name, 'getapikey')).should == "http://www.linode.com/api/utility/user.getapikey"
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
data/spec/linode_spec.rb
CHANGED
@@ -70,8 +70,8 @@ describe 'Linode' do
|
|
70
70
|
|
71
71
|
it 'should use the user.getapikey remote call to look up the API key associated with the username/password combo specified at creation time' do
|
72
72
|
@json = '{"ERRORARRAY":[],"DATA":{"USERNAME":"ogc","API_KEY":"blahblahblah"},"ACTION":"user.getapikey"}'
|
73
|
-
HTTParty.expects(:
|
74
|
-
:
|
73
|
+
HTTParty.expects(:post).with(@api_url,
|
74
|
+
:body => {
|
75
75
|
:api_action => 'user.getapikey',
|
76
76
|
:api_responseFormat => 'json',
|
77
77
|
:username => @username,
|
@@ -136,7 +136,7 @@ describe 'Linode' do
|
|
136
136
|
"ACTION":"test.echo",
|
137
137
|
"DATA":{"FOO":"bar"}
|
138
138
|
}!
|
139
|
-
HTTParty.stubs(:
|
139
|
+
HTTParty.stubs(:post).returns(@json)
|
140
140
|
@linode.stubs(:api_url).returns('https://fake.linode.com/')
|
141
141
|
end
|
142
142
|
|
@@ -150,63 +150,63 @@ describe 'Linode' do
|
|
150
150
|
|
151
151
|
it 'should make a request to the API url' do
|
152
152
|
@linode.stubs(:api_url).returns('https://fake.linode.com/')
|
153
|
-
HTTParty.expects(:
|
153
|
+
HTTParty.expects(:post).with { |path, args|
|
154
154
|
path == 'https://fake.linode.com/'
|
155
155
|
}.returns(@json)
|
156
156
|
@linode.send_request('test.echo', { })
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'should provide the API key when making its request' do
|
160
|
-
HTTParty.expects(:
|
161
|
-
args[:
|
160
|
+
HTTParty.expects(:post).with { |path, args|
|
161
|
+
args[:body][:api_key] == @api_key
|
162
162
|
}.returns(@json)
|
163
163
|
@linode.send_request('test.echo', { })
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should set the designated request method as the HTTP API action' do
|
167
|
-
HTTParty.expects(:
|
168
|
-
args[:
|
167
|
+
HTTParty.expects(:post).with { |path, args|
|
168
|
+
args[:body][:api_action] == 'test.echo'
|
169
169
|
}.returns(@json)
|
170
170
|
@linode.send_request('test.echo', { })
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'should set the response format to JSON' do
|
174
|
-
HTTParty.expects(:
|
175
|
-
args[:
|
174
|
+
HTTParty.expects(:post).with { |path, args|
|
175
|
+
args[:body][:api_responseFormat] == 'json'
|
176
176
|
}.returns(@json)
|
177
177
|
@linode.send_request('test.echo', { })
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'should provide the data hash to the HTTP API request' do
|
181
|
-
HTTParty.expects(:
|
182
|
-
args[:
|
181
|
+
HTTParty.expects(:post).with { |path, args|
|
182
|
+
args[:body]['foo'] == 'bar'
|
183
183
|
}.returns(@json)
|
184
184
|
@linode.send_request('test.echo', { 'foo' => 'bar' })
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'should not allow overriding the API key via the data hash' do
|
188
|
-
HTTParty.expects(:
|
189
|
-
args[:
|
188
|
+
HTTParty.expects(:post).with { |path, args|
|
189
|
+
args[:body][:api_key] == @api_key
|
190
190
|
}.returns(@json)
|
191
191
|
@linode.send_request('test.echo', { :api_key => 'h4x0r' })
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should not allow overriding the API action via the data hash' do
|
195
|
-
HTTParty.expects(:
|
196
|
-
args[:
|
195
|
+
HTTParty.expects(:post).with { |path, args|
|
196
|
+
args[:body][:api_action] == 'test.echo'
|
197
197
|
}.returns(@json)
|
198
198
|
@linode.send_request('test.echo', { :api_action => 'h4x0r' })
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'should not allow overriding the API response format via the data hash' do
|
202
|
-
HTTParty.expects(:
|
203
|
-
args[:
|
202
|
+
HTTParty.expects(:post).with { |path, args|
|
203
|
+
args[:body][:api_responseFormat] == 'json'
|
204
204
|
}.returns(@json)
|
205
205
|
@linode.send_request('test.echo', { :api_responseFormat => 'h4x0r' })
|
206
206
|
end
|
207
207
|
|
208
208
|
it 'should fail when the request submission fails' do
|
209
|
-
HTTParty.stubs(:
|
209
|
+
HTTParty.stubs(:post).returns(%Q!{
|
210
210
|
"ERRORARRAY":["failure"],
|
211
211
|
"ACTION":"test.echo",
|
212
212
|
"DATA":{"foo":"bar"}
|
@@ -216,7 +216,7 @@ describe 'Linode' do
|
|
216
216
|
|
217
217
|
describe 'when the result is a list of hashes' do
|
218
218
|
it 'should return a list of objects with lower-cased methods for the data fields' do
|
219
|
-
HTTParty.stubs(:
|
219
|
+
HTTParty.stubs(:post).returns(%Q!{
|
220
220
|
"ERRORARRAY":[],
|
221
221
|
"ACTION":"test.echo",
|
222
222
|
"DATA":[{"FOO":"bar"},{"BAR":"baz"}]
|
@@ -226,7 +226,7 @@ describe 'Linode' do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should return a list of objects which do not respond to upper-case URLs for the data fields' do
|
229
|
-
HTTParty.stubs(:
|
229
|
+
HTTParty.stubs(:post).returns(%Q!{
|
230
230
|
"ERRORARRAY":[],
|
231
231
|
"ACTION":"test.echo",
|
232
232
|
"DATA":[{"FOO":"bar"},{"BAR":"baz"}]
|
@@ -248,7 +248,7 @@ describe 'Linode' do
|
|
248
248
|
|
249
249
|
describe 'when the result is neither a list nor a hash' do
|
250
250
|
it 'should return the result unchanged' do
|
251
|
-
HTTParty.stubs(:
|
251
|
+
HTTParty.stubs(:post).returns(%Q!{
|
252
252
|
"ERRORARRAY":[],
|
253
253
|
"ACTION":"test.echo",
|
254
254
|
"DATA":"thingie"
|
@@ -417,5 +417,37 @@ describe 'Linode' do
|
|
417
417
|
linode.linode.should == result
|
418
418
|
end
|
419
419
|
end
|
420
|
+
|
421
|
+
it 'should be able to provide access to the Linode Nodebalancer API' do
|
422
|
+
@linode.should respond_to(:nodebalancer)
|
423
|
+
end
|
424
|
+
|
425
|
+
describe 'when providing access to the Linode Nodebalancer API' do
|
426
|
+
it 'should allow no arguments' do
|
427
|
+
lambda { @linode.nodebalancer }.should_not raise_error(ArgumentError)
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'should require no arguments' do
|
431
|
+
lambda { @linode.nodebalancer(:foo) }.should raise_error(ArgumentError)
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'should return a Linode::Nodebalancer instance' do
|
435
|
+
@linode.nodebalancer.class.should == Linode::Nodebalancer
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'should set the API key on the Linode::Nodebalancer instance to be our API key' do
|
439
|
+
@linode.nodebalancer.api_key.should == @api_key
|
440
|
+
end
|
441
|
+
|
442
|
+
it 'should set the API url on the Linode::Nodebalancer instance to be our API url' do
|
443
|
+
@linode.nodebalancer.api_url.should == @api_url
|
444
|
+
end
|
445
|
+
|
446
|
+
it 'should return the same Linode::Nodebalancer instance when called again' do
|
447
|
+
linode = Linode.new(:api_key => @api_key)
|
448
|
+
result = linode.nodebalancer
|
449
|
+
linode.nodebalancer.should == result
|
450
|
+
end
|
451
|
+
end
|
420
452
|
end
|
421
453
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rick Bradley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-07-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,9 @@ files:
|
|
59
59
|
- lib/linode/linode/disk.rb
|
60
60
|
- lib/linode/linode/ip.rb
|
61
61
|
- lib/linode/linode/job.rb
|
62
|
+
- lib/linode/nodebalancer.rb
|
63
|
+
- lib/linode/nodebalancer/config.rb
|
64
|
+
- lib/linode/nodebalancer/node.rb
|
62
65
|
- lib/linode/stackscript.rb
|
63
66
|
- lib/linode/test.rb
|
64
67
|
- lib/linode/user.rb
|
@@ -71,6 +74,9 @@ files:
|
|
71
74
|
- spec/linode/linode/ip_spec.rb
|
72
75
|
- spec/linode/linode/job_spec.rb
|
73
76
|
- spec/linode/linode_spec.rb
|
77
|
+
- spec/linode/nodebalancer/config_spec.rb
|
78
|
+
- spec/linode/nodebalancer/node_spec.rb
|
79
|
+
- spec/linode/nodebalancer_spec.rb
|
74
80
|
- spec/linode/stackscript_spec.rb
|
75
81
|
- spec/linode/test_spec.rb
|
76
82
|
- spec/linode/user_spec.rb
|
@@ -119,6 +125,9 @@ test_files:
|
|
119
125
|
- spec/linode/linode/ip_spec.rb
|
120
126
|
- spec/linode/linode/job_spec.rb
|
121
127
|
- spec/linode/linode_spec.rb
|
128
|
+
- spec/linode/nodebalancer/config_spec.rb
|
129
|
+
- spec/linode/nodebalancer/node_spec.rb
|
130
|
+
- spec/linode/nodebalancer_spec.rb
|
122
131
|
- spec/linode/stackscript_spec.rb
|
123
132
|
- spec/linode/test_spec.rb
|
124
133
|
- spec/linode/user_spec.rb
|