Skip to content

Commit 40ee899

Browse files
committed
Version 0.2.0:
- Add support for Users API endpoints - Fix typo in directory structure
1 parent ca9287a commit 40ee899

17 files changed

Lines changed: 221 additions & 72 deletions

cloudability.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
2424
gem.add_development_dependency('fakeweb')
2525
gem.add_development_dependency('rake', '~> 0.6')
2626
gem.add_development_dependency('coveralls')
27+
gem.add_development_dependency('pry')
2728
end

lib/cloudability.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'cloudability/client/budgets'
88
require 'cloudability/client/credentials'
99
require 'cloudability/client/organizations'
10+
require 'cloudability/client/users'
1011

1112
require 'cloudability/version'
1213

@@ -22,6 +23,7 @@ class Client
2223
include Budgets
2324
include Credentials
2425
include Organizations
26+
include Users
2527

2628
include HTTParty
2729

lib/cloudability/client/users.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module Cloudability
2+
class Client
3+
module Users
4+
# Documentation: http://developers.cloudability.com/resources/users/
5+
6+
# List users in your organization.
7+
#
8+
# @return [Array] array of Hashie::Mashes
9+
def users
10+
request = get '/1/users'
11+
convert_to_mashes(request)
12+
end
13+
14+
# Add a user to your organization
15+
#
16+
# @param [String] email of user
17+
# @param [Hash] options
18+
# @option [String] full_name
19+
# @option [String] role
20+
# @option [Boolean] restricted
21+
# @option [Array] new_shared_dimension_filter_set_ids
22+
# @option [Integer] default_dimension_filter_set_id
23+
# @return [Array] array of Hashie::Mashes
24+
def add_user(email, options={})
25+
options[:email] = email
26+
27+
payload = {user: options}
28+
request = post '/1/users', payload
29+
Hashie::Mash.new request
30+
end
31+
32+
# Update a user in your organization
33+
#
34+
# @param [Integer] ID of user
35+
# @param [Hash] options
36+
# @option [String] full_name
37+
# @option [String] role
38+
# @option [Boolean] restricted
39+
# @option [Array] new_shared_dimension_filter_set_ids
40+
# @option [Integer] default_dimension_filter_set_id
41+
# @return [Array] array of Hashie::Mashes
42+
def update_user(id, options={})
43+
payload = {user: options}
44+
request = put "/1/users/#{id}", payload
45+
Hashie::Mash.new request
46+
end
47+
48+
# Delete a user in your organization
49+
#
50+
# @param [Integer] ID of user
51+
# @return [Boolean] success
52+
def delete_user(id)
53+
delete "/1/users/#{id}"
54+
end
55+
end
56+
end
57+
end

lib/cloudability/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cloudability
2-
VERSION = '0.1.1'
2+
VERSION = '0.2.0'
33
end
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
require 'spec_helper'
22

33
describe Cloudability::Client::BillingReports do
4-
5-
before do
6-
@client = Cloudability::Client.new(auth_token: 'token')
7-
end
4+
let(:client) { Cloudability::Client.new(auth_token: 'token') }
85

96
describe '#billing_reports' do
107
it 'should be an array' do
118
stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
12-
@client.billing_report.should be_kind_of Array
9+
client.billing_report.should be_kind_of Array
1310
end
1411

1512
it 'should be an array of Hashie::Mashes' do
1613
stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
17-
@client.billing_report.each{|report| report.should be_kind_of Hashie::Mash }
14+
client.billing_report.each{|report| report.should be_kind_of Hashie::Mash }
1815
end
1916

2017
it 'should have a currency attrubute on every element' do
2118
stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
22-
@client.billing_report.each{|report| report.currency.should_not be_nil }
19+
client.billing_report.each{|report| report.currency.should_not be_nil }
2320
end
2421

2522
it 'should return results by service' do
2623
stub_get('/1/billing_reports?auth_token=token&by=service', 'billing_reports')
27-
expect { @client.billing_report(by: 'service') }.not_to raise_exception
24+
expect { client.billing_report(by: 'service') }.not_to raise_exception
2825
end
2926

3027
it 'should return results given by service, given the vendor and period' do
3128
stub_get('/1/billing_reports?auth_token=token&by=service&vendor=Amazon&period=2012-03-01', 'billing_reports')
32-
expect { @client.billing_report(by: 'service', vendor: 'Amazon', period: '2012-03-01') }.not_to raise_exception
29+
expect { client.billing_report(by: 'service', vendor: 'Amazon', period: '2012-03-01') }.not_to raise_exception
3330
end
3431
end
3532
end
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
require 'spec_helper'
22

33
describe Cloudability::Client::Budgets do
4-
5-
before do
6-
@client = Cloudability::Client.new(auth_token: 'token')
7-
end
4+
let(:client) { Cloudability::Client.new(auth_token: 'token') }
85

96
describe '#budgets' do
107
it 'should be an array' do
118
stub_get('/1/budgets/index?auth_token=token', 'budgets')
12-
@client.budgets.should be_kind_of Array
9+
client.budgets.should be_kind_of Array
1310
end
1411

1512
it 'should be an array of Hashie::Mashes' do
1613
stub_get('/1/budgets/index?auth_token=token', 'budgets')
17-
@client.budgets.each{|budget| budget.should be_kind_of Hashie::Mash }
14+
client.budgets.each{|budget| budget.should be_kind_of Hashie::Mash }
1815
end
1916

2017
it 'should be mappable by ID' do
2118
stub_get('/1/budgets/index?auth_token=token', 'budgets')
22-
@client.budgets.map(&:id).should be_kind_of Array
19+
client.budgets.map(&:id).should be_kind_of Array
2320
end
2421

2522
it 'should be mappable by ID and not be empty' do
2623
stub_get('/1/budgets/index?auth_token=token', 'budgets')
27-
@client.budgets.map(&:id).should_not be_empty
24+
client.budgets.map(&:id).should_not be_empty
2825
end
2926
end
3027
end
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,76 @@
11
require 'spec_helper'
22

33
describe Cloudability::Client::CostReports do
4-
5-
before do
6-
@client = Cloudability::Client.new(auth_token: 'token')
7-
end
4+
let(:client) { Cloudability::Client.new(auth_token: 'token') }
85

96
describe '#cost_reports' do
107
it 'should be an array' do
118
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
12-
@client.cost_reports.should be_kind_of Array
9+
client.cost_reports.should be_kind_of Array
1310
end
1411

1512
it 'should be mappable by ID' do
1613
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
17-
@client.cost_reports.map(&:id).should be_kind_of Array
14+
client.cost_reports.map(&:id).should be_kind_of Array
1815
end
1916

2017
it 'should be mappable by ID and not be empty' do
2118
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
22-
@client.cost_reports.map(&:id).should_not be_empty
19+
client.cost_reports.map(&:id).should_not be_empty
2320
end
2421

2522
it 'should be mappable by category and not be empty' do
2623
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
27-
@client.cost_reports.map(&:category).should_not be_empty
24+
client.cost_reports.map(&:category).should_not be_empty
2825
end
2926

3027
it 'should be an array of Hashie::Mashes' do
3128
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
32-
@client.cost_reports.each{|report| report.should be_kind_of Hashie::Mash }
29+
client.cost_reports.each{|report| report.should be_kind_of Hashie::Mash }
3330
end
3431
end
3532

3633
describe '#cost_measures' do
3734
it 'should be an array' do
3835
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
39-
@client.cost_measures.should be_kind_of Array
36+
client.cost_measures.should be_kind_of Array
4037
end
4138

4239
it 'should be mappable by type' do
4340
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
44-
@client.cost_measures.map(&:type).should be_kind_of Array
41+
client.cost_measures.map(&:type).should be_kind_of Array
4542
end
4643

4744
it 'should be mappable by type and not be empty' do
4845
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
49-
@client.cost_measures.map(&:type).should_not be_empty
46+
client.cost_measures.map(&:type).should_not be_empty
5047
end
5148

5249
it 'should be an array of Hashie::Mashes' do
5350
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
54-
@client.cost_measures.each{|measure| measure.should be_kind_of Hashie::Mash }
51+
client.cost_measures.each{|measure| measure.should be_kind_of Hashie::Mash }
5552
end
5653
end
5754

5855
describe '#cost_filters' do
5956
it 'should be an array' do
6057
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
61-
@client.cost_filters.should be_kind_of Array
58+
client.cost_filters.should be_kind_of Array
6259
end
6360

6461
it 'should not be an empty array' do
6562
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
66-
@client.cost_filters.should_not be_empty
63+
client.cost_filters.should_not be_empty
6764
end
6865

6966
it 'should not be an empty array' do
7067
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
71-
@client.cost_filters.should_not be_empty
68+
client.cost_filters.should_not be_empty
7269
end
7370

7471
it 'should be an array of strings' do
7572
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
76-
@client.cost_filters.each{|filter| filter.should be_kind_of String }
73+
client.cost_filters.each{|filter| filter.should be_kind_of String }
7774
end
7875
end
7976
end
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
require 'spec_helper'
22

33
describe Cloudability::Client::Credentials do
4-
5-
before do
6-
@client = Cloudability::Client.new(auth_token: 'token')
7-
end
4+
let(:client) { Cloudability::Client.new(auth_token: 'token') }
85

96
describe '#credentials' do
107
it 'should be an array' do
118
stub_get('/0/credentials/index?auth_token=token', 'credentials')
12-
@client.credentials.should be_kind_of Array
9+
client.credentials.should be_kind_of Array
1310
end
1411

1512
it 'should be an array of Hashie::Mashes' do
1613
stub_get('/0/credentials/index?auth_token=token', 'credentials')
17-
@client.credentials.each{|report| report.should be_kind_of Hashie::Mash }
14+
client.credentials.each{|report| report.should be_kind_of Hashie::Mash }
1815
end
1916
end
2017
end
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,80 @@
11
require 'spec_helper'
22

33
describe Cloudability::Client::Organizations do
4+
let(:client) { Cloudability::Client.new(auth_token: 'token') }
45

5-
before do
6-
@client = Cloudability::Client.new(auth_token: 'token')
7-
end
8-
96
describe '#my_organization' do
107
it 'should be a Hashie::Mashe' do
118
stub_get('/1/organizations?auth_token=token', 'organization')
12-
@client.my_organization.should be_kind_of Hashie::Mash
9+
client.my_organization.should be_kind_of Hashie::Mash
1310
end
1411
end
1512

1613
describe '#organization_invitations' do
1714
it 'should be an Array' do
1815
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
19-
@client.organization_invitations.should be_kind_of Array
16+
client.organization_invitations.should be_kind_of Array
2017
end
2118

2219
it 'should be an array of Hashie::Mashes' do
2320
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
24-
@client.organization_invitations.each{|invite| invite.should be_kind_of Hashie::Mash }
21+
client.organization_invitations.each{|invite| invite.should be_kind_of Hashie::Mash }
2522
end
2623

2724
it 'should be mappable by ID' do
2825
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
29-
@client.organization_invitations.map(&:id).should be_kind_of Array
26+
client.organization_invitations.map(&:id).should be_kind_of Array
3027
end
3128

3229
it 'should be mappable by ID and not be empty' do
3330
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
34-
@client.organization_invitations.map(&:id).should_not be_empty
31+
client.organization_invitations.map(&:id).should_not be_empty
3532
end
3633
end
3734

3835
describe '#organization_roles' do
3936
it 'should be an Array' do
4037
stub_get('/1/organizations/roles?auth_token=token', 'organization_roles')
41-
@client.organization_roles.should be_kind_of Array
38+
client.organization_roles.should be_kind_of Array
4239
end
4340

4441
it 'should be an array of Hashie::Mashes' do
4542
stub_get('/1/organizations/roles?auth_token=token', 'organization_roles')
46-
@client.organization_roles.each{|role| role.should be_kind_of Hashie::Mash }
43+
client.organization_roles.each{|role| role.should be_kind_of Hashie::Mash }
4744
end
4845
end
4946

5047
describe '#invite_user' do
5148
it 'should be a Hashie::Mash' do
5249
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com', 'organization_invitation')
53-
@client.invite_user('colbyaleyrb@gmail.com').should be_kind_of Hashie::Mash
50+
client.invite_user('colbyaleyrb@gmail.com').should be_kind_of Hashie::Mash
5451
end
5552

5653
it 'should accept a hash with email and name' do
5754
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com&name=colby', 'organization_invitation')
58-
expect { @client.invite_user('colbyaleyrb@gmail.com', name: 'colby') }.not_to raise_exception
55+
expect { client.invite_user('colbyaleyrb@gmail.com', name: 'colby') }.not_to raise_exception
5956
end
6057
end
6158

6259
describe '#delete_invite' do
6360
it 'should should not raise an exception when id is provided' do
6461
stub_delete('/1/organizations/invitations/1?auth_token=token', 'organization_invitation')
65-
expect { @client.delete_invite(1) }.not_to raise_exception
62+
expect { client.delete_invite(1) }.not_to raise_exception
6663
end
6764

6865
it 'should require id as an argument' do
69-
expect { @client.delete_invite }.to raise_exception(ArgumentError)
66+
expect { client.delete_invite }.to raise_exception(ArgumentError)
7067
end
7168
end
7269

7370
describe '#update_invite' do
7471
it 'should should not raise an exception when id and role_id are provided' do
7572
stub_put('/1/organizations/invitations/1?role_id=1&auth_token=token', 'organization_invitation')
76-
expect { @client.update_invite(1,1) }.not_to raise_exception
73+
expect { client.update_invite(1,1) }.not_to raise_exception
7774
end
7875

7976
it 'should require id and role_id as arguments' do
80-
expect { @client.update_invite }.to raise_exception(ArgumentError)
77+
expect { client.update_invite }.to raise_exception(ArgumentError)
8178
end
8279
end
83-
end
80+
end

0 commit comments

Comments
 (0)