vault_client 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class BEventTest < VCTest
4
+ def test_open
5
+ our_params = {
6
+ :hid => "app123",
7
+ :entity_id => 1,
8
+ :rate_code => "RT01",
9
+ :time => Time.utc(2012,1).to_s,
10
+ :product_name => "web",
11
+ :qty => 1
12
+ }
13
+ api_resp_body = VC::HttpHelpers.enc_json(our_params)
14
+ VC.url = "http://provider:password@shushu.heroku.com"
15
+ FakeWeb.register_uri(:put, (VC.url + "/resources/app123/billable_events/1"), :body => api_resp_body)
16
+ event = VC::BEvent.open(our_params)
17
+ assert_equal(1, event["entity_id"])
18
+ end
19
+ end
20
+
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class BillableUnitTest < VCTest
4
+ def test_total
5
+ unit1 = VC::BillableUnit.new("rate" => 10, "qty" => 10)
6
+ assert_equal(100, unit1.total)
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class LineItemTest < VCTest
4
+ def test_total
5
+ unit1 = VC::BillableUnit.new("rate" => 10, "qty" => 10)
6
+ unit_group1 = VC::UnitGroup.new([unit1])
7
+ line_item = VC::LineItem.new([unit_group1])
8
+ assert_equal(100, line_item.total)
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class UnitGroupTest < VCTest
4
+ def test_total
5
+ unit1 = VC::BillableUnit.new("rate" => 10, "qty" => 10)
6
+ unit_group1 = VC::UnitGroup.new([unit1])
7
+ assert_equal(100, unit_group1.total)
8
+ end
9
+
10
+ def test_check_rates
11
+ unit1 = VC::BillableUnit.new("rate" => 10, "qty" => 10)
12
+ unit2 = VC::BillableUnit.new("rate" => 9, "qty" => 10)
13
+ unit_group1 = VC::UnitGroup.new([unit1])
14
+ unit_group2 = VC::UnitGroup.new([unit2])
15
+ assert_raises(VC::UnitGroup::InvalidUnitGroup) {VC::UnitGroup.new([unit1, unit2])}
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class LineItemPresenterTest < VCTest
4
+ def test_unit_group_total
5
+ unit1 = VC::BillableUnit.new("rate" => 1000, "qty" => 10, "product_group" => "dyno")
6
+ unit_group1 = VC::UnitGroup.new([unit1])
7
+ line_item = VC::LineItem.new([unit_group1])
8
+ lip = VC::LineItemPresenter.new(line_item)
9
+ assert_equal("100.00", lip.unit_group_total("dyno"))
10
+ end
11
+
12
+ def test_unit_group_qty
13
+ unit1 = VC::BillableUnit.new("rate" => 1000, "qty" => 10, "product_group" => "dyno")
14
+ unit2 = VC::BillableUnit.new("rate" => 1000, "qty" => 1, "product_group" => "dyno")
15
+ unit_group1 = VC::UnitGroup.new([unit1, unit2])
16
+ line_item = VC::LineItem.new([unit_group1])
17
+ lip = VC::LineItemPresenter.new(line_item)
18
+ assert_equal("11.000", lip.unit_group_qty("dyno"))
19
+ end
20
+
21
+ def test_unit_group_presenters
22
+ unit1 = VC::BillableUnit.new("product_group" => "dyno")
23
+ unit2 = VC::BillableUnit.new("product_group" => "dyno")
24
+ unit3 = VC::BillableUnit.new("product_group" => "addon")
25
+ unit_group1 = VC::UnitGroup.new([unit1, unit2])
26
+ unit_group2 = VC::UnitGroup.new([unit3])
27
+ line_item = VC::LineItem.new([unit_group1, unit_group2])
28
+ lip = VC::LineItemPresenter.new(line_item)
29
+
30
+ assert_equal(2, lip.unit_group_presenters.length)
31
+ assert_equal(1, lip.unit_group_presenters("dyno").map(&:product_group).uniq.length)
32
+ assert_equal("addon", lip.unit_group_presenters("addon").map(&:product_group).uniq.first)
33
+ end
34
+ end
35
+
36
+
@@ -1,16 +1,22 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- class ReportPresenterTest < VaultClientTest
3
+ class ReportPresenterTest < VCTest
4
+
5
+ def report
6
+ VC::Report.new.tap do |r|
7
+ r.billable_units = Fixtures.billable_units.map {|h| VC::BillableUnit.new(h)}
8
+ end
9
+ end
4
10
 
5
11
  def test_init
6
- presenter = VaultClient::ReportPresenter.new(units)
12
+ presenter = VC::ReportPresenter.new(report)
7
13
  assert(!presenter.nil?)
8
14
  end
9
15
 
10
16
  def test_returns_line_item_presenters
11
- presenter = VaultClient::ReportPresenter.new(units)
17
+ presenter = VC::ReportPresenter.new(report)
12
18
  lip = presenter.line_item_presenters
13
- assert_equal(VaultClient::LineItemPresenter, lip.first.class)
19
+ assert_equal(VC::LineItemPresenter, lip.first.class)
14
20
  end
15
21
 
16
22
  end
@@ -1,24 +1,28 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- class LineItemBuilderTest < VaultClientTest
3
+ class LineItemBuilderTest < VCTest
4
+
5
+ def units
6
+ Fixtures.billable_units.map {|h| VC::BillableUnit.new(h)}
7
+ end
4
8
 
5
9
  def test_build
6
- line_items = VaultClient::LineItemBuilder.build(units)
10
+ line_items = VC::LineItemBuilder.build(units)
7
11
  assert(!line_items.nil?)
8
12
  end
9
13
 
10
14
  def test_build_creates_line_item_by_hid
11
- line_items = VaultClient::LineItemBuilder.build(units)
15
+ line_items = VC::LineItemBuilder.build(units)
12
16
  assert_equal(1, line_items.length)
13
17
  end
14
18
 
15
19
  def test_build_creates_one_unit_group_for_line_item
16
- line_item = VaultClient::LineItemBuilder.build(units).pop
20
+ line_item = VC::LineItemBuilder.build(units).pop
17
21
  assert_equal(1, line_item.unit_groups.length)
18
22
  end
19
23
 
20
24
  def test_build_puts_both_units_on_unit_group
21
- line_item = VaultClient::LineItemBuilder.build(units).pop
25
+ line_item = VC::LineItemBuilder.build(units).pop
22
26
  unit_group = line_item.unit_groups.pop
23
27
  assert_equal(2, unit_group.units.length)
24
28
  end
@@ -8,14 +8,12 @@ require "bundler"
8
8
  Bundler.require(:default, :test)
9
9
 
10
10
  require "minitest/autorun"
11
- require "webmock/minitest"
12
11
  require "vault_client"
12
+ require 'fakeweb'
13
13
  require "fixtures"
14
14
 
15
- class VaultClientTest < MiniTest::Unit::TestCase
16
-
17
- def units
18
- Fixtures.billable_units.map{|h| VaultClient::BillableUnit.new(h)}
19
- end
15
+ puts "Blocking network connectivity"
16
+ FakeWeb.allow_net_connect = false
20
17
 
18
+ class VCTest < MiniTest::Unit::TestCase
21
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000Z
12
+ date: 2011-12-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &14169520 !ruby/object:Gem::Requirement
16
+ requirement: &10827140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *14169520
24
+ version_requirements: *10827140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &14166100 !ruby/object:Gem::Requirement
27
+ requirement: &10826660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *14166100
35
+ version_requirements: *10826660
36
36
  description: A ruby wrapper around The Vault's HTTP API.
37
37
  email: ryan@heroku.com
38
38
  executables: []
@@ -40,31 +40,32 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
  files:
42
42
  - readme.md
43
- - lib/dto/billable_event.rb
44
- - lib/dto/usage_report.rb
45
43
  - lib/presenters/base_presenter.rb
46
44
  - lib/presenters/unit_presenter.rb
47
45
  - lib/presenters/unit_group_presenter.rb
48
46
  - lib/presenters/report_presenter.rb
49
47
  - lib/presenters/line_item_presenter.rb
50
- - lib/usage_reports_client.rb
51
48
  - lib/vault_client.rb
49
+ - lib/models/account.rb
50
+ - lib/models/acct_own.rb
51
+ - lib/models/report.rb
52
52
  - lib/models/unit_group.rb
53
53
  - lib/models/line_item.rb
54
- - lib/models/usage_report.rb
54
+ - lib/models/res_own.rb
55
+ - lib/models/b_event.rb
55
56
  - lib/models/billable_unit.rb
56
- - lib/billable_events_client.rb
57
- - lib/vault_helper.rb
57
+ - lib/helpers/http_helpers.rb
58
58
  - lib/services/line_item_builder.rb
59
- - lib/services/report_builder.rb
60
- - lib/resource_ownership_client.rb
59
+ - test/presenters/line_item_presenter_test.rb
61
60
  - test/presenters/report_presenter_test.rb
62
61
  - test/fixtures.rb
63
- - test/models/usage_report_test.rb
64
- - test/resource_ownership_client_test.rb
62
+ - test/models/billable_unit_test.rb
63
+ - test/models/b_event_test.rb
64
+ - test/models/unit_group_test.rb
65
+ - test/models/line_item_test.rb
65
66
  - test/services/line_item_builder_test.rb
66
67
  - test/test_helper.rb
67
- homepage: http://github.com/heroku/vault_client
68
+ homepage: http://github.com/heroku/vc
68
69
  licenses: []
69
70
  post_install_message:
70
71
  rdoc_options: []
@@ -87,9 +88,12 @@ rubyforge_project:
87
88
  rubygems_version: 1.8.10
88
89
  signing_key:
89
90
  specification_version: 3
90
- summary: The Vault
91
+ summary: The Vault Client
91
92
  test_files:
93
+ - test/presenters/line_item_presenter_test.rb
92
94
  - test/presenters/report_presenter_test.rb
93
- - test/models/usage_report_test.rb
94
- - test/resource_ownership_client_test.rb
95
+ - test/models/billable_unit_test.rb
96
+ - test/models/b_event_test.rb
97
+ - test/models/unit_group_test.rb
98
+ - test/models/line_item_test.rb
95
99
  - test/services/line_item_builder_test.rb
@@ -1,45 +0,0 @@
1
- module BillableEventsClient
2
- extend self
3
- extend VaultHelper
4
-
5
- Open = "open"
6
- Close = "close"
7
-
8
- def make_request(action, args)
9
- case action
10
- when :open
11
- open(args)
12
- when :close
13
- close(args)
14
- end
15
- end
16
-
17
- def open(args)
18
- assert_args!(args, :hid, :event_id, :qty, :time, :rate_code)
19
- res = resource(args[:hid], args[:event_id])
20
- res.put(
21
- :qty => args[:qty],
22
- :time => encode_time(args[:time]),
23
- :state => Open,
24
- :rate_code => args[:rate_code],
25
- :product_name => args[:product_name]
26
- )
27
- end
28
-
29
- def close(args)
30
- assert_args!(args, :hid, :event_id, :time, :rate_code)
31
- res = resource(args[:hid], args[:event_id])
32
- res.put(
33
- :time => encode_time(args[:time]),
34
- :state => Close,
35
- :rate_code => args[:rate_code]
36
- )
37
- end
38
-
39
- def resource(hid, event_id)
40
- url = VaultClient.url
41
- url += "/resources/#{hid}/billable_events/#{event_id}"
42
- RestClient::Resource.new(url, :headers => {:accept => "application/json"})
43
- end
44
-
45
- end
File without changes
@@ -1,35 +0,0 @@
1
- require 'yajl/http_stream'
2
- module VaultClient
3
- module DataTransferObject
4
- module UsageReport
5
- extend VaultHelper
6
- extend self
7
-
8
- def make_request(action, args)
9
- case action
10
- when :query
11
- query(args)
12
- else
13
- raise "Unkown Action"
14
- end
15
- end
16
-
17
- def query(args)
18
- assert_args!(args, :account_id, :from, :to)
19
- #res = resource(args[:account_id])
20
- #Yajl::Parser.parse(res.get(:params => {:from => encode_time(args[:from]), :to => encode_time(args[:to])}))
21
- data = []
22
- uri = URI.parse([VaultClient.url, "/accounts/#{args[:account_id]}/usage_reports?from=#{args[:from]}&to=#{args[:to]}"].join)
23
- Yajl::HttpStream.get(uri) {|c| data << c}
24
- data
25
- end
26
-
27
- def resource(account_id)
28
- url = VaultClient.url.dup
29
- url << "/accounts/#{account_id}/usage_reports"
30
- RestClient::Resource.new(url, :headers => {:accept => "application/json"})
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,21 +0,0 @@
1
- module VaultClient
2
- class UsageReport
3
-
4
- attr_accessor(
5
- :account_id,
6
- :from,
7
- :to,
8
- :billable_units,
9
- :total
10
- )
11
-
12
- def initialize(account_id, from, to, billable_units, total)
13
- @account_id = from
14
- @from = from
15
- @to = to
16
- @billable_units = billable_units
17
- @total = total
18
- end
19
-
20
- end
21
- end
@@ -1,55 +0,0 @@
1
- module ResourceOwnershipClient
2
- extend self
3
- extend VaultHelper
4
-
5
- def make_request(action, args)
6
- case action
7
- when :activate
8
- activate(args)
9
- when :transfer
10
- transfer(args)
11
- when :deactivate
12
- deactivate(args)
13
- when :query
14
- query(args)
15
- else
16
- raise(ArgumentError, "Resource Ownership API does not respond to #{action}")
17
- end
18
- end
19
-
20
- def activate(args)
21
- assert_args!(args, :account_id, :event_id, :hid, :time)
22
- res = resource(args[:account_id], args[:event_id])
23
- res.post(:hid => args[:hid], :time => encode_time(args[:time]))
24
- end
25
-
26
- def transfer(args)
27
- assert_args!(args, :account_id, :prev_account_id, :event_id, :prev_event_id, :hid, :time)
28
- res = resource(args[:prev_account_id], args[:prev_event_id])
29
- res.put(:account_id => args[:account_id], :event_id => args[:event_id], :hid => args[:hid], :time => encode_time(args[:time]))
30
- end
31
-
32
- def deactivate(args)
33
- assert_args!(args, :account_id, :event_id, :hid, :time)
34
- res = resource(args[:account_id])["#{args[:event_id]}?hid=#{args[:hid]}&time=#{encode_time(args[:time])}"]
35
- res.delete
36
- end
37
-
38
- def query(args)
39
- assert_args!(args, :account_id)
40
- res = resource(args[:account_id])
41
- res.get
42
- end
43
-
44
- def resource(account_id, event_id=nil)
45
- url = VaultClient.url.dup
46
- url << "/accounts/#{account_id}/resource_ownerships"
47
- if event_id
48
- url << "/#{event_id}"
49
- end
50
- @resource ||= begin
51
- RestClient::Resource.new(url, :headers => {:accept => "application/json"})
52
- end
53
- end
54
-
55
- end