right_api_client 1.5.12 → 1.5.13

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,6 +7,7 @@ nbproject
7
7
  .bundle
8
8
  .idea
9
9
  .idea/*
10
+ .ruby-version
10
11
  coverage/*
11
12
  doc/*
12
13
  *~
@@ -1,43 +1,52 @@
1
- = right_api_client - CHANGELOG.md
2
-
3
- == right_api_client - 1.5.11
4
- #33 fix specs and readme
5
- #32 fix nested array of hashes params
6
- #30 README markdown formatting
7
- #29 rename read me and add mandatory ownership string
8
-
9
- == right_api_client - 1.5.10
10
- #28 Preserve the last request made and make it accessible
11
- #26 Fix specs. Separate out unit tests and functional tests.
12
- #25 Add support for other RightScale endpoints.
13
- #23 Fix child_account update href.
14
- #20 Always store the latest cookies. Also includes a jump from rspec 1.3.0 to 2.9.0 and spec infrastructure reorganization.
15
-
16
- == right_api_client - 1.5.9
17
- Downgrade even further to Ruby 1.8.7. Should still work in Ruby 1.9.x.
18
-
19
- == right_api_client - 1.5.8
20
- Fix invalid gemspec by downgrading to Ruby 1.9.2 when building gem.
21
-
22
- == right_api_client - 1.5.7
23
- Enforce Ruby 1.9 interpreter.
24
- Remove the default 60 second timeout on requests.
25
-
26
- == right_api_client - 1.5.6
27
- Remove unused constant. Fix license and read me.
28
- Refs #11682 - allow all methods on resource classes and post them to rightapi.
29
-
30
- == right_api_client - 1.5.5
31
- Fix crash on audit_entry.detail.show (text and not JSON).
32
-
33
- == right_api_client - 1.5.4
34
- Fix singular for audit_entries resources. Update rest-client gem version to 1.6.7.
35
-
36
- == right_api_client - 1.5.3
37
- Add support for audit_entries resources. Update RConf ruby version to ruby-1.9.2-p290.
38
-
39
- == right_api_client - 1.5.2
40
- Fix issues with client when using Ruby 1.8.7 (note that right_api_client has not been fully tested with 1.8.7 yet).
41
-
42
- == right_api_client - 1.5.1
43
- Initial public release, supports all of the calls in RightScale API 1.5.
1
+ # CHANGELOG.md
2
+ ## 1.5.13
3
+ - \#44 Charcoal 13 18 account id in header acu103549
4
+ - \#42 Salmon 13 17 acu135785 add current url
5
+ - \#41 Add '/index.html' to the api ref url due to 404
6
+ - \#39 acu119168 fix markup
7
+ - \#37 acu111022 fix readme ownership string
8
+
9
+ ## 1.5.12
10
+ - \#35 acu104862 remove activesupport dependency and replace inflector
11
+
12
+ ## 1.5.11
13
+ - \#33 fix specs and readme
14
+ - \#32 fix nested array of hashes params
15
+ - \#30 README markdown formatting
16
+ - \#29 rename read me and add mandatory ownership string
17
+
18
+ ## 1.5.10
19
+ - \#28 Preserve the last request made and make it accessible
20
+ - \#26 Fix specs. Separate out unit tests and functional tests.
21
+ - \#25 Add support for other RightScale endpoints.
22
+ - \#23 Fix child_account update href.
23
+ - \#20 Always store the latest cookies. Also includes a jump from rspec 1.3.0 to 2.9.0 and spec infrastructure reorganization.
24
+
25
+ ## 1.5.9
26
+ - Downgrade even further to Ruby 1.8.7. Should still work in Ruby 1.9.x.
27
+
28
+ ## 1.5.8
29
+ - Fix invalid gemspec by downgrading to Ruby 1.9.2 when building gem.
30
+
31
+ ## 1.5.7
32
+ - Enforce Ruby 1.9 interpreter.
33
+ - Remove the default 60 second timeout on requests.
34
+
35
+ ## 1.5.6
36
+ - Remove unused constant. Fix license and read me.
37
+ - Refs #11682 - allow all methods on resource classes and post them to rightapi.
38
+
39
+ ## 1.5.5
40
+ - Fix crash on audit_entry.detail.show (text and not JSON).
41
+
42
+ ## 1.5.4
43
+ - Fix singular for audit_entries resources. Update rest-client gem version to 1.6.7.
44
+
45
+ ## 1.5.3
46
+ - Add support for audit_entries resources. Update RConf ruby version to ruby-1.9.2-p290.
47
+
48
+ ## 1.5.2
49
+ - Fix issues with client when using Ruby 1.8.7 (note that right_api_client has not been fully tested with 1.8.7 yet).
50
+
51
+ ## 1.5.1
52
+ - Initial public release, supports all of the calls in RightScale API 1.5.
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ right_api_client (1.5.13)
5
+ json
6
+ rest-client (~> 1.6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.1.3)
12
+ flexmock (0.8.7)
13
+ json (1.8.1)
14
+ mime-types (1.24)
15
+ rake (0.8.7)
16
+ rest-client (1.6.7)
17
+ mime-types (>= 1.16)
18
+ rspec (2.9.0)
19
+ rspec-core (~> 2.9.0)
20
+ rspec-expectations (~> 2.9.0)
21
+ rspec-mocks (~> 2.9.0)
22
+ rspec-core (2.9.0)
23
+ rspec-expectations (2.9.1)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.9.0)
26
+ simplecov (0.4.2)
27
+ simplecov-html (~> 0.4.4)
28
+ simplecov-html (0.4.5)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler
35
+ flexmock (= 0.8.7)
36
+ rake (= 0.8.7)
37
+ right_api_client!
38
+ rspec (= 2.9.0)
39
+ simplecov (= 0.4.2)
data/README.md CHANGED
@@ -6,9 +6,9 @@ in making HTTP calls and translating their responses.
6
6
  It is assumed that users are already familiar with the RightScale API:
7
7
 
8
8
  - API Documentation: http://support.rightscale.com/12-Guides/RightScale_API_1.5
9
- - API Reference Docs: http://reference.rightscale.com/api1.5
9
+ - API Reference Docs: http://reference.rightscale.com/api1.5/index.html
10
10
 
11
- Maintained by the RightScale "Yellow_team"
11
+ Maintained by the RightScale Salmon team
12
12
 
13
13
  ## Installation
14
14
  Ruby 1.8.7 or higher is required.
@@ -41,15 +41,41 @@ and treat every resource in the paths as objects that can call other objects usi
41
41
 
42
42
  Examples:
43
43
 
44
- - Index: /api/clouds/:cloud_id/datacenters => @client.clouds(:id => :cloud_id).show.datacenters.index
45
- - Show: /api/clouds/:cloud_id/datacenters/:id => @client.clouds(:id => :cloud_id).show.datacenters(:id => :datacenter_id).show
46
- - Create: /api/deployments/:deployment_id/servers => @client.deployments(:id => :deployment_id).show.servers.create
47
- - Update: /api/deployments/:deployment_id/servers/:id => @client.deployments(:id => :deployment_id).show.servers(:id => :server_id).update
48
- - Destroy: /api/deployments/:deployment_id/servers/:id => @client.deployments(:id => :deployment_id).show.servers(:id => :server_id).destroy
49
- - An action: /api/servers/:server_id/launch => @client.servers(:id => :server_id).show.launch
44
+ # Index datacenters: GET /api/clouds/:cloud_id/datacenters
45
+ @client.clouds(:id => 1).show.datacenters.index
46
+
47
+ # Show server: GET /api/clouds/:cloud_id/datacenters/:id
48
+ @client.clouds(:id => 1).show.datacenters(:id => 2).show
49
+
50
+ # Create server: POST /api/deployments/:deployment_id/servers
51
+ @client.deployments(:id => 3).show.servers.create
52
+
53
+ # Update server: PUT /api/deployments/:deployment_id/servers/:id
54
+ @client.deployments(:id => 3).show.servers(:id => 4).update
55
+
56
+ # Destroy server: DELETE /api/deployments/:deployment_id/servers/:id
57
+ @client.deployments(:id => 3).show.servers(:id => 4).destroy
58
+
59
+ # A non-CRUD action: POST /api/servers/:server_id/launch
60
+ @client.servers(:id => 4).show.launch
50
61
 
51
62
  As seen above, whenever you need to chain methods, you must call .show before specifying the next method.
52
63
 
64
+ ### Last HTTP Request
65
+
66
+ You can inspect all the information about the last HTTP request, including its response.
67
+ For more info: https://github.com/rest-client/rest-client
68
+
69
+ Examples:
70
+
71
+ deployments = @client.deployments.index
72
+ last_request = @client.last_request[:request]
73
+ last_url = last_request.url
74
+ last_method = last_request.method
75
+ last_response = @client.last_request[:response]
76
+ last_code = last_response.code
77
+ last_headers = last_request.headers
78
+
53
79
  ### Parameters
54
80
  Pass-in parameters to the method that they belong to. Lets say you want to filter on the index for deployments:
55
81
 
@@ -58,15 +84,39 @@ Pass-in parameters to the method that they belong to. Lets say you want to filte
58
84
  The filter is the parameter for the index call and not the deployment call.
59
85
 
60
86
  ### Logging HTTP Requests
61
- The HTTP calls made by right\_api\_client can be logged in two ways:
62
- 1. Log to a file
87
+ The HTTP calls made by right\_api\_client can be logged in two ways.
88
+
89
+ Log to a file:
63
90
 
64
91
  @client.log('~/right_api_client.log')
65
92
 
66
- 2. Log to STDOUT
93
+ Log to STDOUT:
67
94
 
68
95
  @client.log(STDOUT)
69
96
 
97
+ ### Managing multiple accounts
98
+ Multiple accounts can be managed by using the api\_url and account\_id attributes on the client.
99
+
100
+ The api\_url attribute allows users to modify the shard which the client is being used to connect to.
101
+ This should not be required as the client will find the correct shard using the account id but is
102
+ included for completeness.
103
+
104
+ Example:
105
+
106
+ @client.api_url # https://my.rightscale.com
107
+ @client.api_url = 'https://us-3.rightscale.com' # Update the client to make requests to shard 3
108
+
109
+ The account\_id switches which account is being managed by the client. This allows a user with
110
+ multiple accounts to perform actions whilst only having to authenticate once. This defaults to the
111
+ account which was used to create the client.
112
+
113
+ Example:
114
+
115
+ @client.account_id = 1
116
+ @client.users.index.count # The number of users in account with id 1
117
+ @client.account_id = 2
118
+ @client.users.index.count # The number of users in account with id 2
119
+
70
120
  ## Examples
71
121
  Get a list of all servers (aka doing an Index call)
72
122
 
@@ -27,6 +27,7 @@ module RightApi
27
27
  ]
28
28
 
29
29
  attr_reader :cookies, :instance_token, :last_request
30
+ attr_accessor :account_id, :api_url
30
31
 
31
32
  def initialize(args)
32
33
 
@@ -141,7 +142,7 @@ module RightApi
141
142
 
142
143
  # Returns the request headers
143
144
  def headers
144
- {'X_API_VERSION' => @api_version, :cookies => @cookies, :accept => :json}
145
+ {'X_API_VERSION' => @api_version, 'X_ACCOUNT' => @account_id, :cookies => @cookies, :accept => :json}
145
146
  end
146
147
 
147
148
  def update_last_request(request, response)
@@ -244,6 +245,9 @@ module RightApi
244
245
  else
245
246
  response.return!(request, result)
246
247
  end
248
+ when 301, 302
249
+ update_api_url(response)
250
+ do_post(path, params)
247
251
  when 404
248
252
  raise UnknownRouteError.new(request, response)
249
253
  else
@@ -280,6 +284,9 @@ module RightApi
280
284
  when 200
281
285
  when 204
282
286
  nil
287
+ when 301, 302
288
+ update_api_url(response)
289
+ do_delete(path, params)
283
290
  when 404
284
291
  raise UnknownRouteError.new(request, response)
285
292
  else
@@ -313,6 +320,9 @@ module RightApi
313
320
  case response.code
314
321
  when 204
315
322
  nil
323
+ when 301, 302
324
+ update_api_url(response)
325
+ do_put(path, params)
316
326
  when 404
317
327
  raise UnknownRouteError.new(request, response)
318
328
  else
@@ -2,7 +2,7 @@
2
2
  module RightApi
3
3
  class Client
4
4
  API_VERSION = '1.5'
5
- CLIENT_VERSION = '12'
5
+ CLIENT_VERSION = '13'
6
6
  VERSION = "#{API_VERSION}.#{CLIENT_VERSION}"
7
7
  end
8
8
  end
@@ -1,10 +1,9 @@
1
1
  ruby do
2
2
  version 'ree-1.8.7-2012.02'
3
- rubygems '1.8.17'
4
3
  gemset 'right_api_client'
5
4
  end
6
5
  bundler do
7
- version '1.0.21'
6
+ version '1.3.5'
8
7
  exclusions 'deployment'
9
8
  bundle_path File.join(ENV["HOME"], '.rightscale_bundle', 'right_api_client')
10
9
  end
@@ -58,29 +58,45 @@ describe RightApi::Client do
58
58
  end
59
59
 
60
60
  it "sends post/get/put/delete requests to the server correctly" do
61
- new_deployment = @client.deployments.create(:deployment => {:name => 'test'})
62
- new_deployment2 = @client.deployments.create(:deployment => {:name => 'test2'})
61
+ deployment_name = "right_api_client functional test #{Time.now.to_s}"
62
+ # create a new deployment
63
+ new_deployment = @client.deployments.create(:deployment => {:name => deployment_name})
63
64
  new_deployment.class.should == RightApi::Resource
64
- new_deployment.show.name.should == 'test'
65
+ new_deployment.show.name.should == deployment_name
65
66
 
67
+ # verify new deployment
66
68
  deployment = @client.deployments(:id => new_deployment.show.href.split('/').last)
67
69
  deployment.class.should == RightApi::Resource
68
70
  deployment.show.class.should == RightApi::ResourceDetail
69
71
  deployment.show.href.should == new_deployment.show.href
70
72
 
71
- deployment.update(:deployment => {:name => 'test2'}).should be_nil
72
- deployment.show.name.should == 'test2'
73
+ # update deployment
74
+ deployment.update(:deployment => {:name => "#{deployment_name} updated"}).should be_nil
75
+ deployment.show.name.should == "#{deployment_name} updated"
73
76
 
74
- # Tags are a bit special as they use POST and return content type so they need specific tests
75
- @client.tags.multi_add("resource_hrefs[]=#{deployment.show.href}&resource_hrefs[]=#{new_deployment2.show.href}&tags[]=tag1").should == nil
76
- tags = @client.tags.by_resource("resource_hrefs[]=#{deployment.show.href}&resource_hrefs[]=#{new_deployment2.show.href}")
77
+ # delete deployment
78
+ deployment.destroy.should be_nil
79
+ end
80
+
81
+ # Tags are a bit special as they use POST and return content type so they need specific tests
82
+ it "adds tag to deployment" do
83
+ deployment_name = "right_api_client functional test #{Time.now.to_s}"
84
+
85
+ # create a new deployment
86
+ new_deployment = @client.deployments.create(:deployment => {:name => deployment_name})
87
+
88
+ # add a tag to deployment
89
+ @client.tags.multi_add("resource_hrefs[]=#{new_deployment.show.href}&tags[]=tag1").should == nil
90
+
91
+ # verify tag
92
+ tags = @client.tags.by_resource("resource_hrefs[]=#{new_deployment.show.href}")
77
93
  tags.class.should == Array
78
94
  tags.first.class.should == RightApi::ResourceDetail
79
95
  tags.first.tags.first.should == {"name" => "tag1"}
80
- tags.first.resource.first.show.name.should == 'test2'
96
+ tags.first.resource.show.name.should == deployment_name
81
97
 
82
- deployment.destroy.should be_nil
83
- new_deployment2.destroy.should be_nil
98
+ # delete deployment
99
+ new_deployment.destroy.should be_nil
84
100
  end
85
101
 
86
102
  it "singularizes resource_types correctly" do
@@ -1,12 +1,12 @@
1
-
2
1
  module MockSpecHelper
3
2
 
4
3
  def mock_rest_client
5
4
  @api_version = RightApi::Client::API_VERSION
5
+ @test_account_id = '1'
6
6
  @rest_client = RestClient::Resource.new(RightApi::Client::DEFAULT_API_URL)
7
7
  flexmock(RestClient::Resource).should_receive(:new).and_return(@rest_client)
8
8
  @session = flexmock(:cookies => {})
9
- @header = {'X_API_VERSION' => @api_version, :cookies => {}, :accept => :json}
9
+ @header = {'X_API_VERSION' => @api_version, 'X_ACCOUNT' => @test_account_id, :cookies => {}, :accept => :json}
10
10
  end
11
11
 
12
12
  def given_user_facing_client
@@ -15,7 +15,7 @@ module MockSpecHelper
15
15
  {'email' => 'email', 'password' => 'password', 'account_href' => '/api/accounts/1'},
16
16
  {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
17
17
  flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{}'])
18
- @client = RightApi::Client.new(:email => 'email', :password => 'password', :account_id => '1')
18
+ @client = RightApi::Client.new(:email => 'email', :password => 'password', :account_id => @test_account_id)
19
19
  end
20
20
 
21
21
  def given_instance_facing_client
@@ -28,7 +28,7 @@ module MockSpecHelper
28
28
  "href": "/api/clouds/1/instances/1",
29
29
  "rel": "self"
30
30
  }]}'])
31
- @client = RightApi::Client.new(:instance_token => 'instance_token', :account_id => '1')
31
+ @client = RightApi::Client.new(:instance_token => 'instance_token', :account_id => @test_account_id)
32
32
  end
33
33
  end
34
34
 
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 12
10
- version: 1.5.12
9
+ - 13
10
+ version: 1.5.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - RightScale, Inc.
@@ -15,12 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-07-09 00:00:00 -04:00
19
- default_executable:
18
+ date: 2013-12-03 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: json
23
- prerelease: false
24
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
@@ -30,11 +28,11 @@ dependencies:
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
31
+ prerelease: false
33
32
  type: :runtime
34
33
  requirement: *id001
35
34
  - !ruby/object:Gem::Dependency
36
35
  name: rest-client
37
- prerelease: false
38
36
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
37
  none: false
40
38
  requirements:
@@ -45,11 +43,11 @@ dependencies:
45
43
  - 1
46
44
  - 6
47
45
  version: "1.6"
46
+ prerelease: false
48
47
  type: :runtime
49
48
  requirement: *id002
50
49
  - !ruby/object:Gem::Dependency
51
50
  name: rake
52
- prerelease: false
53
51
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
52
  none: false
55
53
  requirements:
@@ -61,11 +59,11 @@ dependencies:
61
59
  - 8
62
60
  - 7
63
61
  version: 0.8.7
62
+ prerelease: false
64
63
  type: :development
65
64
  requirement: *id003
66
65
  - !ruby/object:Gem::Dependency
67
66
  name: rspec
68
- prerelease: false
69
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
68
  none: false
71
69
  requirements:
@@ -77,11 +75,11 @@ dependencies:
77
75
  - 9
78
76
  - 0
79
77
  version: 2.9.0
78
+ prerelease: false
80
79
  type: :development
81
80
  requirement: *id004
82
81
  - !ruby/object:Gem::Dependency
83
82
  name: flexmock
84
- prerelease: false
85
83
  version_requirements: &id005 !ruby/object:Gem::Requirement
86
84
  none: false
87
85
  requirements:
@@ -93,11 +91,11 @@ dependencies:
93
91
  - 8
94
92
  - 7
95
93
  version: 0.8.7
94
+ prerelease: false
96
95
  type: :development
97
96
  requirement: *id005
98
97
  - !ruby/object:Gem::Dependency
99
98
  name: simplecov
100
- prerelease: false
101
99
  version_requirements: &id006 !ruby/object:Gem::Requirement
102
100
  none: false
103
101
  requirements:
@@ -109,11 +107,11 @@ dependencies:
109
107
  - 4
110
108
  - 2
111
109
  version: 0.4.2
110
+ prerelease: false
112
111
  type: :development
113
112
  requirement: *id006
114
113
  - !ruby/object:Gem::Dependency
115
114
  name: bundler
116
- prerelease: false
117
115
  version_requirements: &id007 !ruby/object:Gem::Requirement
118
116
  none: false
119
117
  requirements:
@@ -123,6 +121,7 @@ dependencies:
123
121
  segments:
124
122
  - 0
125
123
  version: "0"
124
+ prerelease: false
126
125
  type: :development
127
126
  requirement: *id007
128
127
  description: "\n\
@@ -141,6 +140,7 @@ files:
141
140
  - .gitignore
142
141
  - CHANGELOG.md
143
142
  - Gemfile
143
+ - Gemfile.lock
144
144
  - LICENSE.txt
145
145
  - README.md
146
146
  - Rakefile
@@ -165,7 +165,6 @@ files:
165
165
  - spec/unit/resource_detail_spec.rb
166
166
  - spec/unit/resource_spec.rb
167
167
  - spec/unit/resources_spec.rb
168
- has_rdoc: true
169
168
  homepage: https://github.com/rightscale/right_api_client
170
169
  licenses: []
171
170
 
@@ -195,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
194
  requirements: []
196
195
 
197
196
  rubyforge_project:
198
- rubygems_version: 1.6.2
197
+ rubygems_version: 1.8.28
199
198
  signing_key:
200
199
  specification_version: 3
201
200
  summary: RightScale MultiCloud API HTTP Client