right_api_client 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
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 = [ 'Ali Khajeh-Hosseini' ]
10
+ s.email = [ 'alikhajeh1@gmail.com' ]
11
+ s.homepage = 'https://github.com/rightscale/right_api_client'
12
+ s.summary = 'RightScale MultiCloud API HTTP Client'
13
+ s.description = %{
14
+ The right_api_client gem simplifies the use of RightScale's MultiCloud API. It provides
15
+ a simple object model of the API resources, and handles all of the fine details involved
16
+ in making HTTP calls and translating their responses.
17
+ }
18
+ s.files = `git ls-files`.split(' ')
19
+ s.test_files = `git ls-files spec config`.split(' ')
20
+ s.rubygems_version = '1.6.2'
21
+
22
+ s.add_runtime_dependency 'json'
23
+ s.add_runtime_dependency 'rest-client', '1.6.3'
24
+
25
+ s.add_development_dependency 'rake', '0.8.7'
26
+ s.add_development_dependency 'rspec', '1.3.0'
27
+ s.add_development_dependency 'flexmock', '0.8.7'
28
+ s.add_development_dependency 'ruby-debug19', '0.11.6'
29
+ s.add_development_dependency 'simplecov', '0.4.2'
30
+ s.add_development_dependency 'bundler'
31
+ end
@@ -0,0 +1,10 @@
1
+ ruby do
2
+ version 'ruby-1.9.2-p180'
3
+ rubygems '1.6.2'
4
+ gemset 'right_api_client'
5
+ end
6
+ bundler do
7
+ version '1.0.10'
8
+ exclusions 'deployment'
9
+ bundle_path File.join(ENV["HOME"], '.rightscale', 'right_api_client')
10
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'yaml'
3
+
4
+ describe RightApi::Client do
5
+ context "Given a valid set of credentials in the config/login.yml file" do
6
+ before(:all) do
7
+ @creds = '../../config/login.yml'
8
+ begin
9
+ @client = RightApi::Client.new(YAML.load_file(File.expand_path(@creds, __FILE__)))
10
+ rescue Exception => e
11
+ 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"
12
+ puts e.message
13
+ end
14
+ end
15
+
16
+ it "Should login" do
17
+ @client.headers[:cookies].should_not be_nil
18
+ @client.session.index.message.should == 'You have successfully logged into the RightScale API.'
19
+ end
20
+
21
+ it "Should return a cookies Hash with a 'domain' and a '_session_id'" do
22
+ @client.cookies.class.should == Hash
23
+ @client.cookies.keys.sort.should == %w[ _session_id domain rs_gbl ]
24
+ end
25
+
26
+ it "Should accept a cookie argument when creating a new client" do
27
+ client1 = RightApi::Client.new(:cookies => @client.cookies)
28
+ client2 = RightApi::Client.new(YAML.load_file(File.expand_path(@creds, __FILE__)))
29
+
30
+ client1.cookies.should == @client.cookies
31
+ client2.cookies.should_not == @client.cookies
32
+ end
33
+
34
+ it "Should send post/get/put/delete requests to the server correctly" do
35
+ new_deployment = @client.deployments.create(:deployment => {:name => 'test'})
36
+ new_deployment2 = @client.deployments.create(:deployment => {:name => 'test2'})
37
+ new_deployment.class.should == RightApi::Resource
38
+ new_deployment.show.name.should == 'test'
39
+
40
+ deployment = @client.deployments(:id => new_deployment.show.href.split('/').last)
41
+ deployment.class.should == RightApi::Resource
42
+ deployment.show.class.should == RightApi::ResourceDetail
43
+ deployment.show.href.should == new_deployment.show.href
44
+
45
+ deployment.update(:deployment => {:name => 'test2'}).should be_nil
46
+ deployment.show.name.should == 'test2'
47
+
48
+ # Tags are a bit special as they use POST and return content type so they need specific tests
49
+ @client.tags.multi_add("resource_hrefs[]=#{deployment.show.href}&resource_hrefs[]=#{new_deployment2.show.href}&tags[]=tag1").should == ""
50
+ tags = @client.tags.by_resource("resource_hrefs[]=#{deployment.show.href}&resource_hrefs[]=#{new_deployment2.show.href}")
51
+ tags.class.should == Array
52
+ tags.first.class.should == RightApi::ResourceDetail
53
+ tags.first.tags.first.should == {"name" => "tag1"}
54
+ tags.first.resource.first.show.name.should == 'test2'
55
+
56
+ deployment.destroy.should be_nil
57
+ new_deployment2.destroy.should be_nil
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ include MockSpecHelper
3
+
4
+ describe RightApi::Client do
5
+ context "Given an instance-facing logged in RightScale user" do
6
+ before(:each) do
7
+ given_instance_facing_client
8
+ end
9
+
10
+ it "Should have the required methods for the client" do
11
+ @client.api_methods.sort.should == [:backups, :get_instance, :live_tasks, :volume_attachments, :volume_snapshots, :volume_types, :volumes]
12
+ end
13
+
14
+ it "Should return an instance of the Resource class when user provides an id" do
15
+ @client.volumes(:id => 1).class.should == RightApi::Resource
16
+ @client.backups(:id => 1).class.should == RightApi::Resource
17
+ @client.live_tasks(:id => 1).class.should == RightApi::Resource
18
+ end
19
+
20
+ it "Should return an instance of the Resources class when user does not provide an id" do
21
+ @client.volumes.class.should == RightApi::Resources
22
+ @client.backups.class.should == RightApi::Resources
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ include MockSpecHelper
3
+
4
+ describe RightApi::ResourceDetail do
5
+ context "Given a logged in RightScale user" do
6
+ before(:each) do
7
+ given_user_facing_client
8
+ end
9
+
10
+ it "Should have the required methods for instances of the ResourceDetail class" do
11
+ resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1', {})
12
+ resource.api_methods.sort.should == [:destroy, :links, :show, :update]
13
+ end
14
+
15
+ it "Should not have destroy/show/update for instances of the ResourceDetail class that do not support them" do
16
+ resource = RightApi::ResourceDetail.new(@client, 'session', '/api/session', {})
17
+ resource.api_methods.sort.should == [:links]
18
+ end
19
+
20
+ it "Should have resource-specific methods for instances of the ResourceDetail class" do
21
+ resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
22
+ {:attribute1 => 'value1', :attribute2 => 'value2'})
23
+ resource.api_methods.sort.should == [:attribute1, :attribute2, :destroy, :links, :show, :update]
24
+ end
25
+
26
+ it "Should have the links for instances of the ResourceDetail class" do
27
+ resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
28
+ {'links' => [{'rel' => 'link1', 'href' => 'link1_href'},
29
+ {'rel' => 'link2', 'href' => 'link2_href'}]})
30
+ resource.api_methods.sort.should == [:destroy, :link1, :link2, :links, :show, :update]
31
+ end
32
+
33
+ it "Should have the actions for instances of the ResourceDetail class" do
34
+ resource = RightApi::ResourceDetail.new(@client, 'deployment', '/api/deployments/1',
35
+ {'links' => [{'rel' => 'self', 'href' => 'self'}],
36
+ 'actions' => [{'rel' => 'action1'}, {'rel' => 'action2'}]})
37
+ resource.api_methods.sort.should == [:action1, :action2, :destroy, :href, :links, :show, :update]
38
+
39
+ flexmock(@rest_client).should_receive(:post).with({}, @header, Proc).and_return('ok')
40
+ resource.action1.should == 'ok'
41
+ end
42
+
43
+ it "Should have live_tasks for the 'instance' resource" do
44
+ resource = RightApi::ResourceDetail.new(@client, 'instance', '/api/instances/1', {})
45
+ resource.api_methods.sort.should == [:links, :live_tasks, :show, :update]
46
+ flexmock(RightApi::Resource).should_receive(:process).with(@client, 'live_task', '/api/instances/1/live/tasks/1').and_return('ok')
47
+ resource.live_tasks(:id => '1').should == 'ok'
48
+ end
49
+
50
+ it "Should add methods for child resources from detailed views" do
51
+ resource = RightApi::ResourceDetail.new(@client, 'server', '/api/servers/1', {
52
+ 'links' => [
53
+ {'href' => '/api/servers/1', 'rel' => 'self'},
54
+ {'href' => '/api/clouds/1/instances/1', 'rel' => 'current_instance'}],
55
+ 'current_instance' => {'links' => [{'href' => '/api/clouds/1/instances/1', 'rel' => 'self'}]}})
56
+ resource.api_methods.sort.should == [:current_instance, :destroy, :href, :links, :show, :update]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ include MockSpecHelper
3
+
4
+ describe RightApi::Resource do
5
+ context "Given a logged in RightScale user" do
6
+ before(:each) do
7
+ given_user_facing_client
8
+ end
9
+
10
+ it "Should have the required methods for instances of the Resource class" do
11
+ resource = RightApi::Resource.process(@client, 'deployment', '/api/deployments/1')
12
+ resource.api_methods.sort.should == [:destroy, :show, :update]
13
+ end
14
+
15
+ it "Should not have destroy/show/update for instances of the Resource class that do not support them" do
16
+ resource = RightApi::Resource.process(@client, 'session', '/api/session')
17
+ resource.api_methods.sort.should == []
18
+ end
19
+
20
+ it "Should have an array of ResourceDetail instances for index calls" do
21
+ resources = RightApi::Resource.process(@client, 'deployment', '/api/deployments', [{}])
22
+ resources.first.class.should == RightApi::ResourceDetail
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ include MockSpecHelper
3
+
4
+ describe RightApi::Resources do
5
+ context "Given a logged in RightScale user" do
6
+ before(:each) do
7
+ given_user_facing_client
8
+ end
9
+
10
+ it "Should have the required methods for instances of the Resources class" do
11
+ resource = RightApi::Resources.new(@client, '/api/deployments', 'deployments')
12
+ resource.api_methods.sort.should == [:create, :index]
13
+ end
14
+
15
+ it "Should not have index 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.should == [:by_resource, :by_tag, :multi_add, :multi_delete]
18
+ end
19
+
20
+ it "Should have resource-specific methods for instances of the Resources class" do
21
+ resource = RightApi::Resources.new(@client, '/api/backups', 'backups')
22
+ resource.api_methods.sort.should == [:cleanup, :create, :index]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'simplecov'
2
+ SimpleCov.start if ENV["COVERAGE"]
3
+ require File.expand_path('../../lib/right_api_client', __FILE__)
4
+ require 'spec'
5
+ require 'rest_client'
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.mock_with :flexmock
9
+ end
10
+
11
+ module MockSpecHelper
12
+ def mock_rest_client
13
+ @api_version = RightApi::Client::API_VERSION
14
+ @rest_client = RestClient::Resource.new(RightApi::Client::DEFAULT_API_URL)
15
+ flexmock(RestClient::Resource).should_receive(:new).and_return(@rest_client)
16
+ @session = flexmock(:cookies => '')
17
+ @header = {'X_API_VERSION' => @api_version, :cookies => '', :accept => :json}
18
+ end
19
+
20
+ def given_user_facing_client
21
+ mock_rest_client
22
+ flexmock(@rest_client).should_receive(:post).with(
23
+ {'email' => 'email', 'password' => 'password', 'account_href' => '/api/accounts/1'},
24
+ {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
25
+ flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{}'])
26
+ @client = RightApi::Client.new(:email => 'email', :password => 'password', :account_id => '1')
27
+ end
28
+
29
+ def given_instance_facing_client
30
+ mock_rest_client
31
+ flexmock(@rest_client).should_receive(:post).with(
32
+ {'instance_token' => 'instance_token', 'account_href' => '/api/accounts/1'},
33
+ {'X_API_VERSION' => @api_version}, Proc).and_return(@session)
34
+ flexmock(@rest_client).should_receive(:get).with(@header, Proc).and_return(['', '{"links": [
35
+ {
36
+ "href": "/api/clouds/1/instances/1",
37
+ "rel": "self"
38
+ }]}'])
39
+ @client = RightApi::Client.new(:instance_token => 'instance_token', :account_id => '1')
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: right_api_client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.5.1
6
+ platform: ruby
7
+ authors:
8
+ - Ali Khajeh-Hosseini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-28 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.3
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.7
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.3.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: flexmock
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.8.7
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: ruby-debug19
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
78
+ version: 0.11.6
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: simplecov
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - "="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ description: "\n\
105
+ The right_api_client gem simplifies the use of RightScale's MultiCloud API. It provides\n\
106
+ a simple object model of the API resources, and handles all of the fine details involved\n\
107
+ in making HTTP calls and translating their responses.\n "
108
+ email:
109
+ - alikhajeh1@gmail.com
110
+ executables: []
111
+
112
+ extensions: []
113
+
114
+ extra_rdoc_files: []
115
+
116
+ files:
117
+ - .gitignore
118
+ - CHANGELOG.rdoc
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.rdoc
122
+ - Rakefile
123
+ - config/login.yml.example
124
+ - lib/right_api_client.rb
125
+ - lib/right_api_client/client.rb
126
+ - lib/right_api_client/helper.rb
127
+ - lib/right_api_client/resource.rb
128
+ - lib/right_api_client/resource_detail.rb
129
+ - lib/right_api_client/resources.rb
130
+ - lib/right_api_client/version.rb
131
+ - login_to_client_irb.rb
132
+ - right_api_client.gemspec
133
+ - right_api_client.rconf
134
+ - spec/client_spec.rb
135
+ - spec/instance_facing_spec.rb
136
+ - spec/resource_detail_spec.rb
137
+ - spec/resource_spec.rb
138
+ - spec/resources_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: true
141
+ homepage: https://github.com/rightscale/right_api_client
142
+ licenses: []
143
+
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 2710163890528289054
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 2710163890528289054
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project:
170
+ rubygems_version: 1.6.2
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: RightScale MultiCloud API HTTP Client
174
+ test_files:
175
+ - config/login.yml.example
176
+ - spec/client_spec.rb
177
+ - spec/instance_facing_spec.rb
178
+ - spec/resource_detail_spec.rb
179
+ - spec/resource_spec.rb
180
+ - spec/resources_spec.rb
181
+ - spec/spec_helper.rb