cloudability 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -18
- data/cloudability.gemspec +1 -0
- data/lib/cloudability.rb +65 -4
- data/lib/cloudability/client/billing_reports.rb +22 -0
- data/lib/cloudability/client/budgets.rb +15 -0
- data/lib/cloudability/client/cost_reports.rb +33 -0
- data/lib/cloudability/client/credentials.rb +15 -0
- data/lib/cloudability/client/organizations.rb +76 -0
- data/lib/cloudability/client/usage_reports.rb +33 -0
- data/lib/cloudability/version.rb +1 -1
- data/spec/cloduability/billing_spec.rb +16 -34
- data/spec/cloduability/budgets_spec.rb +14 -49
- data/spec/cloduability/cost_spec.rb +79 -0
- data/spec/cloduability/credentials_spec.rb +6 -15
- data/spec/cloduability/organizations_spec.rb +41 -22
- data/spec/cloduability/usage_spec.rb +44 -0
- data/spec/fixtures/billing_reports +18 -0
- data/spec/fixtures/budgets +18 -0
- data/spec/fixtures/{report_by_period → cost/filters} +7 -7
- data/spec/fixtures/cost/measures +18 -0
- data/spec/fixtures/cost/report +16 -0
- data/spec/fixtures/cost/reports +18 -0
- data/spec/fixtures/usage/filters +18 -0
- data/spec/fixtures/usage/measures +18 -0
- data/spec/fixtures/usage/reports +18 -0
- data/spec/spec_helper.rb +3 -1
- metadata +44 -13
- data/lib/cloudability/billing.rb +0 -65
- data/lib/cloudability/budgets.rb +0 -61
- data/lib/cloudability/credentials.rb +0 -34
- data/lib/cloudability/organizations.rb +0 -71
- data/lib/cloudability/time_helper.rb +0 -25
- data/spec/fixtures/all_budgets +0 -18
- data/spec/fixtures/report_by_account +0 -18
@@ -0,0 +1,18 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx/1.4.4
|
3
|
+
Date: Thu, 26 Dec 2013 07:58:43 GMT
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 17437
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
Strict-Transport-Security: max-age=31536000
|
9
|
+
Set-Cookie: _mkra_ctxt=38a29ac591a907a6ea6462573e6309c4--200; path=/; secure
|
10
|
+
X-UA-Compatible: IE=Edge,chrome=1
|
11
|
+
ETag: "ea20a4170651ebda67ae994220b6c558"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: 95e301a456925e1ff3b97bf0cb673bde
|
14
|
+
X-Runtime: 0.663877
|
15
|
+
X-Rack-Cache: miss
|
16
|
+
Origin: app.cloudability.com
|
17
|
+
|
18
|
+
[{"id":1,"category":"Invoice Costs","title":"Account","description":null,"end_date":"today","start_date":"last week","end_date_is_relative":true,"start_date_is_relative":true,"owned_by_user":false,"shared":false,"custom":false,"metrics":[{"type":"metric","name":"invoiced_cost","label":"Total Invoiced Costs","description":"Total cost including taxes and credits","data_type":"currency","group":{"key":"billing","name":"Billing"},"sub_group":{"key":"costs","name":"Costs"}}],"dimensions":[{"type":"dimension","name":"linked_account_name","label":"Linked Account Name","description":"The account name for a linked account in consolidated billing","data_type":"string","group":{"key":"billing","name":"Billing"},"sub_group":{"key":"vendor","name":"Vendor"}}],"filters":[],"report_dimension_links":[]},{"id":2,"category":"Top Products","title":"All Products","description":null,"end_date":"today","start_date":"last week","end_date_is_relative":true,"start_date_is_relative":true,"owned_by_user":false,"shared":false,"custom":false,"metrics":[{"type":"metric","name":"invoiced_cost","label":"Total Invoiced Costs","description":"Total cost including taxes and credits","data_type":"currency","group":{"key":"billing","name":"Billing"},"sub_group":{"key":"costs","name":"Costs"}}],"dimensions":[{"type":"dimension","name":"service_key","label":"Product Code","description":"Shortened name of the product","data_type":"string","group":{"key":"billing","name":"Billing"},"sub_group":{"key":"vendor","name":"Vendor"}}],"filters":[],"report_dimension_links":[]}]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx/1.4.4
|
3
|
+
Date: Thu, 26 Dec 2013 18:23:36 GMT
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 39
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
Strict-Transport-Security: max-age=31536000
|
9
|
+
Set-Cookie: _mkra_ctxt=4b25dd0859fe4bffe0cff2b14c615917--200; path=/; secure
|
10
|
+
X-UA-Compatible: IE=Edge,chrome=1
|
11
|
+
ETag: "8762e8222fbc8f34a7359e143314adab"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: c7062d59dc778b533dc4e0cfd94a9431
|
14
|
+
X-Runtime: 0.010188
|
15
|
+
X-Rack-Cache: miss
|
16
|
+
Origin: app.cloudability.com
|
17
|
+
|
18
|
+
["==","!=","<=",">=","<",">","=@","=~"]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx/1.4.4
|
3
|
+
Date: Thu, 26 Dec 2013 18:21:53 GMT
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 15116
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
Strict-Transport-Security: max-age=31536000
|
9
|
+
Set-Cookie: _mkra_ctxt=de570b8bd77b09a8585e532d37847226--200; path=/; secure
|
10
|
+
X-UA-Compatible: IE=Edge,chrome=1
|
11
|
+
ETag: "c96f24bb9f20de7fcca0972b52aa64f9"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: 656a6fc360cb046750819e6fc2cc1028
|
14
|
+
X-Runtime: 0.044087
|
15
|
+
X-Rack-Cache: miss
|
16
|
+
Origin: app.cloudability.com
|
17
|
+
|
18
|
+
[{"type":"metric","name":"estimated_cost","label":"Estimated Cost","description":"Estimated based on usage hours multiplied by on-demand pricing","data_type":"currency","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"billing","name":"Billing"}},{"type":"metric","name":"avg_estimated_cost","label":"Avg Estimated Cost","description":"Average estimated cost","data_type":"currency","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"billing","name":"Billing"}},{"type":"metric","name":"avg_estimated_hourly_cost","label":"Avg Estimated Hourly Instance Cost","description":"Average estimated hourly cost","data_type":"currency","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"billing","name":"Billing"}},{"type":"metric","name":"num_attached_storage","label":"Storage Devices","description":"Number of attached storage devices","data_type":"integer","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}},{"type":"metric","name":"inbound_bandwidth","label":"Bandwidth In","description":"The number of bytes inbound on the network","data_type":"bytes","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}}]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx/1.4.4
|
3
|
+
Date: Fri, 27 Dec 2013 05:31:15 GMT
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 44476
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
Strict-Transport-Security: max-age=31536000
|
9
|
+
Set-Cookie: _mkra_ctxt=1f0f9e994c1eda7c8aaca1c638e169e7--200; path=/; secure
|
10
|
+
X-UA-Compatible: IE=Edge,chrome=1
|
11
|
+
ETag: "575c428e918fe64a860eaf6e6cc8ba2e"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: 9534fd1ae2484ed36a74011e9f5816e4
|
14
|
+
X-Runtime: 1.713328
|
15
|
+
X-Rack-Cache: miss
|
16
|
+
Origin: app.cloudability.com
|
17
|
+
|
18
|
+
[{"id":2,"category":"Utilization","title":"Longest Running","description":null,"end_date":"today","start_date":"last week","end_date_is_relative":true,"start_date_is_relative":true,"owned_by_user":false,"shared":false,"custom":false,"metrics":[{"type":"metric","name":"hours_since_launch","label":"Hours Since Launch","description":"Hours since instance launch","data_type":"float","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"time","name":"Time"}},{"type":"metric","name":"utilization_hours","label":"Utilization Hours","description":"Utilization hours","data_type":"integer","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}},{"type":"metric","name":"avg_estimated_hourly_cost","label":"Avg Estimated Hourly Instance Cost","description":"Average estimated hourly cost","data_type":"currency","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"billing","name":"Billing"}}],"dimensions":[{"type":"dimension","name":"instance_identifier","label":"Instance ID","description":"Instance ID","data_type":"string","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"common","name":"Common"}},{"type":"dimension","name":"instance_size","label":"Size","description":"Size of the Instance","data_type":"string","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"common","name":"Common"}}],"filters":[],"report_dimension_links":[]},{"id":3,"category":"Utilization","title":"Instance Aging","description":null,"end_date":"today","start_date":"last week","end_date_is_relative":true,"start_date_is_relative":true,"owned_by_user":false,"shared":false,"custom":false,"metrics":[{"type":"metric","name":"terminated_instances","label":"Terminated Instances","description":"Number of terminated instances","data_type":"integer","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}},{"type":"metric","name":"running_instances","label":"Running Instances","description":"Number of running instances","data_type":"integer","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}}],"dimensions":[{"type":"dimension","name":"days_since_launch","label":"Days Alive","description":"Days since instance was launched","data_type":"integer","group":{"key":"compute","name":"Compute"},"sub_group":{"key":"usage","name":"Usage"}}],"filters":[],"report_dimension_links":[]}]
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
2
4
|
require 'bundler'
|
3
5
|
require 'fakeweb'
|
4
6
|
require 'cloudability'
|
@@ -33,7 +35,6 @@ module FakeRequestHelpers
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
38
|
RSpec.configure do |c|
|
38
39
|
c.include(FakeRequestHelpers)
|
39
40
|
|
@@ -43,6 +44,7 @@ RSpec.configure do |c|
|
|
43
44
|
end
|
44
45
|
|
45
46
|
FakeWeb.allow_net_connect = false
|
47
|
+
FakeWeb.allow_net_connect = %r[^https?://coveralls.io/api/v1/jobs]
|
46
48
|
|
47
49
|
# Creating fixtures:
|
48
50
|
# curl -is https://app.cloudability.com/api/0/billing_reports?auth_token=token&by=account > spec/fixtures/billing_report
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colby Aley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ~>
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.6'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: coveralls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Ruby wrapper for the Cloudability API
|
85
99
|
email:
|
86
100
|
- colby@cloudability.com
|
@@ -97,24 +111,33 @@ files:
|
|
97
111
|
- Rakefile
|
98
112
|
- cloudability.gemspec
|
99
113
|
- lib/cloudability.rb
|
100
|
-
- lib/cloudability/
|
101
|
-
- lib/cloudability/budgets.rb
|
102
|
-
- lib/cloudability/
|
103
|
-
- lib/cloudability/
|
104
|
-
- lib/cloudability/
|
114
|
+
- lib/cloudability/client/billing_reports.rb
|
115
|
+
- lib/cloudability/client/budgets.rb
|
116
|
+
- lib/cloudability/client/cost_reports.rb
|
117
|
+
- lib/cloudability/client/credentials.rb
|
118
|
+
- lib/cloudability/client/organizations.rb
|
119
|
+
- lib/cloudability/client/usage_reports.rb
|
105
120
|
- lib/cloudability/version.rb
|
106
121
|
- spec/cloduability/billing_spec.rb
|
107
122
|
- spec/cloduability/budgets_spec.rb
|
123
|
+
- spec/cloduability/cost_spec.rb
|
108
124
|
- spec/cloduability/credentials_spec.rb
|
109
125
|
- spec/cloduability/organizations_spec.rb
|
110
|
-
- spec/
|
126
|
+
- spec/cloduability/usage_spec.rb
|
127
|
+
- spec/fixtures/billing_reports
|
128
|
+
- spec/fixtures/budgets
|
129
|
+
- spec/fixtures/cost/filters
|
130
|
+
- spec/fixtures/cost/measures
|
131
|
+
- spec/fixtures/cost/report
|
132
|
+
- spec/fixtures/cost/reports
|
111
133
|
- spec/fixtures/credentials
|
112
134
|
- spec/fixtures/organization
|
113
135
|
- spec/fixtures/organization_invitation
|
114
136
|
- spec/fixtures/organization_invitations
|
115
137
|
- spec/fixtures/organization_roles
|
116
|
-
- spec/fixtures/
|
117
|
-
- spec/fixtures/
|
138
|
+
- spec/fixtures/usage/filters
|
139
|
+
- spec/fixtures/usage/measures
|
140
|
+
- spec/fixtures/usage/reports
|
118
141
|
- spec/spec_helper.rb
|
119
142
|
homepage: https://github.com/colbyaley/cloudability
|
120
143
|
licenses:
|
@@ -143,14 +166,22 @@ summary: Ruby wrapper for the Cloudability API built with HTTParty
|
|
143
166
|
test_files:
|
144
167
|
- spec/cloduability/billing_spec.rb
|
145
168
|
- spec/cloduability/budgets_spec.rb
|
169
|
+
- spec/cloduability/cost_spec.rb
|
146
170
|
- spec/cloduability/credentials_spec.rb
|
147
171
|
- spec/cloduability/organizations_spec.rb
|
148
|
-
- spec/
|
172
|
+
- spec/cloduability/usage_spec.rb
|
173
|
+
- spec/fixtures/billing_reports
|
174
|
+
- spec/fixtures/budgets
|
175
|
+
- spec/fixtures/cost/filters
|
176
|
+
- spec/fixtures/cost/measures
|
177
|
+
- spec/fixtures/cost/report
|
178
|
+
- spec/fixtures/cost/reports
|
149
179
|
- spec/fixtures/credentials
|
150
180
|
- spec/fixtures/organization
|
151
181
|
- spec/fixtures/organization_invitation
|
152
182
|
- spec/fixtures/organization_invitations
|
153
183
|
- spec/fixtures/organization_roles
|
154
|
-
- spec/fixtures/
|
155
|
-
- spec/fixtures/
|
184
|
+
- spec/fixtures/usage/filters
|
185
|
+
- spec/fixtures/usage/measures
|
186
|
+
- spec/fixtures/usage/reports
|
156
187
|
- spec/spec_helper.rb
|
data/lib/cloudability/billing.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Cloudability
|
2
|
-
class Billing
|
3
|
-
include HTTParty
|
4
|
-
base_uri "https://app.cloudability.com/api/0"
|
5
|
-
format :json
|
6
|
-
|
7
|
-
attr_accessor :auth_token
|
8
|
-
|
9
|
-
def initialize(options={})
|
10
|
-
raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?
|
11
|
-
|
12
|
-
@auth_token = options[:auth_token]
|
13
|
-
@params=[]
|
14
|
-
end
|
15
|
-
|
16
|
-
# Define which dimension the billing report will return.
|
17
|
-
#
|
18
|
-
# @param [Symbol] dimension to report on.
|
19
|
-
# @return [Array] array of Hashie::Mashes
|
20
|
-
def report_by(dimension)
|
21
|
-
case dimension
|
22
|
-
when :account
|
23
|
-
@params << "&by=account"
|
24
|
-
when :credential
|
25
|
-
@params << "&by=credential"
|
26
|
-
when :period
|
27
|
-
@params << "&by=period"
|
28
|
-
when :service
|
29
|
-
@params << "&by=service"
|
30
|
-
when :vendor
|
31
|
-
@params << "&by=vendor"
|
32
|
-
else
|
33
|
-
raise ArgumentError, "You must provide a valid dimension to report on."
|
34
|
-
end
|
35
|
-
|
36
|
-
billings = get_url(@params)
|
37
|
-
billings.map { |b| Hashie::Mash.new(b) }
|
38
|
-
end
|
39
|
-
|
40
|
-
# Find a particular period, based on its month.
|
41
|
-
# Period must be in YY-MM-01 format with the date always 01.
|
42
|
-
def filter_by_period(period)
|
43
|
-
unless period =~ /^[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/
|
44
|
-
raise ArgumentError, "You must provide a valid date in the form of 'YY-MM-DD'."
|
45
|
-
end
|
46
|
-
|
47
|
-
@params << "&period=#{period}"
|
48
|
-
single_billing = get_url(@params).first
|
49
|
-
|
50
|
-
Hashie::Mash.new(single_billing)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# GET a URL with HTTParty
|
56
|
-
#
|
57
|
-
# @param [Array] array of URL params to pass to HTTParty
|
58
|
-
def get_url(params)
|
59
|
-
joined_param = params.join
|
60
|
-
response = self.class.get("/billing_reports?auth_token=#{@auth_token}#{joined_param}")
|
61
|
-
response.success? ? response : raise(response.response)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
data/lib/cloudability/budgets.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
module Cloudability
|
2
|
-
class Budgets
|
3
|
-
include HTTParty
|
4
|
-
base_uri "https://app.cloudability.com/api/1"
|
5
|
-
format :json
|
6
|
-
|
7
|
-
attr_accessor :auth_token
|
8
|
-
|
9
|
-
def initialize(options={})
|
10
|
-
raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?
|
11
|
-
@auth_token = options[:auth_token]
|
12
|
-
end
|
13
|
-
|
14
|
-
# Return all the budgets for the current account, and return as mash's.
|
15
|
-
def find_all
|
16
|
-
convert_to_mashes(get_budgets)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Find a particular budget, based on its id, and return a mash.
|
20
|
-
def find_by_id(id)
|
21
|
-
find_all.select {|b| b.id == id}.first
|
22
|
-
end
|
23
|
-
|
24
|
-
# Find a particular budget, based on its subject, and return a mash.
|
25
|
-
def find_by_subject(subject)
|
26
|
-
unless subject.length == 14
|
27
|
-
raise ArgumentError, "You must provide a valid subject such as 1234-5678-9101."
|
28
|
-
end
|
29
|
-
|
30
|
-
find_all.select {|b| b.subject == subject}.first
|
31
|
-
end
|
32
|
-
|
33
|
-
# Find a particular budget, based on a key, and return a mash.
|
34
|
-
def find_by_key(options={})
|
35
|
-
case options[:key]
|
36
|
-
when :id
|
37
|
-
budget = find_by_id(options[:value])
|
38
|
-
when :subject
|
39
|
-
budget = find_by_subject(options[:value])
|
40
|
-
else
|
41
|
-
raise ArgumentError, "You must provide a valid key."
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def get_budgets
|
48
|
-
response = self.class.get("/budgets/index?auth_token=#{@auth_token}")
|
49
|
-
response.success? ? response : raise(response.response)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Convert the JSON into an Array of Mashes.
|
53
|
-
#
|
54
|
-
# @param [String] JSON array
|
55
|
-
# @return [Array] array of Hashie::Mashes
|
56
|
-
def convert_to_mashes(response)
|
57
|
-
response.map { |budget| Hashie::Mash.new(budget) }
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Cloudability
|
2
|
-
class Credentials
|
3
|
-
include HTTParty
|
4
|
-
base_uri "https://app.cloudability.com/api/0"
|
5
|
-
format :json
|
6
|
-
|
7
|
-
attr_accessor :auth_token
|
8
|
-
|
9
|
-
def initialize(options={})
|
10
|
-
raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?
|
11
|
-
@auth_token = options[:auth_token]
|
12
|
-
end
|
13
|
-
|
14
|
-
def find_all
|
15
|
-
convert_to_mashes(get_credentials)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def get_credentials
|
21
|
-
response = self.class.get("/credentials/index?auth_token=#{@auth_token}")
|
22
|
-
response.success? ? response : raise(response.response)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Convert the JSON into an Array of Mashes.
|
26
|
-
#
|
27
|
-
# @param [String] JSON array
|
28
|
-
# @return [Array] array of Hashie::Mashes
|
29
|
-
def convert_to_mashes(response)
|
30
|
-
response.map { |credential| Hashie::Mash.new(credential) }
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module Cloudability
|
2
|
-
class Organizations
|
3
|
-
include HTTParty
|
4
|
-
base_uri "https://app.cloudability.com/api/1"
|
5
|
-
format :json
|
6
|
-
|
7
|
-
attr_accessor :auth_token
|
8
|
-
|
9
|
-
def initialize(options={})
|
10
|
-
raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?
|
11
|
-
|
12
|
-
@auth_token = options[:auth_token]
|
13
|
-
end
|
14
|
-
|
15
|
-
def my_organization
|
16
|
-
response = get_url("/organizations?auth_token=#{@auth_token}")
|
17
|
-
Hashie::Mash.new(response)
|
18
|
-
end
|
19
|
-
|
20
|
-
def invitations
|
21
|
-
response = get_url("/organizations/invitations?auth_token=#{@auth_token}")
|
22
|
-
convert_to_mashes(response)
|
23
|
-
end
|
24
|
-
|
25
|
-
def roles
|
26
|
-
response = get_url("/organizations/roles?auth_token=#{@auth_token}")
|
27
|
-
convert_to_mashes(response)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Invite a user to your organization
|
31
|
-
#
|
32
|
-
# @param [Hash] args to pass to HTTParty
|
33
|
-
# @option [String] email (required)
|
34
|
-
# @option [String] name
|
35
|
-
# @option [String] role_id
|
36
|
-
def invite_user(args)
|
37
|
-
raise ArgumentError, "You must provide an email" if args[:email].nil?
|
38
|
-
|
39
|
-
response = post_url("/organizations/invitations?auth_token=#{@auth_token}", args)
|
40
|
-
Hashie::Mash.new(response)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
# POST a URL with HTTParty
|
46
|
-
#
|
47
|
-
# @param [String] URL to post
|
48
|
-
# @param [Hash] params to pass to HTTParty
|
49
|
-
def post_url(url, params={})
|
50
|
-
response = self.class.post(url, query: params)
|
51
|
-
response.success? ? response : raise(response.response)
|
52
|
-
end
|
53
|
-
|
54
|
-
# GET a URL with HTTParty
|
55
|
-
#
|
56
|
-
# @param [String] URL to get
|
57
|
-
def get_url(url)
|
58
|
-
response = self.class.get(url)
|
59
|
-
response.success? ? response : raise(response.response)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Convert the JSON into an Array of Mashes.
|
63
|
-
#
|
64
|
-
# @param [String] JSON array
|
65
|
-
# @return [Array] array of Hashie::Mashes
|
66
|
-
def convert_to_mashes(response)
|
67
|
-
response.map { |budget| Hashie::Mash.new(budget) }
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
require 'hashie'
|
3
|
-
|
4
|
-
# Cloudability requires time periods formatted in YYYY-MM-01 The date must always be 1.
|
5
|
-
# This provides a set of helpers to always return the correct period format.
|
6
|
-
|
7
|
-
class TimeHelper
|
8
|
-
|
9
|
-
def last_three_months
|
10
|
-
dt = DateTime.now
|
11
|
-
|
12
|
-
current_month = dt.strftime("%Y-%m-01")
|
13
|
-
last_month = (dt << 1).strftime("%Y-%m-01")
|
14
|
-
three_month = (dt << 2).strftime("%Y-%m-01")
|
15
|
-
|
16
|
-
hash = { current: current_month, last: last_month, three: three_month }
|
17
|
-
Hashie::Mash.new(hash)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Returns the current month
|
21
|
-
def current_month
|
22
|
-
DateTime.now.strftime("%Y-%m-01")
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|