cloudability 0.0.5 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 089d78278f2d92caf434767c88c8d04ed8c95ecc
4
- data.tar.gz: d918cba1038ea27011947c1c18df94e714dca66b
3
+ metadata.gz: 97772a04d10ae950a9ac8b6c7f821bf6a43fbbe6
4
+ data.tar.gz: 48ba113fcd25cc19921743f5fa6304b069897589
5
5
  SHA512:
6
- metadata.gz: e03406715373ac541fbef6f58b8b525396f812be03f8999966c69ebcefadc7ef61e1d9d536a77ff9b9b0111d65689bf99780b70e9d8f8158235910ac876f60ec
7
- data.tar.gz: cd06e24b5b8d9e7c5d68dc5f8f93d840e854a89896a2a3c214e33c62523d3c11713b8c450a388b78f898f83f4c59a630b12f24adba34f0c9b6470335543dd3cc
6
+ metadata.gz: a166392737fe8d90c66b8345e43cb3f4b29266291682f7c5d64cb81742c4784e214f662b23b5f725a079ca4cb45d07dad6241b3a11e832d5c0648afe69510ba3
7
+ data.tar.gz: 5945d472dce52218f9c54addec0f4cfb588bd94d92e8a86cff02b9d012b9eaea08612e364408e54d99f5214faae6436bcd2efa1b35f00812e1b1f0ae05ecbc50
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
+ Cloudability
2
+ ===
3
+
1
4
  [![Build Status](https://travis-ci.org/ColbyAley/cloudability.png?branch=master)](https://travis-ci.org/ColbyAley/cloudability)
5
+ [![Code Climate](https://codeclimate.com/github/ColbyAley/cloudability.png)](https://codeclimate.com/github/ColbyAley/cloudability)
6
+ [![Coverage Status](https://coveralls.io/repos/ColbyAley/cloudability/badge.png)](https://coveralls.io/r/ColbyAley/cloudability)
7
+
8
+ Ruby wrapper for the [Cloudability API](http://developers.cloudability.com/). Supports most of the public API endpoints, including some legacy ones such as bugets. Converts JSON responses to objects with Hashie::Mash.
2
9
 
3
- Ruby wrapper for the [Cloudability API](http://developers.cloudability.com/).
10
+ This is the README for version 0.1.0 of the gem. v0.1.0 introduces a radically different interface. If you're still on v0.0.5, please refer to it's [README](https://github.com/ColbyAley/cloudability/tree/v0.0.5).
4
11
 
5
12
  ## Installation
6
13
 
@@ -19,34 +26,61 @@ Or install it yourself as:
19
26
  ## Usage
20
27
 
21
28
  Supported endpoints:
29
+
22
30
  * Credentials
23
- * Budgets
24
- * Reporting
25
31
  * Organizations (Including invitations and roles.)
32
+ * Budgets
33
+ * Billing Reports
34
+ * Cost Reporrts
35
+ * Usage Reports
36
+
37
+ You will need to generate an API token to use the API. Read more [here](https://support.cloudability.com/hc/en-us/articles/200311933-API-Setup-and-Documentation).
26
38
 
27
39
  Feel free to shoot me an email at colby@cloudability.com if you have any questions or need help.
28
40
 
29
- ### Credentials
30
- Retrieve an array containing all your Cloud Accounts.
41
+ ### Examples
42
+
43
+ @client = Cloudability::Client.new(auth_token: 'auth_token')
44
+
45
+ #### Credentials
46
+
47
+ credentials = @client.credentials # Get all of your connected credentials
48
+ puts first_account.last.account_created_at
49
+ puts credentials.first.account_identifier
50
+
51
+ #### Organizations
52
+
53
+ @client.invite_user('colby@cloudability.com', name: 'Colby Aley') # Invite a user to your org
54
+ @client.delete_invite(1) # Delete invite 1
55
+ @client.update_invite(103,1) # Update invitation 103 to have role id 1
56
+ @client.my_organization # Get info about your org
57
+ @client.organization_invitations # List invitations for your org
58
+ @client.organization_roles # List roles for your org
59
+
60
+ #### Budgets
61
+
62
+ @client.budgets # List your current budgets
63
+
64
+ #### Billing Reports
65
+
66
+ @client.billing_report # Generate a report of your spend
67
+ @client.billing_report(vendor: 'Amazon', by: 'period')
68
+ @client.billing_report(by: 'vendor')
31
69
 
32
- credentials = Cloudability::Credentials.new(auth_token: 'xxxxxxxxxxxxxxxxxxxx')
33
- all_credentials = credentials.find_all
70
+ #### Cost Reports
34
71
 
35
- puts first_account.account_created_at
36
- puts first_account.account_identifier
37
- puts first_account.created_at
38
- puts first_account.has_auth
39
- puts first_account.has_estimate
72
+ @client.cost_reports # List cost reports
73
+ @client.cost_measures # List measures supported by server
74
+ @client.cost_filters # List filters supported by the server
40
75
 
41
- ### Organizations
76
+ #### Usage Reports
42
77
 
43
- c = Cloudability::Organizations.new(auth_token: 'xxxxxxxxxxxxxxxxxxxx')
44
- c.invite_user(email: 'colby@cloudability.com', name: 'Colby Aley')
45
- c.roles
46
- c.invitations
78
+ @client.usage_reports # List usage reports
79
+ @client.usage_measures # List measures supported by server
80
+ @client.usage_filters # List filters supported by the server
47
81
 
48
82
  ## TODO:
49
- * More tests!
83
+ * Better tests!
50
84
  * More endpoints!
51
85
  * More awesomeness!
52
86
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency('rspec')
24
24
  gem.add_development_dependency('fakeweb')
25
25
  gem.add_development_dependency('rake', '~> 0.6')
26
+ gem.add_development_dependency('coveralls')
26
27
  end
@@ -1,9 +1,70 @@
1
1
  require 'httparty'
2
2
  require 'hashie'
3
3
 
4
- require 'cloudability/billing'
5
- require 'cloudability/budgets'
6
- require 'cloudability/credentials'
7
- require 'cloudability/organizations'
4
+ require 'cloudability/client/billing_reports'
5
+ require 'cloudability/client/cost_reports'
6
+ require 'cloudability/client/usage_reports'
7
+ require 'cloudability/client/budgets'
8
+ require 'cloudability/client/credentials'
9
+ require 'cloudability/client/organizations'
8
10
 
9
11
  require 'cloudability/version'
12
+
13
+
14
+ module Cloudability
15
+ class Client
16
+ include Cloudability::Client::BillingReports
17
+ include Cloudability::Client::UsageReports
18
+ include Cloudability::Client::CostReports
19
+ include Cloudability::Client::Budgets
20
+ include Cloudability::Client::Credentials
21
+ include Cloudability::Client::Organizations
22
+ include HTTParty
23
+
24
+ def initialize(options={})
25
+ raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?
26
+ @auth_token = options[:auth_token]
27
+ end
28
+
29
+ base_uri 'https://app.cloudability.com/api'
30
+
31
+ private
32
+
33
+ def get(url, params={})
34
+ response = self.class.get(url, options(query: params))
35
+ response.success? ? response : raise(response.response)
36
+ end
37
+
38
+ def post(url, params={})
39
+ response = self.class.post(url, options(query: params))
40
+ response.success? ? response : raise(response.response)
41
+ end
42
+
43
+ def put(url, params={})
44
+ response = self.class.put(url, options(query: params))
45
+ response.success? ? response : raise(response.response)
46
+ end
47
+
48
+ def delete(url, params={})
49
+ response = self.class.delete(url, options(query: params))
50
+ response.success? ? response : raise(response.response)
51
+ end
52
+
53
+ # Convert the an array of hashes into an array of Mashes!
54
+ #
55
+ # @param [String] array of hashes.
56
+ # @return [Array] array of Hashie::Mashes
57
+ def convert_to_mashes(array)
58
+ array.map { |element| Hashie::Mash.new(element) }
59
+ end
60
+
61
+ def options(o={})
62
+ o[:query] ||= {}
63
+ o[:headers] ||= {}
64
+ o[:headers]['User-Agent'] = "Cloudability-Ruby #{Cloudability::VERSION}"
65
+ o[:query][:auth_token] = @auth_token
66
+ o
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,22 @@
1
+ module Cloudability
2
+ class Client
3
+ module BillingReports
4
+
5
+ # Generate a report of your spend
6
+ #
7
+ # @param [Hash] optional parameters
8
+ # @return [Array] array of Hashie::Mashes
9
+ # @see http://developers.cloudability.com/resources/billing_reports/
10
+ # @example generate report
11
+ # .billing_report(vendor: 'Amazon')
12
+ # .billing_report(by: 'vendor')
13
+ # .billing_report(by: 'service', vendor: 'Amazon', period: '2012-03-01')
14
+ def billing_report(options={})
15
+ request = get '/1/billing_reports', options
16
+ convert_to_mashes request
17
+ end
18
+ alias :billing_reports :billing_report
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Cloudability
2
+ class Client
3
+ module Budgets
4
+
5
+ # Retrieve information about your budgets
6
+ #
7
+ # @return [Array] array of Hashie::Mashes
8
+ def budgets
9
+ request = get '/1/budgets/index'
10
+ convert_to_mashes(request)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ module Cloudability
2
+ class Client
3
+ module CostReports
4
+
5
+ # List current cost reports
6
+ #
7
+ # @see http://developers.cloudability.com/resources/cost/
8
+ # @return [Array] array of Hashie::Mashes
9
+ def cost_reports
10
+ response = get '/1/reporting/cost'
11
+ convert_to_mashes response
12
+ end
13
+
14
+ # List measures recognized by the server
15
+ #
16
+ # @see http://developers.cloudability.com/resources/cost/
17
+ # @return [Array] array of Hashie::Mashes
18
+ def cost_measures
19
+ response = get '/1/reporting/cost/measures'
20
+ convert_to_mashes response
21
+ end
22
+
23
+ # List available filters for requesting data
24
+ #
25
+ # @see http://developers.cloudability.com/resources/cost/
26
+ # @return [Array] array of filters as strings
27
+ def cost_filters
28
+ get('/1/reporting/cost/filters').to_a
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module Cloudability
2
+ class Client
3
+ module Credentials
4
+
5
+ # Get information about your configured credentials
6
+ #
7
+ # @return [Array] array of Hashie::Mashes
8
+ def credentials
9
+ request = get '/0/credentials/index'
10
+ convert_to_mashes request
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,76 @@
1
+ module Cloudability
2
+ class Client
3
+ module Organizations
4
+
5
+ # Get information about the authenticted user's organization
6
+ # NOTE: This requires that you are the organization admin.
7
+ #
8
+ # @return [Hashie::Mash]
9
+ def my_organization
10
+ request = get '/1/organizations'
11
+ Hashie::Mash.new request
12
+ end
13
+ alias :organization :my_organization
14
+
15
+ # List all invitations to the authenticated user's organization
16
+ #
17
+ # @see http://developers.cloudability.com/resources/organizations/invitations/
18
+ # @return [Array] array of Hashie::Mashes
19
+ def organization_invitations
20
+ request = get '/1/organizations/invitations'
21
+ convert_to_mashes request
22
+ end
23
+ alias :invitations :organization_invitations
24
+
25
+ # Retrieve your organizations roles.
26
+ #
27
+ # @return [Array] array of Hashie::Mashes
28
+ def organization_roles
29
+ request = get '/1/organizations/roles'
30
+ convert_to_mashes request
31
+ end
32
+ alias :roles :organization_roles
33
+
34
+ # Create a new invitation to the authenticated user's organization
35
+ #
36
+ # @see http://developers.cloudability.com/resources/organizations/invitations/
37
+ # @param [String] email to send invitation to
38
+ # @param [Hash] args to pass to HTTParty
39
+ # @option [String] name
40
+ # @option [String] role_id
41
+ def invite_user(email, options={})
42
+ options[:email] = email
43
+
44
+ request = post '/1/organizations/invitations', options
45
+ Hashie::Mash.new request
46
+ end
47
+ alias :invite :invite_user
48
+
49
+ # Delete an invitation to the authenticated user's organization
50
+ #
51
+ # @see http://developers.cloudability.com/resources/organizations/invitations/
52
+ # @param [Integer] id of the invitation
53
+ # @return
54
+ def delete_invite(id)
55
+ request = delete "/1/organizations/invitations/#{id}"
56
+ Hashie::Mash.new request
57
+ end
58
+ alias :delete_invitation :delete_invite
59
+
60
+ # Update a user's invitation to an organization.
61
+ #
62
+ # @see http://developers.cloudability.com/resources/organizations/invitations/
63
+ # @param [Integer] id to update
64
+ # @param [Integer] role id to assign to invite
65
+ # @return [Hashie::Mash]
66
+ def update_invite(id, role_id)
67
+ options = {}
68
+ options[:role_id] = role_id
69
+
70
+ request = put "/1/organizations/invitations/#{id}", options
71
+ Hashie::Mash.new request
72
+ end
73
+ alias :update_invitation :update_invite
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,33 @@
1
+ module Cloudability
2
+ class Client
3
+ module UsageReports
4
+
5
+ # List current usage reports.
6
+ #
7
+ # @see http://developers.cloudability.com/resources/usage/
8
+ # @return [Array] array of Hashie::Mashes
9
+ def usage_reports
10
+ request = get '/1/reporting'
11
+ convert_to_mashes request
12
+ end
13
+
14
+ # List measures recognized by the server
15
+ #
16
+ # @see http://developers.cloudability.com/resources/usage/
17
+ # @return [Array] array of Hashie::Mashes
18
+ def usage_measures
19
+ request = get '/1/reporting/measures'
20
+ convert_to_mashes request
21
+ end
22
+
23
+ # List available filters for requesting data
24
+ #
25
+ # @see http://developers.cloudability.com/resources/usage/
26
+ # @return [Array] array of filters as strings
27
+ def usage_filters
28
+ get('/1/reporting/filters').to_a
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Cloudability
2
- VERSION = "0.0.5"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,53 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Cloudability::Billing do
4
- describe '#initialize' do
5
- it 'should raise ArgumentError when auth_token is not provided' do
6
- expect { Cloudability::Billing.new }.to raise_exception(ArgumentError)
7
- end
8
-
9
- it 'should not raise any exception when auth token is provided' do
10
- expect { Cloudability::Billing.new(auth_token: 'token') }.not_to raise_exception
11
- end
12
- end
3
+ describe Cloudability::Client::BillingReports do
13
4
 
14
5
  before do
15
- @cloudability = Cloudability::Billing.new(auth_token: 'token')
6
+ @client = Cloudability::Client.new(auth_token: 'token')
16
7
  end
17
-
18
- describe '#report_by' do
19
- it 'should raise an ArgumentError when no dimension is passed' do
20
- expect { @cloudability.report_by }.to raise_exception(ArgumentError)
21
- end
22
-
23
- it 'should raise an ArgumentError when unknown dimension is passed' do
24
- expect { @cloudability.report_by(:coolness) }.to raise_exception(ArgumentError)
25
- end
26
8
 
9
+ describe '#billing_reports' do
27
10
  it 'should be an array' do
28
- stub_get('/0/billing_reports?auth_token=token&by=account', 'report_by_account')
29
- @cloudability.report_by(:account).class.should == Array
11
+ stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
12
+ @client.billing_report.should be_kind_of Array
30
13
  end
31
14
 
32
15
  it 'should be an array of Hashie::Mashes' do
33
- stub_get('/0/billing_reports?auth_token=token&by=account', 'report_by_account')
34
- @cloudability.report_by(:account).each{|report| report.class.should == Hashie::Mash }
16
+ stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
17
+ @client.billing_report.each{|report| report.should be_kind_of Hashie::Mash }
35
18
  end
36
- end
37
19
 
38
- describe '#filter_by_period' do
39
- it 'should get a report given a period' do
40
- stub_get('/0/billing_reports?auth_token=token&period=13-08-05', 'report_by_period')
41
- expect { @cloudability.filter_by_period('13-08-05') }.not_to raise_exception
20
+ it 'should have a currency attrubute on every element' do
21
+ stub_get('/1/billing_reports?auth_token=token', 'billing_reports')
22
+ @client.billing_report.each{|report| report.currency.should_not be_nil }
42
23
  end
43
24
 
44
- it 'should be a Hashie::Mash' do
45
- stub_get('/0/billing_reports?auth_token=token&period=13-08-05', 'report_by_period')
46
- @cloudability.filter_by_period('13-08-05').class.should == Hashie::Mash
25
+ it 'should return results by service' do
26
+ stub_get('/1/billing_reports?auth_token=token&by=service', 'billing_reports')
27
+ expect { @client.billing_report(by: 'service') }.not_to raise_exception
47
28
  end
48
29
 
49
- it 'should raise an ArgumentError when an invalid date is provided' do
50
- expect { @cloudability.filter_by_period('1343-08-05') }.to raise_exception(ArgumentError)
30
+ it 'should return results given by service, given the vendor and period' do
31
+ 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
51
33
  end
52
34
  end
53
35
  end