Skip to content

Commit 08d8728

Browse files
committed
Moar docs, and support for inviting org members
1 parent 20efa41 commit 08d8728

8 files changed

Lines changed: 127 additions & 13 deletions

File tree

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ Feel free to shoot me an email at colby@cloudability.com if you have any questio
3030

3131
credentials = Cloudability::Credentials.new(auth_token: 'xxxxxxxxxxxxxxxxxxxx')
3232
all_credentials = credentials.find_all
33-
first_account = all_credentials.first
3433

3534
puts first_account.account_created_at
3635
puts first_account.account_identifier
3736
puts first_account.created_at
3837
puts first_account.has_auth
3938
puts first_account.has_estimate
40-
puts first_account.id
41-
puts first_account.is_duplicate
42-
puts first_account.nickname
43-
puts first_account.state
44-
puts first_account.updated_at
45-
puts first_account.vendor_id
46-
puts first_account.vendor_key
39+
40+
### Organizations
41+
42+
c = Cloudability::Organizations.new(auth_token: 'xxxxxxxxxxxxxxxxxxxx')
43+
c.invite_user(email: 'colby@cloudability.com', name: 'Colby Aley')
4744

4845
## TODO:
4946
* More tests!

lib/cloudability/billing.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def initialize(options={})
1414
end
1515

1616
# Define which dimension the billing report will return.
17+
#
18+
# @param [Symbol] dimension to report on.
19+
# @return [Array] array of Hashie::Mashes
1720
def report_by(dimension)
1821
case dimension
1922
when :account
@@ -49,6 +52,9 @@ def filter_by_period(period)
4952

5053
private
5154

55+
# GET a URL with HTTParty
56+
#
57+
# @param [Array] array of URL params to pass to HTTParty
5258
def get_url(params)
5359
joined_param = params.join
5460
response = self.class.get("/billing_reports?auth_token=#{@auth_token}#{joined_param}")

lib/cloudability/budgets.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def get_budgets
4949
response.success? ? response : raise(response.response)
5050
end
5151

52-
# Convert the json into an Array of Mashes.
52+
# Convert the JSON into an Array of Mashes.
53+
#
54+
# @param [String] JSON array
55+
# @return [Array] array of Hashie::Mashes
5356
def convert_to_mashes(response)
5457
response.map { |budget| Hashie::Mash.new(budget) }
5558
end

lib/cloudability/credentials.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def get_credentials
2222
response.success? ? response : raise(response.response)
2323
end
2424

25-
# Convert the json into an Array of Mashes.
25+
# Convert the JSON into an Array of Mashes.
26+
#
27+
# @param [String] JSON array
28+
# @return [Array] array of Hashie::Mashes
2629
def convert_to_mashes(response)
2730
response.map { |credential| Hashie::Mash.new(credential) }
2831
end

lib/cloudability/organizations.rb

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'json'
2+
13
module Cloudability
24
class Organizations
35
include HTTParty
@@ -13,15 +15,54 @@ def initialize(options={})
1315
end
1416

1517
def my_organization
16-
Hashie::Mash.new(get_my_organization)
18+
response = get_url("/organizations?auth_token=#{@auth_token}")
19+
Hashie::Mash.new(response)
20+
end
21+
22+
def invitations
23+
response = get_url("/organizations/invitations?auth_token=#{@auth_token}")
24+
convert_to_mashes(response)
25+
end
26+
27+
# Invite a user to your organization
28+
#
29+
# @param [Hash] args to pass to HTTParty
30+
# @option [String] email (required)
31+
# @option [String] name
32+
# @option [String] role_id
33+
def invite_user(args)
34+
raise ArgumentError, "You must provide an email" if args[:email].nil?
35+
36+
response = post_url("/organizations/invitations?auth_token=#{@auth_token}", args)
37+
Hashie::Mash.new(response)
1738
end
1839

1940
private
2041

21-
def get_my_organization
22-
response = self.class.get("/organizations?auth_token=#{@auth_token}")
42+
# POST a URL with HTTParty
43+
#
44+
# @param [String] URL to post
45+
# @param [Hash] params to pass to HTTParty
46+
def post_url(url, params={})
47+
response = self.class.post(url, query: params)
2348
response.success? ? response : raise(response.response)
2449
end
2550

51+
# GET a URL with HTTParty
52+
#
53+
# @param [String] URL to get
54+
def get_url(url)
55+
response = self.class.get(url)
56+
response.success? ? response : raise(response.response)
57+
end
58+
59+
# Convert the JSON into an Array of Mashes.
60+
#
61+
# @param [String] JSON array
62+
# @return [Array] array of Hashie::Mashes
63+
def convert_to_mashes(response)
64+
response.map { |budget| Hashie::Mash.new(budget) }
65+
end
66+
2667
end
2768
end

spec/cloduability/organizations_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,32 @@
2121
@cloudability.my_organization.class.should == Hashie::Mash
2222
end
2323
end
24+
25+
describe '#invitations' do
26+
it 'should be an Array' do
27+
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
28+
@cloudability.invitations.class.should == Array
29+
end
30+
31+
it 'should be an array of Hashie::Mashes' do
32+
stub_get('/1/organizations/invitations?auth_token=token', 'organization_invitations')
33+
@cloudability.invitations.each{|invite| invite.class.should == Hashie::Mash }
34+
end
35+
end
36+
37+
describe '#invite_user' do
38+
it 'should be a Hashie::Mash' do
39+
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com', 'organization_invitation')
40+
@cloudability.invite_user(email: 'colbyaleyrb@gmail.com').class.should == Hashie::Mash
41+
end
42+
43+
it 'should accept a hash with email and name' do
44+
stub_post('/1/organizations/invitations?auth_token=token&email=colbyaleyrb%40gmail.com&name=colby', 'organization_invitation')
45+
expect { @cloudability.invite_user(email: 'colbyaleyrb@gmail.com', name: 'colby') }.not_to raise_exception
46+
end
47+
48+
it 'should not accept requests without an email' do
49+
expect { @cloudability.invite_user(name: 'Colby Aley') }.to raise_exception(ArgumentError)
50+
end
51+
end
2452
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
HTTP/1.1 201 Created
2+
Server: nginx/1.4.4
3+
Date: Wed, 25 Dec 2013 05:47:18 GMT
4+
Content-Type: application/json
5+
Content-Length: 318
6+
Connection: keep-alive
7+
Status: 201 Created
8+
Strict-Transport-Security: max-age=31536000
9+
Set-Cookie: _mkra_ctxt=379f814d012ea011e3b06a9d27c08589--201; path=/; secure
10+
X-UA-Compatible: IE=Edge,chrome=1
11+
ETag: "315d11c00c3c098a8b232bdc46310b93"
12+
Cache-Control: max-age=0, private, must-revalidate
13+
X-Request-Id: eada05630363230c2942dd46f0561cf2
14+
X-Runtime: 1.487748
15+
X-Rack-Cache: invalidate, pass
16+
Origin: app.cloudability.com
17+
18+
{"id":10427,"state":"pending","user":{"id":10505,"full_name":null,"email":"colbyaleyrb@gmail.com","default_filter_set_id":null,"is_organization_admin":false,"currency":{"key":"usd","symbol":"$","symbol_first":true,"thousands_separator":",","decimal_mark":"."}},"organization_role":{"id":2,"key":"user","label":"User"}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
HTTP/1.1 200 OK
2+
Server: nginx/1.4.4
3+
Date: Wed, 25 Dec 2013 04:46:40 GMT
4+
Content-Type: application/json
5+
Content-Length: 746
6+
Connection: keep-alive
7+
Status: 200 OK
8+
Strict-Transport-Security: max-age=31536000
9+
Set-Cookie: _mkra_ctxt=53ec8b9512d2efe39fd059709c8ad35c--200; path=/; secure
10+
X-UA-Compatible: IE=Edge,chrome=1
11+
ETag: "55e062e7527926f54559b0e2ad810915"
12+
Cache-Control: max-age=0, private, must-revalidate
13+
X-Request-Id: 2f5a92d8db37da8e719265cf74866386
14+
X-Runtime: 0.151318
15+
X-Rack-Cache: miss
16+
Origin: app.cloudability.com
17+
18+
[{"id":10424,"state":"pending","user":{"id":10502,"full_name":"Cudi Aley","email":"ayycudi@aley.me","default_filter_set_id":null,"is_organization_admin":false,"currency":{"key":"usd","symbol":"$","symbol_first":true,"thousands_separator":",","decimal_mark":"."},"is_enterprise":true,"ri_az_transfer_beta":false},"organization_role":{"id":2,"key":"user","label":"User"}},{"id":1548,"state":"accepted","user":{"id":5902,"full_name":"Colby Aley","email":"colby@aley.me","default_filter_set_id":null,"is_organization_admin":true,"currency":{"key":"usd","symbol":"$","symbol_first":true,"thousands_separator":",","decimal_mark":"."},"is_enterprise":true,"ri_az_transfer_beta":false},"organization_role":{"id":1,"key":"admin","label":"Administrator"}}]

0 commit comments

Comments
 (0)