cloudability 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +9 -0
- data/cloudability.gemspec +21 -0
- data/lib/cloudability.rb +9 -0
- data/lib/cloudability/billing.rb +66 -0
- data/lib/cloudability/budgets.rb +55 -0
- data/lib/cloudability/credentials.rb +32 -0
- data/lib/cloudability/time_helper.rb +26 -0
- data/lib/cloudability/version.rb +3 -0
- data/test/fixtures/billing_report_by-vendor.json +1 -0
- data/test/fixtures/billing_report_period.json +1 -0
- data/test/fixtures/billing_report_year.json +54 -0
- data/test/fixtures/budgets.json +34 -0
- data/test/fixtures/credentials.json +28 -0
- data/test/helper.rb +22 -0
- data/test/lib/cloudability/test_billing.rb +55 -0
- data/test/lib/cloudability/test_budgets.rb +44 -0
- data/test/lib/cloudability/test_credentials.rb +21 -0
- data/test/lib/cloudability/test_time_helper.rb +24 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aaron Bento
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Cloudability
|
2
|
+
|
3
|
+
Ruby wrapper for the Cloudability API using httparty.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cloudability'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cloudability
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Covers endpoints:
|
22
|
+
* credentials
|
23
|
+
* budgets
|
24
|
+
* and partial billing_reports
|
25
|
+
|
26
|
+
|
27
|
+
### Credential Endpoint:
|
28
|
+
Caputure an array containing all your Cloud Accounts
|
29
|
+
|
30
|
+
credentials = Cloudability::Credentials.new(:auth_token => 'xxxxxxxxxxxxxxxxxxxx')
|
31
|
+
all_credentials = credentials.find_all
|
32
|
+
first_account = all_credentials.first
|
33
|
+
|
34
|
+
puts first_account.account_created_at
|
35
|
+
puts first_account.account_identifier
|
36
|
+
puts first_account.created_at
|
37
|
+
puts first_account.has_auth
|
38
|
+
puts first_account.has_estimate
|
39
|
+
puts first_account.id
|
40
|
+
puts first_account.is_duplicate
|
41
|
+
puts first_account.nickname
|
42
|
+
puts first_account.state
|
43
|
+
puts first_account.updated_at
|
44
|
+
puts first_account.vendor_id
|
45
|
+
puts first_account.vendor_key
|
46
|
+
|
47
|
+
|
48
|
+
## TODO:
|
49
|
+
* finish report by and filter by options.
|
50
|
+
* Refactor!
|
51
|
+
* More Docs!
|
52
|
+
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloudability/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cloudability"
|
8
|
+
gem.version = Cloudability::VERSION
|
9
|
+
gem.authors = ["Aaron Bento"]
|
10
|
+
gem.email = ["abento+github@gmail.com"]
|
11
|
+
gem.description = %q{Ruby wrapper for the Cloudability API}
|
12
|
+
gem.summary = %q{Ruby wrapper for the Cloudability API using httparty}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency('httparty')
|
20
|
+
gem.add_dependency('mash')
|
21
|
+
end
|
data/lib/cloudability.rb
ADDED
@@ -0,0 +1,66 @@
|
|
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
|
+
@auth_token = options[:auth_token]
|
11
|
+
@params=[]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Option #1 is a hash with parameter value
|
15
|
+
# {:param1 => "period", }
|
16
|
+
def report_by(options={})
|
17
|
+
|
18
|
+
# TODO ::
|
19
|
+
# - by= : period, vendor, service, credential, account
|
20
|
+
# https://app.cloudability.com/api/0/billing_reports?auth_token=VZSaZ65u87X2p7HqgpJv&by=vendor
|
21
|
+
# [{"vendor_id":1,"vendor_name":"Amazon","spend":"149744.69"}]
|
22
|
+
@params << "&by=account" if options == :account
|
23
|
+
@params << "&by=credential" if options == :credential
|
24
|
+
@params << "&by=period" if options == :period
|
25
|
+
@params << "&by=service" if options == :service
|
26
|
+
@params << "&by=vendor" if options == :vendor
|
27
|
+
|
28
|
+
billing = get_url(@params)
|
29
|
+
convert_to_mashes(billing)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Find a particular period, based on its month.
|
33
|
+
# Period must be in YY-MM-01 format with the date always 01.
|
34
|
+
def filter_by_period(period)
|
35
|
+
billing = get_billing_report(period)
|
36
|
+
convert_to_mash(billing)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get_billing_report(period)
|
42
|
+
response = self.class.get("/billing_reports?auth_token=#{@auth_token}&period=#{period}")
|
43
|
+
response.success? ? response : raise(response.response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_url(params)
|
47
|
+
joined_param = params.join
|
48
|
+
url = "/billing_reports?auth_token=#{@auth_token}#{joined_param}"
|
49
|
+
response = self.class.get("/billing_reports?auth_token=#{@auth_token}#{joined_param}")
|
50
|
+
response.success? ? response : raise(response.response)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Convert the json into a Mash.
|
54
|
+
def convert_to_mash(response)
|
55
|
+
mash = Mash.new(response.first)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Convert the json into an Array of Mashes.
|
59
|
+
def convert_to_mashes(response)
|
60
|
+
billings =[]
|
61
|
+
response.each { |b| billings << Mash.new(b)}
|
62
|
+
return billings
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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
|
+
@auth_token = options[:auth_token]
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return all the budgets for the current account, and return as mash's.
|
14
|
+
def find_all
|
15
|
+
convert_to_mashes(get_budgets)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Find a particular budget, based on its id, and return a mash.
|
19
|
+
def find_by_id(id)
|
20
|
+
all_budgets = find_all
|
21
|
+
budget = all_budgets.select {|r| r.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
|
+
all_budgets = find_all
|
27
|
+
budget = all_budgets.select {|r| r.subject == subject}.first
|
28
|
+
end
|
29
|
+
|
30
|
+
# Find a particular budget, based on a key, and return a mash.
|
31
|
+
def find_by_key(options={})
|
32
|
+
case options[:key]
|
33
|
+
when :id
|
34
|
+
budget = find_by_id(options[:value])
|
35
|
+
when :subject
|
36
|
+
budget = find_by_subject(options[:value])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def get_budgets
|
43
|
+
response = self.class.get("/budgets/index?auth_token=#{self.auth_token}")
|
44
|
+
response.success? ? response : raise(response.response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Convert the json into an Array of Mashes.
|
48
|
+
def convert_to_mashes(response)
|
49
|
+
budgets =[]
|
50
|
+
response.each { |b| budgets << Mash.new(b)}
|
51
|
+
return budgets
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
+
@auth_token = options[:auth_token]
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_all
|
14
|
+
convert_to_mashes(get_credentials)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_credentials
|
20
|
+
response = self.class.get("/credentials/index?auth_token=#{self.auth_token}")
|
21
|
+
response.success? ? response : raise(response.response)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Convert the json into an Array of Mashes.
|
25
|
+
def convert_to_mashes(response)
|
26
|
+
credentials = []
|
27
|
+
mashes = response.each { |c| credentials << Mash.new(c) }
|
28
|
+
return credentials
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'mash'
|
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
|
+
mash = Mash.new(hash)
|
18
|
+
return mash
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the current month
|
22
|
+
def current_month
|
23
|
+
DateTime.now.strftime("%Y-%m-01")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"vendor_id":1,"vendor_name":"Amazon","spend":"100000.99"}]
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"period":"2012-11-01","spend":"4987.99"}]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"period": "2011-11-01",
|
4
|
+
"spend": "4463.67"
|
5
|
+
},
|
6
|
+
{
|
7
|
+
"period": "2011-12-01",
|
8
|
+
"spend": "5207.81"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"period": "2012-01-01",
|
12
|
+
"spend": "6398.46"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"period": "2012-02-01",
|
16
|
+
"spend": "7645.38"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"period": "2012-03-01",
|
20
|
+
"spend": "10005.89"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"period": "2012-04-01",
|
24
|
+
"spend": "12363.48"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"period": "2012-05-01",
|
28
|
+
"spend": "13752.46"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"period": "2012-06-01",
|
32
|
+
"spend": "12618.84"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"period": "2012-07-01",
|
36
|
+
"spend": "13739.12"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"period": "2012-08-01",
|
40
|
+
"spend": "13461.66"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"period": "2012-09-01",
|
44
|
+
"spend": "12741.14"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"period": "2012-10-01",
|
48
|
+
"spend": "12729.93"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"period": "2012-11-01",
|
52
|
+
"spend": "4987.99"
|
53
|
+
}
|
54
|
+
]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"predicted_monthly_spend": {
|
4
|
+
"cents": 1000000,
|
5
|
+
"currency": {
|
6
|
+
"id": 146,
|
7
|
+
"key": "usd",
|
8
|
+
"priority": 1,
|
9
|
+
"iso_code": "USD"
|
10
|
+
}
|
11
|
+
},
|
12
|
+
"subject": "1234-5678-90A",
|
13
|
+
"type": "Account",
|
14
|
+
"id": 1234,
|
15
|
+
"is_active": true,
|
16
|
+
"threshold": "100000.0"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"predicted_monthly_spend": {
|
20
|
+
"cents": 10000000,
|
21
|
+
"currency": {
|
22
|
+
"id": 146,
|
23
|
+
"key": "usd",
|
24
|
+
"priority": 1,
|
25
|
+
"iso_code": "USD"
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"subject": "user@example.com",
|
29
|
+
"type": "User",
|
30
|
+
"id": 9999,
|
31
|
+
"is_active": true,
|
32
|
+
"threshold": "10000.0"
|
33
|
+
}
|
34
|
+
]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"has_auth": true,
|
4
|
+
"has_estimate": false,
|
5
|
+
"is_duplicate": false,
|
6
|
+
"vendor_key": "Amazon",
|
7
|
+
"id": 10001,
|
8
|
+
"vendor_id": 1,
|
9
|
+
"created_at": "2011-11-01T00:00:00Z",
|
10
|
+
"updated_at": "2012-11-01T00:00:00Z",
|
11
|
+
"nickname": "Amazon Example",
|
12
|
+
"state": "verified",
|
13
|
+
"account_identifier": "1234-5678-90A",
|
14
|
+
"account_created_at": "2011-11-01T00:00:00Z"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"has_auth": false,
|
18
|
+
"has_estimate": false,
|
19
|
+
"is_duplicate": false,
|
20
|
+
"vendor_key": "Cloudability",
|
21
|
+
"id": 10001,
|
22
|
+
"vendor_id": 122,
|
23
|
+
"created_at": "2012-11-01T00:00:00Z",
|
24
|
+
"updated_at": "2012-11-01T00:00:00Z",
|
25
|
+
"nickname": "Cloudability",
|
26
|
+
"state": "invisible"
|
27
|
+
}
|
28
|
+
]
|
data/test/helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'turn/autorun'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'fakeweb'
|
5
|
+
require 'matchy'
|
6
|
+
|
7
|
+
require_relative '../lib/cloudability'
|
8
|
+
|
9
|
+
FakeWeb.allow_net_connect = false
|
10
|
+
|
11
|
+
def fixture_file(filename)
|
12
|
+
return '' if filename == ''
|
13
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
14
|
+
File.read(file_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_get(url, filename, status=nil)
|
18
|
+
options = {:body => fixture_file(filename)}
|
19
|
+
options.merge!({:status => status}) unless status.nil?
|
20
|
+
|
21
|
+
FakeWeb.register_uri(:get, url, options)
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
class TestCloudability < Test::Unit::TestCase
|
4
|
+
context "Billing :: Hitting the Cloudability Billing API" do
|
5
|
+
setup do
|
6
|
+
@auth_token = 'xxxxxxxxxxxxxxxxxxxx'
|
7
|
+
@report = Cloudability::Billing.new(:auth_token => @auth_token)
|
8
|
+
|
9
|
+
# The billing API endpoint
|
10
|
+
@billing_uri = "https://app.cloudability.com/api/0/billing_reports?auth_token=#{@auth_token}"
|
11
|
+
@default_fixture = "billing_report_period.json"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Filter by TODO ::
|
15
|
+
# - <filter>= : vendor, service, credential, account
|
16
|
+
# - combine filters
|
17
|
+
should "return a single period Mash containing spending" do
|
18
|
+
period = "2012-11-01"
|
19
|
+
uri = "#{@billing_uri}&period=#{period}"
|
20
|
+
|
21
|
+
stub_get uri, @default_fixture
|
22
|
+
single_period = @report.filter_by_period(period)
|
23
|
+
single_period.period.should == period
|
24
|
+
single_period.spend.should == "4987.99"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Report by TODO ::
|
28
|
+
# - by= : service, credential, account
|
29
|
+
# - combine filters
|
30
|
+
|
31
|
+
should "report by period" do
|
32
|
+
uri = "#{@billing_uri}&by=period"
|
33
|
+
stub_get uri, "billing_report_year.json"
|
34
|
+
|
35
|
+
billing_report = @report.report_by(:period)
|
36
|
+
|
37
|
+
billing_report.count.should == 13
|
38
|
+
billing_report.first.period.should == "2011-11-01"
|
39
|
+
billing_report.last.period.should == "2012-11-01"
|
40
|
+
billing_report.last.spend.should == "4987.99"
|
41
|
+
end
|
42
|
+
|
43
|
+
should "report by vendor" do
|
44
|
+
uri = "#{@billing_uri}&by=vendor"
|
45
|
+
stub_get uri, "billing_report_by-vendor.json"
|
46
|
+
|
47
|
+
billing_report = @report.report_by(:vendor)
|
48
|
+
|
49
|
+
billing_report.count.should == 1
|
50
|
+
billing_report.first.vendor_name.should == "Amazon"
|
51
|
+
billing_report.last.spend.should == "100000.99"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
class TestCloudability < Test::Unit::TestCase
|
4
|
+
context "Budgets :: Hitting the Cloudability Budgets API" do
|
5
|
+
setup do
|
6
|
+
@auth_token = 'xxxxxxxxxxxxxxxxxxxx'
|
7
|
+
@budgets = Cloudability::Budgets.new(:auth_token => @auth_token)
|
8
|
+
|
9
|
+
# The budget API endpoint
|
10
|
+
@default_uri = "https://app.cloudability.com/api/1/budgets/index?auth_token=#{@auth_token}"
|
11
|
+
@default_fixture = "budgets.json"
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return all budgets in an Array of Mashes" do
|
15
|
+
stub_get @default_uri, @default_fixture
|
16
|
+
all_budgets = @budgets.find_all
|
17
|
+
all_budgets.class.should == Array
|
18
|
+
all_budgets.each { |b| b.class.should == Mash }
|
19
|
+
end
|
20
|
+
|
21
|
+
should "return a single budget Mash when calling find with an id" do
|
22
|
+
stub_get @default_uri, @default_fixture
|
23
|
+
single_budget = @budgets.find_by_id(1234)
|
24
|
+
single_budget.subject.should == "1234-5678-90A"
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return a single budget Mash when calling find with a subject" do
|
28
|
+
stub_get @default_uri, @default_fixture
|
29
|
+
single_budget = @budgets.find_by_subject("1234-5678-90A")
|
30
|
+
single_budget.id.should == 1234
|
31
|
+
end
|
32
|
+
|
33
|
+
should "return a single budget Mash when calling find with a key" do
|
34
|
+
stub_get @default_uri, @default_fixture
|
35
|
+
|
36
|
+
single_budget = @budgets.find_by_key({ :key => :id, :value => 1234 })
|
37
|
+
single_budget.subject.should == "1234-5678-90A"
|
38
|
+
|
39
|
+
single_budget = @budgets.find_by_key({ :key => :subject, :value => "1234-5678-90A" })
|
40
|
+
single_budget.id.should == 1234
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
class TestCloudability < Test::Unit::TestCase
|
4
|
+
context "Credentials :: Hitting the Cloudability Credentials API" do
|
5
|
+
setup do
|
6
|
+
@auth_token = 'xxxxxxxxxxxxxxxxxxxx'
|
7
|
+
@credentials = Cloudability::Credentials.new(:auth_token => @auth_token)
|
8
|
+
|
9
|
+
# The budget API endpoint
|
10
|
+
@default_uri = "https://app.cloudability.com/api/0/credentials/index?auth_token=#{@auth_token}"
|
11
|
+
@default_fixture = "credentials.json"
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return all credentials in an Array of Mashes" do
|
15
|
+
stub_get @default_uri, @default_fixture
|
16
|
+
all_credentials = @credentials.find_all
|
17
|
+
all_credentials.class.should == Array
|
18
|
+
all_credentials.each { |c| c.class.should == Mash }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
class TestCloudability < Test::Unit::TestCase
|
4
|
+
context "Time Helper :: When using time_helper, it" do
|
5
|
+
setup do
|
6
|
+
@mock_dt = DateTime.parse("2012-11-02T00:00:00+00:00")
|
7
|
+
@real_dt = DateTime.now
|
8
|
+
@timehelper = TimeHelper.new
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return the current month in YYYY-MM-01" do
|
12
|
+
currrent_month = DateTime.now.strftime("%Y-%m-01")
|
13
|
+
@timehelper.current_month.should == currrent_month
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return a Mash with the last three months in YYYY-MM-01" do
|
17
|
+
months = @timehelper.last_three_months
|
18
|
+
months.current.should == "2012-11-01"
|
19
|
+
months.last.should == "2012-10-01"
|
20
|
+
months.three.should == "2012-09-01"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudability
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Bento
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mash
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby wrapper for the Cloudability API
|
47
|
+
email:
|
48
|
+
- abento+github@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- cloudability.gemspec
|
59
|
+
- lib/cloudability.rb
|
60
|
+
- lib/cloudability/billing.rb
|
61
|
+
- lib/cloudability/budgets.rb
|
62
|
+
- lib/cloudability/credentials.rb
|
63
|
+
- lib/cloudability/time_helper.rb
|
64
|
+
- lib/cloudability/version.rb
|
65
|
+
- test/fixtures/billing_report_by-vendor.json
|
66
|
+
- test/fixtures/billing_report_period.json
|
67
|
+
- test/fixtures/billing_report_year.json
|
68
|
+
- test/fixtures/budgets.json
|
69
|
+
- test/fixtures/credentials.json
|
70
|
+
- test/helper.rb
|
71
|
+
- test/lib/cloudability/test_billing.rb
|
72
|
+
- test/lib/cloudability/test_budgets.rb
|
73
|
+
- test/lib/cloudability/test_credentials.rb
|
74
|
+
- test/lib/cloudability/test_time_helper.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.24
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Ruby wrapper for the Cloudability API using httparty
|
99
|
+
test_files:
|
100
|
+
- test/fixtures/billing_report_by-vendor.json
|
101
|
+
- test/fixtures/billing_report_period.json
|
102
|
+
- test/fixtures/billing_report_year.json
|
103
|
+
- test/fixtures/budgets.json
|
104
|
+
- test/fixtures/credentials.json
|
105
|
+
- test/helper.rb
|
106
|
+
- test/lib/cloudability/test_billing.rb
|
107
|
+
- test/lib/cloudability/test_budgets.rb
|
108
|
+
- test/lib/cloudability/test_credentials.rb
|
109
|
+
- test/lib/cloudability/test_time_helper.rb
|