linode 0.6.2 → 0.6.3

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.
@@ -1,6 +1,4 @@
1
1
  --format
2
2
  s
3
3
  --colour
4
- --loadby
5
- mtime
6
4
  --backtrace
data/CHANGELOG CHANGED
@@ -1,2 +1,80 @@
1
1
 
2
- * 2009/08/04 - Initial commit.
2
+ 0.6.3 / 2010-11-23
3
+ ==================
4
+ * Can now initialize w/ username/pass; also support for user.getapikey API call
5
+
6
+ 2010-11-21 Rick Bradley <rick@rickbradley.com>
7
+ * Adding rspec2 support for autotest
8
+ * Continuing conversion of spec_helper for rspec2
9
+ * moving spec/spec.opts to /.rspec
10
+
11
+ 2010-11-21 Aaron Hamid <aaron.hamid@gmail.com>
12
+ * did the minimal amount necessary to get tests to run on latest RSpec release; https://github.com/rick/linode/issues#issue/3
13
+
14
+ 2010-08-03 Rick Bradley <rick@rickbradley.com>
15
+ * updating gemspec for 0.6.2
16
+ * Version bump to 0.6.2
17
+ * remove Jeweler warning as noone else needs to ever see it, basically
18
+ * make 'rake test' an alias for 'rake spec'
19
+
20
+ 2010-03-31 Rick Bradley <rick@rickbradley.com>
21
+ * updated gemspec
22
+ * Version bump to 0.6.1
23
+ * Missed a couple new Linode API stackscript bits.
24
+
25
+ 2010-03-27 Rick Bradley <rick@rickbradley.com>
26
+ * Merge branch 'newgem'
27
+ * updating gemspec
28
+ * Regenerated gemspec for version 0.6.0
29
+ * Version bump to 0.6.0
30
+ * adding support for stackscript API
31
+
32
+ 2009-12-21 Rick Bradley <rick@rickbradley.com>
33
+ * updating README (thx dvyjones!)
34
+
35
+ 2009-12-20 Rick Bradley <rick@rickbradley.com>
36
+ * updated gemspec
37
+ * Version bump to 0.5.4
38
+ * enabling GemCutter support for our gem
39
+
40
+ 2009-08-05 Rick Bradley <rick@rickbradley.com>
41
+ * new gemspec
42
+ * Version bump to 0.5.3
43
+ * make error messages much more helpful, including link to relevant API page.
44
+ * fixing mis-named spec example descriptions for nested namespaces
45
+ * updating gemspec
46
+ * Version bump to 0.5.2
47
+ * tiny tweak to use has_namespace instead of an old literal method declaration
48
+ * updating gemspec
49
+ * Version bump to 0.5.1
50
+ * making sure rake actually runs specs; adding httparty gem dependency
51
+ * Version bump to 0.5.0
52
+ * adding Jeweler recipe, gemspec, etc.
53
+ * README now has examples.
54
+ * Linode.Ip API
55
+ * Linode.Job API
56
+ * Linode.Disk API
57
+ * Linode.Config API
58
+ * the Linode
59
+ * more metaprogramming, now that we know how a namespace behaves
60
+ * Domain.Resource nested API
61
+ * cleaning up missed example description change
62
+ * metprogramming avail, user, test APIs
63
+ * adding domain spec; using domain spec to introduce has_method metaprogramming
64
+ * adding User API
65
+ * making the data -> object(s) conversion more robust
66
+ * Avail API specs and methods
67
+ * metaprogramming the Test API specs, for later use in other specs
68
+ * first working version of a simple request (test.echo)
69
+ * adding httparty dependency to README
70
+
71
+ 2009-08-04 Rick Bradley <rick@rickbradley.com>
72
+ * set real API URL, allow overriding
73
+ * Adding basic request method to base class.
74
+ * trivial testing dependencies in README
75
+ * add Avail API hook, reorganize how subclass specs are stored
76
+ * nest namespace classes, automate discovery
77
+ * making a way to access our simplest API (Linode.test)
78
+ * Linode.new.
79
+ * initial commit.
80
+
data/README CHANGED
@@ -138,3 +138,6 @@ Here is an annoyingly exhaustive IRB session where I play around with the API:
138
138
  irb> l.linode.ip.list(:LinodeId => 12446)
139
139
  => [#<OpenStruct rdns_name="byggvir.websages.com", ipaddressid=12286, linodeid=12446, ispublic=1, ipaddress="209.123.234.161">, #<OpenStruct rdns_name="li101-51.members.linode.com", ipaddressid=23981, linodeid=12446, ispublic=1, ipaddress="97.107.140.51">]
140
140
  irb> ^D@ Wed Aug 05 01:50:52 rick@Yer-Moms-Computer
141
+
142
+ CREDITS:
143
+ - Thanks to Aaron Hamid for updates for RSpec 2 and work on user.getapikey + username/password initialization.
data/Rakefile CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
- require 'spec/rake/spectask'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  desc 'Default: run specs.'
7
7
  task :default => :spec
8
8
 
9
9
  desc 'Test the linode library.'
10
- Spec::Rake::SpecTask.new('spec') do |t|
11
- t.spec_files = FileList['spec/**/*_spec.rb']
10
+ RSpec::Core::RakeTask.new('spec') do |t|
11
+ t.pattern = 'spec/**/*_spec.rb'
12
12
  end
13
13
 
14
14
  desc 'Test the linode library.'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/lib/linode.rb CHANGED
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
  require 'httparty'
4
4
 
5
5
  class Linode
6
- attr_reader :api_key
6
+ attr_reader :username, :password
7
7
 
8
8
  def self.has_method(*actions)
9
9
  actions.each do |action|
@@ -30,31 +30,53 @@ class Linode
30
30
  has_namespace :test, :avail, :user, :domain, :linode
31
31
 
32
32
  def initialize(args)
33
- raise ArgumentError, ":api_key is required" unless args[:api_key]
34
- @api_key = args[:api_key]
35
33
  @api_url = args[:api_url] if args[:api_url]
34
+
35
+ if args.include?(:api_key)
36
+ @api_key = args[:api_key]
37
+ elsif args.include?(:username) and args.include?(:password)
38
+ @username = args[:username]
39
+ @password = args[:password]
40
+ else
41
+ raise ArgumentError, "Either :api_key, or both :username and :password, are required."
42
+ end
36
43
  end
37
44
 
38
45
  def api_url
39
46
  @api_url || 'https://api.linode.com/'
40
47
  end
41
48
 
49
+ def api_key
50
+ @api_key ||= fetch_api_key
51
+ end
52
+
42
53
  def send_request(action, data)
43
54
  data.delete_if {|k,v| [:api_key, :api_action, :api_responseFormat].include?(k) }
44
- result = Crack::JSON.parse(HTTParty.get(api_url, :query => { :api_key => api_key, :api_action => action, :api_responseFormat => 'json' }.merge(data)))
45
- raise "Errors completing request [#{action}] @ [#{api_url}] with data [#{data.inspect}]:\n#{error_message(result, action)}" if error?(result)
46
- reformat_response(result)
55
+ response = get({ :api_key => api_key, :api_action => action, :api_responseFormat => 'json' }.merge(data))
56
+ raise "Errors completing request [#{action}] @ [#{api_url}] with data [#{data.inspect}]:\n#{error_message(response, action)}" if error?(response)
57
+ reformat_response(response)
47
58
  end
48
59
 
49
60
  protected
50
61
 
62
+ def fetch_api_key
63
+ response = get(:api_action => 'user.getapikey', :api_responseFormat => 'json', :username => username, :password => password)
64
+ raise "Errors completing request [user.getapikey] @ [#{api_url}] for username [#{username}]:\n#{error_message(response, 'user.getapikey')}" if error?(response)
65
+ reformat_response(response).api_key
66
+ end
67
+
68
+ def get(data)
69
+ Crack::JSON.parse(HTTParty.get(api_url, :query => data))
70
+ end
71
+
51
72
  def error?(response)
52
73
  response and response["ERRORARRAY"] and ! response["ERRORARRAY"].empty?
53
74
  end
54
75
 
55
76
  def error_message(response, action)
56
77
  response["ERRORARRAY"].collect { |err|
57
- " - Error \##{err["ERRORCODE"]} - #{err["ERRORMESSAGE"]}. (Please consult http://www.linode.com/api/autodoc.cfm?method=#{action})"
78
+ " - Error \##{err["ERRORCODE"]} - #{err["ERRORMESSAGE"]}. "+
79
+ "(Please consult http://www.linode.com/api/autodoc.cfm?method=#{action})"
58
80
  }.join("\n")
59
81
  end
60
82
 
data/lib/linode/user.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  class Linode::User < Linode
2
- has_method :getapikey
2
+ def getapikey
3
+ api_key
4
+ end
3
5
  end
data/linode.gemspec CHANGED
@@ -1,74 +1,73 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{linode}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
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{2010-08-03}
12
+ s.date = %q{2010-11-23}
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 = [
16
16
  "README"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "CHANGELOG",
21
- "MIT-LICENSE",
22
- "README",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/linode.rb",
26
- "lib/linode/avail.rb",
27
- "lib/linode/domain.rb",
28
- "lib/linode/domain/resource.rb",
29
- "lib/linode/linode.rb",
30
- "lib/linode/linode/config.rb",
31
- "lib/linode/linode/disk.rb",
32
- "lib/linode/linode/ip.rb",
33
- "lib/linode/linode/job.rb",
34
- "lib/linode/stackscript.rb",
35
- "lib/linode/test.rb",
36
- "lib/linode/user.rb",
37
- "linode.gemspec",
38
- "spec/linode/avail_spec.rb",
39
- "spec/linode/domain/resource_spec.rb",
40
- "spec/linode/domain_spec.rb",
41
- "spec/linode/linode/config_spec.rb",
42
- "spec/linode/linode/disk_spec.rb",
43
- "spec/linode/linode/ip_spec.rb",
44
- "spec/linode/linode/job_spec.rb",
45
- "spec/linode/linode_spec.rb",
46
- "spec/linode/stackscript_spec.rb",
47
- "spec/linode/test_spec.rb",
48
- "spec/linode/user_spec.rb",
49
- "spec/linode_spec.rb",
50
- "spec/spec.opts",
51
- "spec/spec_helper.rb"
19
+ ".rspec",
20
+ "CHANGELOG",
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "autotest/discover.rb",
26
+ "lib/linode.rb",
27
+ "lib/linode/avail.rb",
28
+ "lib/linode/domain.rb",
29
+ "lib/linode/domain/resource.rb",
30
+ "lib/linode/linode.rb",
31
+ "lib/linode/linode/config.rb",
32
+ "lib/linode/linode/disk.rb",
33
+ "lib/linode/linode/ip.rb",
34
+ "lib/linode/linode/job.rb",
35
+ "lib/linode/stackscript.rb",
36
+ "lib/linode/test.rb",
37
+ "lib/linode/user.rb",
38
+ "linode.gemspec",
39
+ "spec/linode/avail_spec.rb",
40
+ "spec/linode/domain/resource_spec.rb",
41
+ "spec/linode/domain_spec.rb",
42
+ "spec/linode/linode/config_spec.rb",
43
+ "spec/linode/linode/disk_spec.rb",
44
+ "spec/linode/linode/ip_spec.rb",
45
+ "spec/linode/linode/job_spec.rb",
46
+ "spec/linode/linode_spec.rb",
47
+ "spec/linode/stackscript_spec.rb",
48
+ "spec/linode/test_spec.rb",
49
+ "spec/linode/user_spec.rb",
50
+ "spec/linode_spec.rb",
51
+ "spec/spec_helper.rb"
52
52
  ]
53
53
  s.homepage = %q{http://github.com/rick/linode}
54
- s.rdoc_options = ["--charset=UTF-8"]
55
54
  s.require_paths = ["lib"]
56
55
  s.rubygems_version = %q{1.3.7}
57
56
  s.summary = %q{a Ruby wrapper for the Linode API}
58
57
  s.test_files = [
59
58
  "spec/linode/avail_spec.rb",
60
- "spec/linode/domain/resource_spec.rb",
61
- "spec/linode/domain_spec.rb",
62
- "spec/linode/linode/config_spec.rb",
63
- "spec/linode/linode/disk_spec.rb",
64
- "spec/linode/linode/ip_spec.rb",
65
- "spec/linode/linode/job_spec.rb",
66
- "spec/linode/linode_spec.rb",
67
- "spec/linode/stackscript_spec.rb",
68
- "spec/linode/test_spec.rb",
69
- "spec/linode/user_spec.rb",
70
- "spec/linode_spec.rb",
71
- "spec/spec_helper.rb"
59
+ "spec/linode/domain/resource_spec.rb",
60
+ "spec/linode/domain_spec.rb",
61
+ "spec/linode/linode/config_spec.rb",
62
+ "spec/linode/linode/disk_spec.rb",
63
+ "spec/linode/linode/ip_spec.rb",
64
+ "spec/linode/linode/job_spec.rb",
65
+ "spec/linode/linode_spec.rb",
66
+ "spec/linode/stackscript_spec.rb",
67
+ "spec/linode/test_spec.rb",
68
+ "spec/linode/user_spec.rb",
69
+ "spec/linode_spec.rb",
70
+ "spec/spec_helper.rb"
72
71
  ]
73
72
 
74
73
  if s.respond_to? :specification_version then
@@ -11,35 +11,22 @@ describe Linode::User do
11
11
  @linode.class.should < Linode
12
12
  end
13
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
14
+ it 'should be able to return the API key for the connection' do
15
+ @linode.should respond_to(:getapikey)
16
+ end
18
17
 
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
18
+ describe 'when returning the API key for the connection' do
19
+ it 'should work without arguments' do
20
+ lambda { @linode.getapikey }.should_not raise_error(ArgumentError)
21
+ end
32
22
 
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
23
+ it 'should not allow arguments' do
24
+ lambda { @linode.getapikey(:foo) }.should raise_error(ArgumentError)
25
+ end
37
26
 
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
27
+ it 'should return the api_key via the Linode handle' do
28
+ @linode.stubs(:api_key).returns('foo')
29
+ @linode.getapikey.should == 'foo'
42
30
  end
43
31
  end
44
-
45
32
  end
data/spec/linode_spec.rb CHANGED
@@ -15,8 +15,16 @@ describe Linode do
15
15
  it 'should require an arguments hash' do
16
16
  lambda { Linode.new }.should raise_error(ArgumentError)
17
17
  end
18
-
19
- it 'should fail if no API key is given' do
18
+
19
+ it 'should not fail if an API key is given' do
20
+ lambda { Linode.new({ :api_key => 'foo' }) }.should_not raise_error(ArgumentError)
21
+ end
22
+
23
+ it 'should not fail if a username/password combo is given' do
24
+ lambda { Linode.new({ :username => 'bar', :password => 'baz' }) }.should_not raise_error(ArgumentError)
25
+ end
26
+
27
+ it 'should fail if no API key nor username/password combo is given' do
20
28
  lambda { Linode.new({}) }.should raise_error(ArgumentError)
21
29
  end
22
30
 
@@ -31,26 +39,89 @@ describe 'Linode' do
31
39
  before :each do
32
40
  @api_key = 'foo'
33
41
  @api_url = 'https://fake.linode.com/'
42
+ @username = 'bar'
43
+ @password = 'baz'
34
44
  @linode = Linode.new(:api_key => @api_key, :api_url => @api_url)
35
45
  end
36
46
 
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)
47
+ describe 'when initialized with username and password' do
48
+ before :each do
49
+ @linode = Linode.new(:username => @username, :password => @password, :api_url => @api_url)
50
+ end
51
+
52
+ it 'should be able to return the username provided at creation time' do
53
+ @linode.username.should == 'bar'
54
+ end
55
+
56
+ it 'should be able to return the password provided at creation time' do
57
+ @linode.password.should == 'baz'
58
+ end
59
+
60
+ describe 'when returning the current API URL' do
61
+ it 'should return the API URL provided at creation time if one was provided' do
62
+ @linode.api_url.should == 'https://fake.linode.com/'
63
+ end
64
+
65
+ it 'should return the stock linode API URL if none was provided at creation time' do
66
+ @linode = Linode.new(:username => @username, :password => @api_url)
67
+ @linode.api_url.should == 'https://api.linode.com/'
68
+ end
69
+ end
70
+
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
+ @json = '{"ERRORARRAY":[],"DATA":{"USERNAME":"ogc","API_KEY":"blahblahblah"},"ACTION":"user.getapikey"}'
73
+ HTTParty.expects(:get).with(@api_url,
74
+ :query => {
75
+ :api_action => 'user.getapikey',
76
+ :api_responseFormat => 'json',
77
+ :username => @username,
78
+ :password => @password
79
+ }
80
+ ).returns(@json)
81
+ @linode.api_key
82
+ end
83
+
84
+ it 'should return the API key associated with the username/password combo specified at creation time' do
85
+ @linode.stubs(:fetch_api_key).returns(@api_key)
86
+ @linode.api_key.should == @api_key
87
+ end
88
+
89
+ it 'should fail when looking up the API key if API key remote lookup fails' do
90
+ @linode.stubs(:fetch_api_key).raises
91
+ lambda { @linode.api_key }.should raise_error
92
+ end
93
+
94
+ it 'should cache API key remote lookups for later use' do
95
+ @linode.stubs(:fetch_api_key).returns(@api_key)
96
+ @linode.api_key
97
+ @linode.stubs(:fetch_api_key).raises
98
+ @linode.api_key.should == @api_key
99
+ end
43
100
  end
44
101
 
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/'
102
+ describe 'when initialized with API key' do
103
+ it 'should return a nil username' do
104
+ @linode.username.should be_nil
105
+ end
106
+
107
+ it 'should return a nil password' do
108
+ @linode.password.should be_nil
49
109
  end
50
110
 
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/'
111
+ it 'should be able to return the API key provided at creation time' do
112
+ @linode.api_key.should == 'foo'
113
+ end
114
+
115
+ describe 'when returning the current API URL' do
116
+ it 'should return the API URL provided at creation time if one was provided' do
117
+ @linode = Linode.new(:api_key => @api_key, :api_url => 'https://fake.linode.com/')
118
+ @linode.api_url.should == 'https://fake.linode.com/'
119
+ end
120
+
121
+ it 'should return the stock linode API URL if none was provided at creation time' do
122
+ @linode = Linode.new(:api_key => @api_key)
123
+ @linode.api_url.should == 'https://api.linode.com/'
124
+ end
54
125
  end
55
126
  end
56
127
 
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # this is my favorite way to require ever
2
2
  begin
3
- require 'spec'
3
+ require 'rspec'
4
4
  rescue LoadError
5
5
  require 'rubygems'
6
6
  gem 'rspec'
7
- require 'spec'
7
+ require 'rspec'
8
8
  end
9
9
 
10
10
  begin
@@ -15,7 +15,7 @@ rescue LoadError
15
15
  require 'mocha'
16
16
  end
17
17
 
18
- Spec::Runner.configure do |config|
18
+ Rspec.configure do |config|
19
19
  config.mock_with :mocha
20
20
  end
21
21
 
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
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: 2010-08-03 00:00:00 -05:00
18
+ date: 2010-11-23 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -43,12 +43,13 @@ extensions: []
43
43
  extra_rdoc_files:
44
44
  - README
45
45
  files:
46
- - .gitignore
46
+ - .rspec
47
47
  - CHANGELOG
48
48
  - MIT-LICENSE
49
49
  - README
50
50
  - Rakefile
51
51
  - VERSION
52
+ - autotest/discover.rb
52
53
  - lib/linode.rb
53
54
  - lib/linode/avail.rb
54
55
  - lib/linode/domain.rb
@@ -74,15 +75,14 @@ files:
74
75
  - spec/linode/test_spec.rb
75
76
  - spec/linode/user_spec.rb
76
77
  - spec/linode_spec.rb
77
- - spec/spec.opts
78
78
  - spec/spec_helper.rb
79
79
  has_rdoc: true
80
80
  homepage: http://github.com/rick/linode
81
81
  licenses: []
82
82
 
83
83
  post_install_message:
84
- rdoc_options:
85
- - --charset=UTF-8
84
+ rdoc_options: []
85
+
86
86
  require_paths:
87
87
  - lib
88
88
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- coverage/
2
- pkg/