right_api_client 1.5.9 → 1.5.12

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,42 +1,24 @@
1
- require 'simplecov'
2
- SimpleCov.start if ENV["COVERAGE"]
3
- require File.expand_path('../../lib/right_api_client', __FILE__)
4
- require 'spec'
1
+
5
2
  require 'pp'
6
3
  require 'yaml'
7
4
 
8
- Spec::Runner.configure do |config|
9
- config.mock_with :flexmock
10
- end
5
+ require File.expand_path('../../lib/right_api_client', __FILE__)
11
6
 
12
- module MockSpecHelper
13
- def mock_rest_client
14
- @api_version = RightApi::Client::API_VERSION
15
- @rest_client = RestClient::Resource.new(RightApi::Client::DEFAULT_API_URL)
16
- flexmock(RestClient::Resource).should_receive(:new).and_return(@rest_client)
17
- @session = flexmock(:cookies => '')
18
- @header = {'X_API_VERSION' => @api_version, :cookies => '', :accept => :json}
19
- end
20
7
 
21
- def given_user_facing_client
22
- mock_rest_client
23
- flexmock(@rest_client).should_receive(:post).with(
24
- {'email' => 'email', 'password' => 'password', 'account_href' => '/api/accounts/1'},
25
- {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
26
- flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{}'])
27
- @client = RightApi::Client.new(:email => 'email', :password => 'password', :account_id => '1')
28
- end
8
+ RSpec.configure do |config|
29
9
 
30
- def given_instance_facing_client
31
- mock_rest_client
32
- flexmock(@rest_client).should_receive(:post).with(
33
- {'instance_token' => 'instance_token', 'account_href' => '/api/accounts/1'},
34
- {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
35
- flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{"links": [
36
- {
37
- "href": "/api/clouds/1/instances/1",
38
- "rel": "self"
39
- }]}'])
40
- @client = RightApi::Client.new(:instance_token => 'instance_token', :account_id => '1')
10
+ #
11
+ # include helpers
12
+
13
+ $config = config
14
+
15
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |path|
16
+ require(path)
41
17
  end
18
+
19
+ #
20
+ # misc
21
+
22
+ config.mock_with :flexmock
42
23
  end
24
+
@@ -0,0 +1,36 @@
1
+
2
+ module MockSpecHelper
3
+
4
+ def mock_rest_client
5
+ @api_version = RightApi::Client::API_VERSION
6
+ @rest_client = RestClient::Resource.new(RightApi::Client::DEFAULT_API_URL)
7
+ flexmock(RestClient::Resource).should_receive(:new).and_return(@rest_client)
8
+ @session = flexmock(:cookies => {})
9
+ @header = {'X_API_VERSION' => @api_version, :cookies => {}, :accept => :json}
10
+ end
11
+
12
+ def given_user_facing_client
13
+ mock_rest_client
14
+ flexmock(@rest_client).should_receive(:post).with(
15
+ {'email' => 'email', 'password' => 'password', 'account_href' => '/api/accounts/1'},
16
+ {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
17
+ flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{}'])
18
+ @client = RightApi::Client.new(:email => 'email', :password => 'password', :account_id => '1')
19
+ end
20
+
21
+ def given_instance_facing_client
22
+ mock_rest_client
23
+ flexmock(@rest_client).should_receive(:post).with(
24
+ {'instance_token' => 'instance_token', 'account_href' => '/api/accounts/1'},
25
+ {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
26
+ flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{"links": [
27
+ {
28
+ "href": "/api/clouds/1/instances/1",
29
+ "rel": "self"
30
+ }]}'])
31
+ @client = RightApi::Client.new(:instance_token => 'instance_token', :account_id => '1')
32
+ end
33
+ end
34
+
35
+ $config.include MockSpecHelper
36
+
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ include RightApi::Helper
3
+
4
+ describe RightApi::Helper do
5
+
6
+ API_MEDIA_TYPES = %w{audit_entry ip_address process server}
7
+
8
+ context "#is_singular?" do
9
+ API_MEDIA_TYPES.each do |media_type|
10
+ it "should identify media type #{media_type} as singular" do
11
+ is_singular?(media_type).should == true
12
+ end
13
+ end
14
+ end
15
+
16
+ context "#fix_array_of_hashes" do
17
+ it "fixes all the keys that have the value as array of hashes" do
18
+ res = fix_array_of_hashes(
19
+ 'a' => '1',
20
+ 'b' => [1, 2, 3],
21
+ 'c' => {1 => 2, 3 => 4},
22
+ 'd' => [
23
+ {5 => 6, 7 => 8},
24
+ {9 => 10, 11 => 12}
25
+ ]
26
+ )
27
+
28
+ res.should == {
29
+ 'a' => '1',
30
+ 'b' => [1, 2, 3],
31
+ 'c' => {1 => 2, 3 => 4},
32
+ 'd[]' => [
33
+ {5 => 6, 7 => 8},
34
+ {9 => 10, 11 => 12}
35
+ ]
36
+ }
37
+
38
+ end
39
+
40
+ it "fixes key that have a top-level array of hashes as value" do
41
+ res = fix_array_of_hashes(
42
+ 'a' => [
43
+ {1 => 2},
44
+ {3 => 4}
45
+ ]
46
+ )
47
+
48
+ res.should == {
49
+ 'a[]' => [
50
+ {1 => 2},
51
+ {3 => 4}
52
+ ]
53
+ }
54
+ end
55
+
56
+ it "fixes key that have a nested array of hashes as value" do
57
+ res = fix_array_of_hashes(
58
+ 'a' => {
59
+ 'b' => [
60
+ {1 => 2},
61
+ {3 => 4}
62
+ ]
63
+ }
64
+ )
65
+
66
+ res.should == {
67
+ 'a' => {
68
+ 'b' => {
69
+ '' => [
70
+ {1 => 2},
71
+ {3 => 4}
72
+ ]
73
+ }
74
+ }
75
+ }
76
+ end
77
+ end
78
+ end
@@ -1,25 +1,24 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
- include MockSpecHelper
1
+ require File.expand_path('../../spec_helper', __FILE__)
3
2
 
4
3
  describe RightApi::Client do
5
- context "Given an instance-facing logged in RightScale user" do
4
+ context "given an instance-facing logged in RightScale user" do
6
5
  before(:each) do
7
6
  given_instance_facing_client
8
7
  end
9
8
 
10
- it "Should have the required methods for the client" do
9
+ it "has the required methods for the client" do
11
10
  @client.api_methods.sort.collect{|s| s.to_s}.should == ["backups", "get_instance", "live_tasks", "volume_attachments", "volume_snapshots", "volume_types", "volumes"]
12
11
  end
13
12
 
14
- it "Should return an instance of the Resource class when user provides an id" do
13
+ it "returns an instance of the Resource class when user provides an id" do
15
14
  @client.volumes(:id => 1).class.should == RightApi::Resource
16
15
  @client.backups(:id => 1).class.should == RightApi::Resource
17
16
  @client.live_tasks(:id => 1).class.should == RightApi::Resource
18
17
  end
19
18
 
20
- it "Should return an instance of the Resources class when user does not provide an id" do
19
+ it "returns an instance of the Resources class when user does not provide an id" do
21
20
  @client.volumes.class.should == RightApi::Resources
22
21
  @client.backups.class.should == RightApi::Resources
23
22
  end
24
23
  end
25
- end
24
+ end
@@ -1,31 +1,30 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
- include MockSpecHelper
1
+ require File.expand_path('../../spec_helper', __FILE__)
3
2
 
4
3
  describe RightApi::ResourceDetail do
5
- context "Given a logged in RightScale user" do
4
+ context "given a logged in RightScale user" do
6
5
  before(:each) do
7
6
  given_user_facing_client
8
7
  end
9
8
 
10
- it "Should have the required methods for instances of the ResourceDetail class" do
9
+ it "has the required methods for instances of the ResourceDetail class" do
11
10
  resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1', {})
12
11
  resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "links", "show", "update"]
13
12
  end
14
13
 
15
- it "Should have resource-specific methods for instances of the ResourceDetail class" do
14
+ it "has resource-specific methods for instances of the ResourceDetail class" do
16
15
  resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
17
16
  {:attribute1 => 'value1', :attribute2 => 'value2'})
18
17
  resource.api_methods.sort.collect{|s| s.to_s}.should == ["attribute1", "attribute2", "destroy", "links", "show", "update"]
19
18
  end
20
19
 
21
- it "Should have the links for instances of the ResourceDetail class" do
20
+ it "has the links for instances of the ResourceDetail class" do
22
21
  resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
23
22
  {'links' => [{'rel' => 'link1', 'href' => 'link1_href'},
24
23
  {'rel' => 'link2', 'href' => 'link2_href'}]})
25
24
  resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "link1", "link2", "links", "show", "update"]
26
25
  end
27
26
 
28
- it "Should have the actions for instances of the ResourceDetail class" do
27
+ it "has the actions for instances of the ResourceDetail class" do
29
28
  resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
30
29
  {'links' => [{'rel' => 'self', 'href' => 'self'}],
31
30
  'actions' => [{'rel' => 'action1'}, {'rel' => 'action2'}]})
@@ -35,14 +34,14 @@ describe RightApi::ResourceDetail do
35
34
  resource.action1.should == 'ok'
36
35
  end
37
36
 
38
- it "Should have live_tasks for the 'instance' resource" do
37
+ it "has live_tasks for the 'instance' resource" do
39
38
  resource = RightApi::ResourceDetail.new(@client, 'instance', '/api/instances/1', {})
40
39
  resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "links", "live_tasks", "show", "update"]
41
40
  flexmock(RightApi::Resource).should_receive(:process).with(@client, 'live_task', '/api/instances/1/live/tasks/1').and_return('ok')
42
41
  resource.live_tasks(:id => '1').should == 'ok'
43
42
  end
44
43
 
45
- it "Should add methods for child resources from detailed views" do
44
+ it "adds methods for child resources from detailed views" do
46
45
  resource = RightApi::ResourceDetail.new(@client, 'server', '/api/servers/1', {
47
46
  'links' => [
48
47
  {'href' => '/api/servers/1', 'rel' => 'self'},
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe RightApi::Resource do
4
+ context "given a logged in RightScale user" do
5
+ before(:each) do
6
+ given_user_facing_client
7
+ end
8
+
9
+ it "has the required methods for instances of the Resource class" do
10
+ resource = RightApi::Resource.process(@client, 'deployment', '/api/deployments/1')
11
+ resource.api_methods.sort.map(&:to_s).should == %w[ destroy show update ]
12
+ end
13
+
14
+ it "has destroy/show/update for all instances of the Resource class" do
15
+ resource = RightApi::Resource.process(@client, 'session', '/api/session')
16
+ resource.api_methods.sort.map(&:to_s).should == %w[ destroy show update ]
17
+ end
18
+
19
+ it "has an array of ResourceDetail instances for index calls" do
20
+ resources = RightApi::Resource.process(@client, 'deployment', '/api/deployments', [{}])
21
+ resources.first.class.should == RightApi::ResourceDetail
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe RightApi::Resources do
4
+ context "given a logged in RightScale user" do
5
+ before(:each) do
6
+ given_user_facing_client
7
+ end
8
+
9
+ it "has the required methods for instances of the Resources class" do
10
+ resource = RightApi::Resources.new(@client, '/api/deployments', 'deployments')
11
+ resource.api_methods.sort.collect(&:to_s).should == %w[
12
+ create index ]
13
+ end
14
+
15
+ it "has index even for instances of the Resources class that do not support it" do
16
+ resource = RightApi::Resources.new(@client, '/api/tags', 'tags')
17
+ resource.api_methods.sort.collect(&:to_s).should == %w[
18
+ by_resource by_tag create index multi_add multi_delete ]
19
+ end
20
+
21
+ it "has resource-specific methods for instances of the Resources class" do
22
+ resource = RightApi::Resources.new(@client, '/api/backups', 'backups')
23
+ resource.api_methods.sort.collect(&:to_s).should == %w[
24
+ cleanup create index ]
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_api_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 9
10
- version: 1.5.9
9
+ - 12
10
+ version: 1.5.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - RightScale, Inc.
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-09 00:00:00 -08:00
18
+ date: 2013-07-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: json
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
@@ -31,27 +31,26 @@ dependencies:
31
31
  - 0
32
32
  version: "0"
33
33
  type: :runtime
34
- version_requirements: *id001
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rest-client
37
37
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - "="
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- hash: 1
43
+ hash: 3
44
44
  segments:
45
45
  - 1
46
46
  - 6
47
- - 7
48
- version: 1.6.7
47
+ version: "1.6"
49
48
  type: :runtime
50
- version_requirements: *id002
49
+ requirement: *id002
51
50
  - !ruby/object:Gem::Dependency
52
51
  name: rake
53
52
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
54
  none: false
56
55
  requirements:
57
56
  - - "="
@@ -63,27 +62,27 @@ dependencies:
63
62
  - 7
64
63
  version: 0.8.7
65
64
  type: :development
66
- version_requirements: *id003
65
+ requirement: *id003
67
66
  - !ruby/object:Gem::Dependency
68
67
  name: rspec
69
68
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
70
  none: false
72
71
  requirements:
73
72
  - - "="
74
73
  - !ruby/object:Gem::Version
75
- hash: 27
74
+ hash: 43
76
75
  segments:
77
- - 1
78
- - 3
76
+ - 2
77
+ - 9
79
78
  - 0
80
- version: 1.3.0
79
+ version: 2.9.0
81
80
  type: :development
82
- version_requirements: *id004
81
+ requirement: *id004
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: flexmock
85
84
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
86
  none: false
88
87
  requirements:
89
88
  - - "="
@@ -95,11 +94,11 @@ dependencies:
95
94
  - 7
96
95
  version: 0.8.7
97
96
  type: :development
98
- version_requirements: *id005
97
+ requirement: *id005
99
98
  - !ruby/object:Gem::Dependency
100
99
  name: simplecov
101
100
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
102
  none: false
104
103
  requirements:
105
104
  - - "="
@@ -111,11 +110,11 @@ dependencies:
111
110
  - 2
112
111
  version: 0.4.2
113
112
  type: :development
114
- version_requirements: *id006
113
+ requirement: *id006
115
114
  - !ruby/object:Gem::Dependency
116
115
  name: bundler
117
116
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
119
118
  none: false
120
119
  requirements:
121
120
  - - ">="
@@ -125,11 +124,11 @@ dependencies:
125
124
  - 0
126
125
  version: "0"
127
126
  type: :development
128
- version_requirements: *id007
127
+ requirement: *id007
129
128
  description: "\n\
130
- The right_api_client gem simplifies the use of RightScale's MultiCloud API. It provides\n\
131
- a simple object model of the API resources, and handles all of the fine details involved\n\
132
- in making HTTP calls and translating their responses.\n "
129
+ The right_api_client gem simplifies the use of RightScale's MultiCloud API.\n\
130
+ It provides a simple object model of the API resources, and handles all of the\n\
131
+ fine details involved in making HTTP calls and translating their responses.\n "
133
132
  email:
134
133
  - rubygems@rightscale.com
135
134
  executables: []
@@ -140,15 +139,15 @@ extra_rdoc_files: []
140
139
 
141
140
  files:
142
141
  - .gitignore
143
- - CHANGELOG.rdoc
142
+ - CHANGELOG.md
144
143
  - Gemfile
145
144
  - LICENSE.txt
146
- - README.rdoc
145
+ - README.md
147
146
  - Rakefile
148
147
  - config/login.yml.example
149
148
  - lib/right_api_client.rb
150
149
  - lib/right_api_client/client.rb
151
- - lib/right_api_client/exceptions.rb
150
+ - lib/right_api_client/errors.rb
152
151
  - lib/right_api_client/helper.rb
153
152
  - lib/right_api_client/resource.rb
154
153
  - lib/right_api_client/resource_detail.rb
@@ -157,13 +156,15 @@ files:
157
156
  - login_to_client_irb.rb
158
157
  - right_api_client.gemspec
159
158
  - right_api_client.rconf
160
- - spec/audit_entries_spec.rb
161
- - spec/client_spec.rb
162
- - spec/instance_facing_spec.rb
163
- - spec/resource_detail_spec.rb
164
- - spec/resource_spec.rb
165
- - spec/resources_spec.rb
159
+ - spec/functional/audit_entries_spec.rb
160
+ - spec/functional/client_spec.rb
166
161
  - spec/spec_helper.rb
162
+ - spec/support/mock_spec_helper.rb
163
+ - spec/unit/helper_spec.rb
164
+ - spec/unit/instance_facing_spec.rb
165
+ - spec/unit/resource_detail_spec.rb
166
+ - spec/unit/resource_spec.rb
167
+ - spec/unit/resources_spec.rb
167
168
  has_rdoc: true
168
169
  homepage: https://github.com/rightscale/right_api_client
169
170
  licenses: []
@@ -194,16 +195,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  requirements: []
195
196
 
196
197
  rubyforge_project:
197
- rubygems_version: 1.3.7
198
+ rubygems_version: 1.6.2
198
199
  signing_key:
199
200
  specification_version: 3
200
201
  summary: RightScale MultiCloud API HTTP Client
201
202
  test_files:
202
203
  - config/login.yml.example
203
- - spec/audit_entries_spec.rb
204
- - spec/client_spec.rb
205
- - spec/instance_facing_spec.rb
206
- - spec/resource_detail_spec.rb
207
- - spec/resource_spec.rb
208
- - spec/resources_spec.rb
204
+ - spec/functional/audit_entries_spec.rb
205
+ - spec/functional/client_spec.rb
209
206
  - spec/spec_helper.rb
207
+ - spec/support/mock_spec_helper.rb
208
+ - spec/unit/helper_spec.rb
209
+ - spec/unit/instance_facing_spec.rb
210
+ - spec/unit/resource_detail_spec.rb
211
+ - spec/unit/resource_spec.rb
212
+ - spec/unit/resources_spec.rb