right_api_client 1.5.19 → 1.5.21

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/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ script:
8
+ - RACK_ENV=test bundle exec rspec spec
9
+ bundler_args: --without test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG.md
2
2
 
3
+ ## 1.5.21
4
+ - \#71 Stop locking rest-client to 1.6.x and return to locking it to 1.x
5
+
6
+ ## 1.5.20
7
+ - \#67 Fix bug preventing configuration from setting nil for :timeout.
8
+ - \#67 Lock rest-client to 1.6.x due to requirement for Ruby 1.8.7 support.
9
+ - \#66 Add [TravisCI support](https://travis-ci.org/rightscale/right_api_client).
10
+ - \#64 Jewelerize the project to make maintenance easier.
11
+
3
12
  ## 1.5.19
4
13
  - \#38 Specify `:allow_nan => true` in calls to `JSON.parse` so we don't choke on NAN values.
5
14
  - \#60 Make exception [namespace change](https://github.com/rightscale/right_api_client/commit/84f477907eef0a583ee5bec0ee5336309d933c75) fully backwards compatible.
data/Gemfile CHANGED
@@ -1,8 +1,24 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ # Runtime dependencies that should appear in the gemspec.
4
+ gem 'json', '~> 1.0'
5
+ gem 'mime-types', '~> 1.0'
6
+ gem 'rest-client', '~> 1.6'
4
7
 
5
- gem 'ruby-debug',
6
- :platforms => [:ruby_18]
7
- gem 'debugger',
8
- :platforms => [:ruby_19, :ruby_20, :ruby_21]
8
+ # Development dependencies that should appear in the gemspec.
9
+ group :development do
10
+ gem 'rake', '0.8.7'
11
+ gem 'rspec', '2.9.0'
12
+ gem 'flexmock', '0.8.7'
13
+ gem 'simplecov', '0.4.2',
14
+ :platforms => [:ruby_19, :ruby_20, :ruby_21]
15
+ end
16
+
17
+ # Gems used during test and development that should be OMITTED from the gemspec
18
+ group :test do
19
+ gem 'ruby-debug',
20
+ :platforms => [:ruby_18]
21
+ gem 'debugger',
22
+ :platforms => [:ruby_19, :ruby_20, :ruby_21]
23
+ gem 'jeweler', '~> 2.0'
24
+ end
data/Gemfile.lock CHANGED
@@ -1,14 +1,8 @@
1
- PATH
2
- remote: .
3
- specs:
4
- right_api_client (1.5.19)
5
- json (~> 1.0)
6
- mime-types (~> 1.0)
7
- rest-client (~> 1.6)
8
-
9
1
  GEM
10
2
  remote: https://rubygems.org/
11
3
  specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
12
6
  columnize (0.3.6)
13
7
  debugger (1.6.6)
14
8
  columnize (>= 0.3.1)
@@ -17,15 +11,52 @@ GEM
17
11
  debugger-linecache (1.2.0)
18
12
  debugger-ruby_core_source (1.3.2)
19
13
  diff-lcs (1.1.3)
14
+ faraday (0.8.9)
15
+ multipart-post (~> 1.2.0)
20
16
  flexmock (0.8.7)
17
+ git (1.2.6)
18
+ github_api (0.10.1)
19
+ addressable
20
+ faraday (~> 0.8.1)
21
+ hashie (>= 1.2)
22
+ multi_json (~> 1.4)
23
+ nokogiri (~> 1.5.2)
24
+ oauth2
25
+ hashie (3.0.0)
26
+ highline (1.6.21)
27
+ jeweler (2.0.1)
28
+ builder
29
+ bundler (>= 1.0)
30
+ git (>= 1.2.5)
31
+ github_api
32
+ highline (>= 1.6.15)
33
+ nokogiri (>= 1.5.10)
34
+ rake
35
+ rdoc
21
36
  json (1.8.1)
37
+ jwt (0.1.11)
38
+ multi_json (>= 1.5)
22
39
  linecache (0.46)
23
40
  rbx-require-relative (> 0.0.4)
24
41
  mime-types (1.25.1)
42
+ multi_json (1.10.1)
43
+ multi_xml (0.5.5)
44
+ multipart-post (1.2.0)
45
+ nokogiri (1.5.11)
46
+ oauth2 (0.9.3)
47
+ faraday (>= 0.8, < 0.10)
48
+ jwt (~> 0.1.8)
49
+ multi_json (~> 1.3)
50
+ multi_xml (~> 0.5)
51
+ rack (~> 1.2)
52
+ rack (1.5.2)
25
53
  rake (0.8.7)
26
54
  rbx-require-relative (0.0.9)
27
- rest-client (1.6.7)
28
- mime-types (>= 1.16)
55
+ rdoc (4.1.1)
56
+ json (~> 1.4)
57
+ rest-client (1.6.8)
58
+ mime-types (~> 1.16)
59
+ rdoc (>= 2.4.2)
29
60
  rspec (2.9.0)
30
61
  rspec-core (~> 2.9.0)
31
62
  rspec-expectations (~> 2.9.0)
@@ -47,11 +78,13 @@ PLATFORMS
47
78
  ruby
48
79
 
49
80
  DEPENDENCIES
50
- bundler (~> 1.0)
51
81
  debugger
52
82
  flexmock (= 0.8.7)
83
+ jeweler (~> 2.0)
84
+ json (~> 1.0)
85
+ mime-types (~> 1.0)
53
86
  rake (= 0.8.7)
54
- right_api_client!
87
+ rest-client (~> 1.6)
55
88
  rspec (= 2.9.0)
56
89
  ruby-debug
57
90
  simplecov (= 0.4.2)
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # RightScale API Client
2
+ [![Build Status](https://travis-ci.org/rightscale/right_api_client.svg?branch=master)](https://travis-ci.org/rightscale/right_api_client)
2
3
 
3
4
  The right\_api\_client gem simplifies the use of RightScale's MultiCloud API. It provides
4
5
  a simple object model of the API resources, and handles all of the fine details involved
data/Rakefile CHANGED
@@ -1,17 +1,38 @@
1
- require File.expand_path('../lib/right_api_client', __FILE__)
2
- require 'rubygems'
3
- require 'rake'
1
+ require 'jeweler'
4
2
  require 'rspec/core/rake_task'
5
3
 
6
- task :build do
7
- system "gem build right_api_client.gemspec"
4
+ RSpec::Core::RakeTask.new('spec') do |t|
5
+ t.pattern= 'spec/**/*_spec.rb'
8
6
  end
9
7
 
10
- task :release => :build do
11
- system "gem push right_api_client-#{RightApi::Client::VERSION}.gem"
12
- end
8
+ tasks = Jeweler::Tasks.new do |gem|
9
+ # gem is a Gem::Specification; see http://docs.rubygems.org/read/chapter/20 for more options
10
+ gem.name = 'right_api_client'
11
+ gem.homepage = 'https://github.com/rightscale/right_api_client'
12
+ gem.license = 'MIT'
13
+ gem.summary = 'RightScale MultiCloud API HTTP Client'
14
+ gem.description = %{
15
+ The right_api_client gem simplifies the use of RightScale's MultiCloud API.
16
+ It provides a simple object model of the API resources, and handles all of the
17
+ fine details involved in making HTTP calls and translating their responses.
18
+ }
19
+ gem.email = 'rubygems@rightscale.com'
20
+ gem.authors = ['RightScale, Inc.']
13
21
 
14
- RSpec::Core::RakeTask.new('spec') do |t|
15
- t.pattern= 'spec/**/*_spec.rb'
16
- t.rspec_opts = ['--format nested','--colour']
22
+ # This gem is special; its own VERSION file needs to be shipped with the gem in order to
23
+ # initialize the VERSION constant living under RightApi::Client.
24
+ gem.files.include 'VERSION'
25
+
26
+ # Keep the gem nice and svelte
27
+ gem.files.exclude 'config'
28
+ gem.files.exclude 'cookies'
29
+ gem.files.exclude 'spec'
17
30
  end
31
+
32
+ # Never auto-commit during operations that change the repository. Allows developers to decide on their own commit comment
33
+ # and/or aggregate version bumps into other fixes.
34
+ tasks.jeweler.commit = false
35
+
36
+ Jeweler::RubygemsDotOrgTasks.new
37
+
38
+ CLEAN.include('pkg')
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.5.21
@@ -45,7 +45,7 @@ module RightApi
45
45
 
46
46
  # Initializing all instance variables from hash
47
47
  args.each { |key,value|
48
- instance_variable_set("@#{key}", value) if value && AUTH_PARAMS.include?(key.to_s)
48
+ instance_variable_set("@#{key}", value) if AUTH_PARAMS.include?(key.to_s)
49
49
  } if args.is_a? Hash
50
50
 
51
51
  raise 'This API client is only compatible with the RightScale API 1.5 and upwards.' if (Float(@api_version) < 1.5)
@@ -1,8 +1,8 @@
1
1
  # This gem is versioned with the usual X.Y.Z notation, where X.Y is the API version, and Z is the client version.
2
2
  module RightApi
3
3
  class Client
4
- API_VERSION = '1.5'
5
- CLIENT_VERSION = '19'
6
- VERSION = "#{API_VERSION}.#{CLIENT_VERSION}"
4
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
5
+ API_VERSION = VERSION.split('.')[0..1].join('.')
6
+ CLIENT_VERSION = VERSION.split('.')[1..-1].join('.')
7
7
  end
8
8
  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: 37
4
+ hash: 41
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 19
10
- version: 1.5.19
9
+ - 21
10
+ version: 1.5.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - RightScale, Inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-06-05 00:00:00 Z
18
+ date: 2014-08-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -126,43 +126,29 @@ dependencies:
126
126
  version: 0.4.2
127
127
  prerelease: false
128
128
  requirement: *id007
129
- - !ruby/object:Gem::Dependency
130
- type: :development
131
- name: bundler
132
- version_requirements: &id008 !ruby/object:Gem::Requirement
133
- none: false
134
- requirements:
135
- - - ~>
136
- - !ruby/object:Gem::Version
137
- hash: 15
138
- segments:
139
- - 1
140
- - 0
141
- version: "1.0"
142
- prerelease: false
143
- requirement: *id008
144
- description: "\n\
145
- The right_api_client gem simplifies the use of RightScale's MultiCloud API.\n\
146
- It provides a simple object model of the API resources, and handles all of the\n\
147
- fine details involved in making HTTP calls and translating their responses.\n "
148
- email:
149
- - rubygems@rightscale.com
129
+ description: |
130
+
131
+ The right_api_client gem simplifies the use of RightScale's MultiCloud API.
132
+ It provides a simple object model of the API resources, and handles all of the
133
+ fine details involved in making HTTP calls and translating their responses.
134
+
135
+ email: rubygems@rightscale.com
150
136
  executables: []
151
137
 
152
138
  extensions: []
153
139
 
154
- extra_rdoc_files: []
155
-
140
+ extra_rdoc_files:
141
+ - LICENSE.txt
142
+ - README.md
156
143
  files:
157
- - .gitignore
158
- - .rspec
144
+ - .travis.yml
159
145
  - CHANGELOG.md
160
146
  - Gemfile
161
147
  - Gemfile.lock
162
148
  - LICENSE.txt
163
149
  - README.md
164
150
  - Rakefile
165
- - config/login.yml.example
151
+ - VERSION
166
152
  - lib/right_api_client.rb
167
153
  - lib/right_api_client/client.rb
168
154
  - lib/right_api_client/errors.rb
@@ -173,17 +159,7 @@ files:
173
159
  - lib/right_api_client/resources.rb
174
160
  - lib/right_api_client/version.rb
175
161
  - login_to_client_irb.rb
176
- - right_api_client.gemspec
177
162
  - right_api_client.rconf
178
- - spec/functional/audit_entries_spec.rb
179
- - spec/functional/client_spec.rb
180
- - spec/spec_helper.rb
181
- - spec/support/mock_spec_helper.rb
182
- - spec/unit/helper_spec.rb
183
- - spec/unit/instance_facing_spec.rb
184
- - spec/unit/resource_detail_spec.rb
185
- - spec/unit/resource_spec.rb
186
- - spec/unit/resources_spec.rb
187
163
  homepage: https://github.com/rightscale/right_api_client
188
164
  licenses:
189
165
  - MIT
@@ -217,14 +193,5 @@ rubygems_version: 1.8.15
217
193
  signing_key:
218
194
  specification_version: 3
219
195
  summary: RightScale MultiCloud API HTTP Client
220
- test_files:
221
- - config/login.yml.example
222
- - spec/functional/audit_entries_spec.rb
223
- - spec/functional/client_spec.rb
224
- - spec/spec_helper.rb
225
- - spec/support/mock_spec_helper.rb
226
- - spec/unit/helper_spec.rb
227
- - spec/unit/instance_facing_spec.rb
228
- - spec/unit/resource_detail_spec.rb
229
- - spec/unit/resource_spec.rb
230
- - spec/unit/resources_spec.rb
196
+ test_files: []
197
+
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- .DS_Store
2
- nbproject
3
- *login.yml
4
- .loadpath
5
- .project
6
- .rvmrc
7
- .bundle
8
- .idea
9
- .idea/*
10
- .ruby-version
11
- coverage/*
12
- doc/*
13
- *~
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --format=nested
3
- --backtrace
4
- --debugger
@@ -1,35 +0,0 @@
1
- # The API login details can be put in a YAML file. This is an example login.yml which
2
- # will be needed for login_to_client_irb.rb quick login method.
3
-
4
- # Account ID is a required parameter. You can find your account number by logging into the
5
- # RightScale dashboard (https://my.rightscale.com), navigate to the Settings > Account Settings page.
6
- # The account number is at the end of the browser address bar.
7
- :account_id: my_account_id
8
-
9
- # There are five login mechanisms:
10
-
11
- # 0. Use the following parameters to login with your email and base64-encoded password:
12
- # To encode your plaintext password, use 'base64' command or similar.
13
- :email: my@email.com
14
- :password_base64: my_password_encoded_as_base64
15
-
16
- # 1. Use the following parameters to login with your email and plaintext password:
17
- :email: my@email.com
18
- :password: my_password
19
-
20
- # 2. Use the following parameter to login with an instance_token:
21
- # To find the instance_token, launch a server, navigate to the info page and under
22
- # User Data box, you will see RS_API_TOKEN = your_account_id:the_instance_token
23
- :instance_token: my_instance_token
24
-
25
- # 3. Use the following parameter to send a pre-authenticated cookie with every request:
26
- :cookies: my_cookie_string
27
-
28
- # 4. Use the following parameter to send an existing OAuth access token with every request:
29
- # To learn more about OAuth and how to obtain an access token, see
30
- # http://support.rightscale.com/12-Guides/03-Rightscale_API/OAuth
31
- :access_token: my_token_string
32
-
33
- # The following are optional parameters:
34
- :api_url: (this defaults to https://my.rightscale.com)
35
- :api_version: (this defaults to 1.5)
@@ -1,32 +0,0 @@
1
- require File.expand_path('../lib/right_api_client/version', __FILE__)
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'right_api_client'
5
- s.version = RightApi::Client::VERSION
6
- s.platform = Gem::Platform::RUBY
7
- s.date = Time.now.utc.strftime("%Y-%m-%d")
8
- s.require_path = 'lib'
9
- s.authors = [ 'RightScale, Inc.' ]
10
- s.email = [ 'rubygems@rightscale.com' ]
11
- s.homepage = 'https://github.com/rightscale/right_api_client'
12
- s.summary = 'RightScale MultiCloud API HTTP Client'
13
- s.license = 'MIT'
14
- s.description = %{
15
- The right_api_client gem simplifies the use of RightScale's MultiCloud API.
16
- It provides a simple object model of the API resources, and handles all of the
17
- fine details involved in making HTTP calls and translating their responses.
18
- }
19
- s.files = `git ls-files`.split(' ')
20
- s.test_files = `git ls-files spec config`.split(' ')
21
- s.rubygems_version = '1.3.7'
22
-
23
- s.add_runtime_dependency 'json', '~> 1.0'
24
- s.add_runtime_dependency 'mime-types', '~> 1.0'
25
- s.add_runtime_dependency 'rest-client', '~> 1.6'
26
-
27
- s.add_development_dependency 'rake', '0.8.7'
28
- s.add_development_dependency 'rspec', '2.9.0'
29
- s.add_development_dependency 'flexmock', '0.8.7'
30
- s.add_development_dependency 'simplecov', '0.4.2'
31
- s.add_development_dependency 'bundler', '~> 1.0'
32
- end
@@ -1,64 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe RightApi::Client do
4
-
5
- before(:all) do
6
-
7
- creds = File.expand_path('../../../config/login.yml', __FILE__)
8
-
9
- begin
10
- @client = RightApi::Client.new(YAML.load_file(creds))
11
- rescue Exception => e
12
- puts "=" * 80
13
- puts "WARNING: please provide a valid config/login.yml file"
14
- puts
15
- puts e.message
16
- puts "=" * 80
17
- end
18
-
19
- server_arrays =
20
- @client.server_arrays.index
21
-
22
- @server_array =
23
- server_arrays.find { |sa| sa.name.match(/test/i) } ||
24
- server_arrays.first
25
-
26
- raise "sorry, can't test, no server arrays in your RS" unless @server_array
27
- end
28
-
29
- describe '#audit_entries' do
30
-
31
- describe '#create' do
32
-
33
- it 'creates audit entries' do
34
-
35
- ae = @client.audit_entries.create(:audit_entry => {
36
- 'auditee_href' => @server_array.href,
37
- 'summary' => "right_api_client test #{$$}-#{Time.now.to_f}",
38
- 'detail' => 'sacrificing goats to make it work'
39
- })
40
-
41
- ae.class.should == RightApi::Resource
42
- ae.show.href.should match(/^\/api\/audit_entries\/[a-z0-9]+$/)
43
- end
44
- end
45
- end
46
-
47
- describe 'AuditEntry resource' do
48
-
49
- describe '#detail' do
50
-
51
- it 'returns the detail plain text' do
52
-
53
- ae = @client.audit_entries.create(:audit_entry => {
54
- 'auditee_href' => @server_array.href,
55
- 'summary' => "right_api_client test #{$$}-#{Time.now.to_f}",
56
- 'detail' => "and it's 1984"
57
- })
58
-
59
- ae.show.detail.show.text.should == "and it's 1984"
60
- end
61
- end
62
- end
63
- end
64
-
@@ -1,175 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe RightApi::Client do
4
-
5
- context "given a valid set of credentials in the config/login.yml file" do
6
-
7
- before(:all) do
8
- @creds = '../../../config/login.yml'
9
- begin
10
- @client = RightApi::Client.new(YAML.load_file(File.expand_path(@creds, __FILE__)))
11
- rescue => e
12
- puts "WARNING: The following specs need a valid set of credentials as they are integration tests that can only be done by calling the API server"
13
- puts e.message
14
- puts e.backtrace
15
- end
16
-
17
- # Don't bother to run tests if the client didn't initialize
18
- @client.should_not be_nil
19
- end
20
-
21
- it "logs in" do
22
- @client.send(:headers)[:cookies].should_not be_nil
23
- @client.session.index.message.should == 'You have successfully logged into the RightScale API.'
24
- end
25
-
26
- it "returns valid cookies" do
27
- @client.cookies.class.should == Hash
28
- @client.cookies['_session_id'].should_not be_nil
29
- @client.cookies['domain'].should match /rightscale.com$/
30
- @client.cookies.keys.sort.last.should match /^rs_gbl/ # HACK: not quite sane sanity check
31
- end
32
-
33
- it "accepts a cookie argument when creating a new client" do
34
- my_hash = YAML.load_file(File.expand_path(@creds, __FILE__))
35
- my_hash.delete(:email)
36
- my_hash.delete(:password)
37
- my_hash.delete(:cookies)
38
- my_hash[:cookies] = @client.cookies
39
- client1 = RightApi::Client.new(my_hash)
40
- client1.cookies.should == @client.cookies
41
- end
42
-
43
- it "accepts an access_token argument when creating a new client" do
44
- my_hash = YAML.load_file(File.expand_path(@creds, __FILE__))
45
- my_hash.delete(:email)
46
- my_hash.delete(:password)
47
- my_hash.delete(:cookies)
48
-
49
- access_token = @client.cookies.detect { |k, _| k =~ /^rs_gbl/ }.last
50
- access_token.should_not be_nil
51
- my_hash[:access_token] = access_token
52
-
53
- client1 = RightApi::Client.new(my_hash)
54
- client1.access_token.should == access_token
55
- end
56
-
57
- it "timestamps cookies" do
58
-
59
- @client.cookies.timestamp.should_not == nil
60
- end
61
-
62
- it "keeps track of the cookies all the time" do
63
-
64
- t0 = @client.cookies.timestamp
65
-
66
- @client.deployments.index
67
- t1 = @client.cookies.timestamp
68
-
69
- t0.to_f.should < t1.to_f
70
- end
71
-
72
- it "accepts a YAML argument when creating a new client" do
73
- client2 = RightApi::Client.new(YAML.load_file(File.expand_path(@creds, __FILE__)))
74
- client2.cookies.should_not == @client.cookies
75
- end
76
-
77
- it "sends post/get/put/delete requests to the server correctly" do
78
- deployment_name = "right_api_client functional test #{Time.now.to_s}"
79
- # create a new deployment
80
- new_deployment = @client.deployments.create(:deployment => {:name => deployment_name})
81
- new_deployment.class.should == RightApi::Resource
82
- new_deployment.show.name.should == deployment_name
83
-
84
- # verify new deployment
85
- deployment = @client.deployments(:id => new_deployment.show.href.split('/').last)
86
- deployment.class.should == RightApi::Resource
87
- deployment.show.class.should == RightApi::ResourceDetail
88
- deployment.show.href.should == new_deployment.show.href
89
-
90
- # update deployment
91
- deployment.update(:deployment => {:name => "#{deployment_name} updated"}).should be_nil
92
- deployment.show.name.should == "#{deployment_name} updated"
93
-
94
- # delete deployment
95
- deployment.destroy.should be_nil
96
- end
97
-
98
- # Tags are a bit special as they use POST and return content type so they need specific tests
99
- it "adds tag to deployment" do
100
- deployment_name = "right_api_client functional test #{Time.now.to_s}"
101
-
102
- # create a new deployment
103
- new_deployment = @client.deployments.create(:deployment => {:name => deployment_name})
104
-
105
- # add a tag to deployment
106
- @client.tags.multi_add("resource_hrefs[]=#{new_deployment.show.href}&tags[]=tag1").should == nil
107
-
108
- # verify tag
109
- tags = @client.tags.by_resource("resource_hrefs[]=#{new_deployment.show.href}")
110
- tags.class.should == Array
111
- tags.first.class.should == RightApi::ResourceDetail
112
- tags.first.tags.first.should == {"name" => "tag1"}
113
- tags.first.resource.show.name.should == deployment_name
114
-
115
- # delete deployment
116
- new_deployment.destroy.should be_nil
117
- end
118
-
119
- it "singularizes resource_types correctly" do
120
- @client.get_singular('servers').should == 'server'
121
- @client.get_singular('deployments').should == 'deployment'
122
- @client.get_singular('audit_entries').should == 'audit_entry'
123
- @client.get_singular('processes').should == 'process'
124
- @client.get_singular('ip_addresses').should == 'ip_address'
125
- end
126
-
127
- it "returns the resource when calling #resource(href)" do
128
-
129
- d0 = @client.deployments.index.first
130
-
131
- d1 = @client.resource(d0.href)
132
-
133
- d1.href.should == d0.href
134
- end
135
-
136
- it "raises meaningful errors" do
137
-
138
- err = begin
139
- @client.resource('/api/nada')
140
- rescue => e
141
- e
142
- end
143
-
144
- err.class.should ==
145
- RightApi::UnknownRouteError
146
- err.message.should ==
147
- "Unknown action or route. HTTP Code: 404, Response body: " +
148
- "NotFound: No route matches \"/api/nada\" with {:method=>:get}"
149
- end
150
-
151
- it "wraps errors with _details" do
152
-
153
- err = begin
154
- @client.deployments(:id => 'nada').show
155
- rescue => e
156
- e
157
- end
158
-
159
- #p err
160
- #puts err.backtrace
161
-
162
- err._details.method.should == :get
163
- err._details.path.should == '/api/deployments/nada'
164
- err._details.params.should == {}
165
-
166
- err._details.request.class.should == RestClient::Request
167
-
168
- err._details.response.code.should == 422
169
- err._details.response.class.should == String
170
- err._details.response.should == "ResourceNotFound: Couldn't find Deployment with ID=nada "
171
-
172
- err._details.code.should == 422
173
- end
174
- end
175
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
-
2
- require 'pp'
3
- require 'yaml'
4
-
5
- require File.expand_path('../../lib/right_api_client', __FILE__)
6
-
7
-
8
- RSpec.configure do |config|
9
-
10
- #
11
- # include helpers
12
-
13
- $config = config
14
-
15
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |path|
16
- require(path)
17
- end
18
-
19
- #
20
- # misc
21
-
22
- config.mock_with :flexmock
23
- end
24
-
@@ -1,36 +0,0 @@
1
- module MockSpecHelper
2
-
3
- def mock_rest_client
4
- @api_version = RightApi::Client::API_VERSION
5
- @test_account_id = '1'
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, 'X-Account' => @test_account_id, :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 => @test_account_id)
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 => @test_account_id)
32
- end
33
- end
34
-
35
- $config.include MockSpecHelper
36
-
@@ -1,78 +0,0 @@
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,24 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe RightApi::Client do
4
- context "given an instance-facing logged in RightScale user" do
5
- before(:each) do
6
- given_instance_facing_client
7
- end
8
-
9
- it "has the required methods for the client" do
10
- @client.api_methods.sort.collect{|s| s.to_s}.should == ["backups", "get_instance", "live_tasks", "volume_attachments", "volume_snapshots", "volume_types", "volumes"]
11
- end
12
-
13
- it "returns an instance of the Resource class when user provides an id" do
14
- @client.volumes(:id => 1).class.should == RightApi::Resource
15
- @client.backups(:id => 1).class.should == RightApi::Resource
16
- @client.live_tasks(:id => 1).class.should == RightApi::Resource
17
- end
18
-
19
- it "returns an instance of the Resources class when user does not provide an id" do
20
- @client.volumes.class.should == RightApi::Resources
21
- @client.backups.class.should == RightApi::Resources
22
- end
23
- end
24
- end
@@ -1,53 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe RightApi::ResourceDetail 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 ResourceDetail class" do
10
- resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1', {})
11
- resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "links", "show", "update"]
12
- end
13
-
14
- it "has resource-specific methods for instances of the ResourceDetail class" do
15
- resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
16
- {:attribute1 => 'value1', :attribute2 => 'value2'})
17
- resource.api_methods.sort.collect{|s| s.to_s}.should == ["attribute1", "attribute2", "destroy", "links", "show", "update"]
18
- end
19
-
20
- it "has the links for instances of the ResourceDetail class" do
21
- resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
22
- {'links' => [{'rel' => 'link1', 'href' => 'link1_href'},
23
- {'rel' => 'link2', 'href' => 'link2_href'}]})
24
- resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "link1", "link2", "links", "show", "update"]
25
- end
26
-
27
- it "has the actions for instances of the ResourceDetail class" do
28
- resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
29
- {'links' => [{'rel' => 'self', 'href' => 'self'}],
30
- 'actions' => [{'rel' => 'action1'}, {'rel' => 'action2'}]})
31
- resource.api_methods.sort.collect{|s| s.to_s}.should == ["action1", "action2", "destroy", "href", "links", "show", "update"]
32
-
33
- flexmock(@rest_client).should_receive(:post).with({}, @header, Proc).and_return('ok')
34
- resource.action1.should == 'ok'
35
- end
36
-
37
- it "has live_tasks for the 'instance' resource" do
38
- resource = RightApi::ResourceDetail.new(@client, 'instance', '/api/instances/1', {})
39
- resource.api_methods.sort.collect{|s| s.to_s}.should == ["destroy", "links", "live_tasks", "show", "update"]
40
- flexmock(RightApi::Resource).should_receive(:process).with(@client, 'live_task', '/api/instances/1/live/tasks/1').and_return('ok')
41
- resource.live_tasks(:id => '1').should == 'ok'
42
- end
43
-
44
- it "adds methods for child resources from detailed views" do
45
- resource = RightApi::ResourceDetail.new(@client, 'server', '/api/servers/1', {
46
- 'links' => [
47
- {'href' => '/api/servers/1', 'rel' => 'self'},
48
- {'href' => '/api/clouds/1/instances/1', 'rel' => 'current_instance'}],
49
- 'current_instance' => {'links' => [{'href' => '/api/clouds/1/instances/1', 'rel' => 'self'}]}})
50
- resource.api_methods.collect{|s| s.to_s}.sort.should == ["current_instance", "destroy", "href", "links", "show", "update"]
51
- end
52
- end
53
- end
@@ -1,24 +0,0 @@
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
@@ -1,27 +0,0 @@
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