vault_client 0.0.3 → 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.
@@ -1,15 +0,0 @@
1
- module VaultClient
2
- module ReportBuilder
3
- extend self
4
-
5
- def usage_report(account_id, from, to)
6
- dto = DataTransferObject::UsageReport.query(:account_id => account_id, :from => from, :to => to)
7
- billable_units = dto.map{|bu| BillableUnit.new(bu)}
8
- #from = Time.parse(dto["from"])
9
- #to = Time.parse(dto["to"])
10
- #total = dto["total"].to_i
11
- UsageReport.new(account_id, Time.mktime(2011,12), Time.mktime(2011,12,30), billable_units, 99)
12
- end
13
-
14
- end
15
- end
@@ -1,28 +0,0 @@
1
- module UsageReportsClient
2
- extend VaultHelper
3
- extend self
4
-
5
- def make_request(action, args)
6
- case action
7
- when :query
8
- query(args)
9
- else
10
- raise "Unkown Action"
11
- end
12
- end
13
-
14
- def query(args)
15
- assert_args!(args, :account_id, :from, :to)
16
- res = resource(args[:account_id])
17
- res.get(:from => encode_time(args[:from]), :to => encode_time(args[:to]))
18
- end
19
-
20
- def resource(account_id)
21
- url = VaultClient.url.dup
22
- url << "/accounts/#{account_id}/usage_reports"
23
- @resource ||= begin
24
- RestClient::Resource.new(url, :headers => {:accept => "application/json"})
25
- end
26
- end
27
-
28
- end
@@ -1,15 +0,0 @@
1
- require 'cgi'
2
-
3
- module VaultHelper
4
-
5
- def encode_time(time)
6
- CGI.escape(time.to_s)
7
- end
8
-
9
- def assert_args!(args, *list_of_things_that_should_be)
10
- unless list_of_things_that_should_be.all? {|key| args.include?(key)}
11
- raise(ArgumentError, "Arguments should include: [#{list_of_things_that_should_be}]. You passed: [#{args}]")
12
- end
13
- end
14
-
15
- end
@@ -1,38 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class UsageReportTest < MiniTest::Unit::TestCase
4
-
5
- def test_init_report
6
- usage_report = VaultClient::UsageReport.new(account_id, from, to, Fixtures.billable_units)
7
- assert(!usage_report.nil?, "Expected a usage report. Got nil")
8
- end
9
-
10
- def test_report_returns_from
11
- usage_report = VaultClient::UsageReport.new(account_id, from, to, Fixtures.billable_units)
12
- assert(!usage_report.from.nil?, "Expected #from to return a Time. Got nil")
13
- end
14
-
15
- def test_report_returns_to
16
- usage_report = VaultClient::UsageReport.new(account_id, from, to, Fixtures.billable_units)
17
- assert(!usage_report.to.nil?, "Expected #to to return a Time. Got nil")
18
- end
19
-
20
- def test_report_returns_billable_units
21
- usage_report = VaultClient::UsageReport.new(account_id, from, to, Fixtures.billable_units)
22
- assert(!usage_report.billable_units.nil?, "Expected #billable_units to return a collection of billable_units. Got nil")
23
- assert_equal(VaultClient::BillableUnit, usage_report.billable_units.first.class)
24
- end
25
-
26
- def account_id
27
- 1
28
- end
29
-
30
- def from
31
- Time.mktime(2000,1)
32
- end
33
-
34
- def to
35
- Time.mktime(2000,2)
36
- end
37
-
38
- end
@@ -1,42 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class ResourceOwnershipClientTest < MiniTest::Unit::TestCase
4
-
5
- def test_activate
6
- verb, uri, body = ResourceOwnershipClient.build_request(:activate, [123, 456])
7
- assert_equal(:post, verb)
8
- assert_equal("/resource_ownerships", uri)
9
- assert_equal({:hid => 123, :account_id => 456}, body)
10
- end
11
-
12
- def test_deactivate
13
- verb, uri, body = ResourceOwnershipClient.build_request(:deactivate, [123, 456])
14
- assert_equal(:put, verb)
15
- assert_equal("/resource_ownerships", uri)
16
- assert_equal({:hid => 123, :prev_account_id => 456}, body)
17
- end
18
-
19
- def test_transfer
20
- verb, uri, body = ResourceOwnershipClient.build_request(:transfer, [123, 456, 789])
21
- assert_equal(:put, verb)
22
- assert_equal("/resource_ownerships", uri)
23
- assert_equal({:hid => 123,:prev_account_id => 456, :account_id => 789}, body)
24
- end
25
-
26
- def test_query_with_account_id
27
- verb, uri = ResourceOwnershipClient.build_request(:query, :account_id => 1)
28
- assert_equal(:get, verb)
29
- assert_equal("/resource_ownerships?account_id=1", uri)
30
- end
31
-
32
- def test_query_with_hid
33
- verb, uri = ResourceOwnershipClient.build_request(:query, :hid => 1)
34
- assert_equal(:get, verb)
35
- assert_equal("/resource_ownerships?hid=1", uri)
36
- end
37
-
38
- def test_query_with_account_id_and_hid
39
- assert_raises(ArgumentError) {ResourceOwnershipClient.build_request(:query, :hid => 1, :account_id => 2)}
40
- end
41
-
42
- end