Skip to content

Commit

Permalink
Merge pull request #4 from ColbyAley/0.2.0
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
cp committed Nov 1, 2015
2 parents ca9287a + 40ee899 commit 99f0959
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 72 deletions.
1 change: 1 addition & 0 deletions cloudability.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('fakeweb')
gem.add_development_dependency('rake', '~> 0.6')
gem.add_development_dependency('coveralls')
gem.add_development_dependency('pry')
end
2 changes: 2 additions & 0 deletions lib/cloudability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'cloudability/client/budgets'
require 'cloudability/client/credentials'
require 'cloudability/client/organizations'
require 'cloudability/client/users'

require 'cloudability/version'

Expand All @@ -22,6 +23,7 @@ class Client
include Budgets
include Credentials
include Organizations
include Users

include HTTParty

Expand Down
57 changes: 57 additions & 0 deletions lib/cloudability/client/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Cloudability
class Client
module Users
# Documentation: http://developers.cloudability.com/resources/users/

# List users in your organization.
#
# @return [Array] array of Hashie::Mashes
def users
request = get '/1/users'
convert_to_mashes(request)
end

# Add a user to your organization
#
# @param [String] email of user
# @param [Hash] options
# @option [String] full_name
# @option [String] role
# @option [Boolean] restricted
# @option [Array] new_shared_dimension_filter_set_ids
# @option [Integer] default_dimension_filter_set_id
# @return [Array] array of Hashie::Mashes
def add_user(email, options={})
options[:email] = email

payload = {user: options}
request = post '/1/users', payload
Hashie::Mash.new request
end

# Update a user in your organization
#
# @param [Integer] ID of user
# @param [Hash] options
# @option [String] full_name
# @option [String] role
# @option [Boolean] restricted
# @option [Array] new_shared_dimension_filter_set_ids
# @option [Integer] default_dimension_filter_set_id
# @return [Array] array of Hashie::Mashes
def update_user(id, options={})
payload = {user: options}
request = put "/1/users/#{id}", payload
Hashie::Mash.new request
end

# Delete a user in your organization
#
# @param [Integer] ID of user
# @return [Boolean] success
def delete_user(id)
delete "/1/users/#{id}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cloudability/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Cloudability
VERSION = '0.1.1'
VERSION = '0.2.0'
end
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
require 'spec_helper'

describe Cloudability::Client::BillingReports do

before do
@client = Cloudability::Client.new(auth_token: 'token')
end
let(:client) { Cloudability::Client.new(auth_token: 'token') }

describe '#billing_reports' do
it 'should be an array' do
stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
@client.billing_report.should be_kind_of Array
client.billing_report.should be_kind_of Array
end

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

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

it 'should return results by service' do
stub_get('/1/billing_reports?auth_token=token&by=service', 'billing_reports')
expect { @client.billing_report(by: 'service') }.not_to raise_exception
expect { client.billing_report(by: 'service') }.not_to raise_exception
end

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

describe Cloudability::Client::Budgets do

before do
@client = Cloudability::Client.new(auth_token: 'token')
end
let(:client) { Cloudability::Client.new(auth_token: 'token') }

describe '#budgets' do
it 'should be an array' do
stub_get('/1/budgets/index?auth_token=token', 'budgets')
@client.budgets.should be_kind_of Array
client.budgets.should be_kind_of Array
end

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

it 'should be mappable by ID' do
stub_get('/1/budgets/index?auth_token=token', 'budgets')
@client.budgets.map(&:id).should be_kind_of Array
client.budgets.map(&:id).should be_kind_of Array
end

it 'should be mappable by ID and not be empty' do
stub_get('/1/budgets/index?auth_token=token', 'budgets')
@client.budgets.map(&:id).should_not be_empty
client.budgets.map(&:id).should_not be_empty
end
end
end
31 changes: 14 additions & 17 deletions spec/cloduability/cost_spec.rb → spec/cloudability/cost_spec.rb
Original file line number Diff line number Diff line change
@@ -1,79 +1,76 @@
require 'spec_helper'

describe Cloudability::Client::CostReports do

before do
@client = Cloudability::Client.new(auth_token: 'token')
end
let(:client) { Cloudability::Client.new(auth_token: 'token') }

describe '#cost_reports' do
it 'should be an array' do
stub_get('/1/reporting/cost?auth_token=token', 'cost/reports')
@client.cost_reports.should be_kind_of Array
client.cost_reports.should be_kind_of Array
end

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

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

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

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

describe '#cost_measures' do
it 'should be an array' do
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
@client.cost_measures.should be_kind_of Array
client.cost_measures.should be_kind_of Array
end

it 'should be mappable by type' do
stub_get('/1/reporting/cost/measures?auth_token=token', 'cost/measures')
@client.cost_measures.map(&:type).should be_kind_of Array
client.cost_measures.map(&:type).should be_kind_of Array
end

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

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

describe '#cost_filters' do
it 'should be an array' do
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
@client.cost_filters.should be_kind_of Array
client.cost_filters.should be_kind_of Array
end

it 'should not be an empty array' do
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
@client.cost_filters.should_not be_empty
client.cost_filters.should_not be_empty
end

it 'should not be an empty array' do
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
@client.cost_filters.should_not be_empty
client.cost_filters.should_not be_empty
end

it 'should be an array of strings' do
stub_get('/1/reporting/cost/filters?auth_token=token', 'cost/filters')
@client.cost_filters.each{|filter| filter.should be_kind_of String }
client.cost_filters.each{|filter| filter.should be_kind_of String }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
require 'spec_helper'

describe Cloudability::Client::Credentials do

before do
@client = Cloudability::Client.new(auth_token: 'token')
end
let(:client) { Cloudability::Client.new(auth_token: 'token') }

describe '#credentials' do
it 'should be an array' do
stub_get('/0/credentials/index?auth_token=token', 'credentials')
@client.credentials.should be_kind_of Array
client.credentials.should be_kind_of Array
end

it 'should be an array of Hashie::Mashes' do
stub_get('/0/credentials/index?auth_token=token', 'credentials')
@client.credentials.each{|report| report.should be_kind_of Hashie::Mash }
client.credentials.each{|report| report.should be_kind_of Hashie::Mash }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,83 +1,80 @@
require 'spec_helper'

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

before do
@client = Cloudability::Client.new(auth_token: 'token')
end

describe '#my_organization' do
it 'should be a Hashie::Mashe' do
stub_get('/1/organizations?auth_token=token', 'organization')
@client.my_organization.should be_kind_of Hashie::Mash
client.my_organization.should be_kind_of Hashie::Mash
end
end

describe '#organization_invitations' do
it 'should be an Array' do
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
@client.organization_invitations.should be_kind_of Array
client.organization_invitations.should be_kind_of Array
end

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

it 'should be mappable by ID' do
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
@client.organization_invitations.map(&:id).should be_kind_of Array
client.organization_invitations.map(&:id).should be_kind_of Array
end

it 'should be mappable by ID and not be empty' do
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
@client.organization_invitations.map(&:id).should_not be_empty
client.organization_invitations.map(&:id).should_not be_empty
end
end

describe '#organization_roles' do
it 'should be an Array' do
stub_get('/1/organizations/roles?auth_token=token', 'organization_roles')
@client.organization_roles.should be_kind_of Array
client.organization_roles.should be_kind_of Array
end

it 'should be an array of Hashie::Mashes' do
stub_get('/1/organizations/roles?auth_token=token', 'organization_roles')
@client.organization_roles.each{|role| role.should be_kind_of Hashie::Mash }
client.organization_roles.each{|role| role.should be_kind_of Hashie::Mash }
end
end

describe '#invite_user' do
it 'should be a Hashie::Mash' do
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com', 'organization_invitation')
@client.invite_user('[email protected]').should be_kind_of Hashie::Mash
client.invite_user('[email protected]').should be_kind_of Hashie::Mash
end

it 'should accept a hash with email and name' do
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com&name=colby', 'organization_invitation')
expect { @client.invite_user('[email protected]', name: 'colby') }.not_to raise_exception
expect { client.invite_user('[email protected]', name: 'colby') }.not_to raise_exception
end
end

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

it 'should require id as an argument' do
expect { @client.delete_invite }.to raise_exception(ArgumentError)
expect { client.delete_invite }.to raise_exception(ArgumentError)
end
end

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

it 'should require id and role_id as arguments' do
expect { @client.update_invite }.to raise_exception(ArgumentError)
expect { client.update_invite }.to raise_exception(ArgumentError)
end
end
end
end
Loading

0 comments on commit 99f0959

Please sign in to comment.