shushu 0.1.16 → 1.0.0rc1

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.
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shushu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
5
- prerelease:
4
+ version: 1.0.0rc1
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Smith
@@ -44,43 +44,24 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: 1.1.0
46
46
  description: A ruby wrapper around Shushu's HTTP API.
47
- email: ryan@heroku.com
47
+ email: ryan@heroku.com, christopher.continanza@gmail.com
48
48
  executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
52
  - readme.md
53
53
  - lib/helpers/http_helpers.rb
54
- - lib/models/account.rb
55
- - lib/models/acct_own.rb
56
- - lib/models/b_event.rb
57
- - lib/models/billable_unit.rb
54
+ - lib/models/billable_event.rb
58
55
  - lib/models/heart_beat.rb
59
- - lib/models/line_item.rb
60
- - lib/models/p_method.rb
61
- - lib/models/r_code.rb
56
+ - lib/models/rate_code.rb
62
57
  - lib/models/report.rb
63
- - lib/models/res_own.rb
64
- - lib/models/rev_rep.rb
65
- - lib/models/unit_group.rb
66
- - lib/presenters/base_presenter.rb
67
- - lib/presenters/line_item_presenter.rb
68
- - lib/presenters/report_presenter.rb
69
- - lib/presenters/unit_group_presenter.rb
70
- - lib/presenters/unit_presenter.rb
71
- - lib/services/line_item_builder.rb
58
+ - lib/models/resource_ownership.rb
72
59
  - lib/shushu.rb
60
+ - lib/totalable.rb
73
61
  - test/fixtures.rb
74
- - test/models/b_event_test.rb
75
- - test/models/billable_unit_test.rb
76
- - test/models/line_item_test.rb
77
- - test/models/p_method_test.rb
78
- - test/models/r_code_test.rb
79
- - test/models/rev_rep_test.rb
80
- - test/models/unit_group_test.rb
81
- - test/presenters/line_item_presenter_test.rb
82
- - test/presenters/report_presenter_test.rb
83
- - test/services/line_item_builder_test.rb
62
+ - test/models/billable_event_test.rb
63
+ - test/models/rate_code_test.rb
64
+ - test/reports_test.rb
84
65
  - test/test_helper.rb
85
66
  homepage: http://github.com/heroku/shushu
86
67
  licenses: []
@@ -97,9 +78,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
78
  required_rubygems_version: !ruby/object:Gem::Requirement
98
79
  none: false
99
80
  requirements:
100
- - - ! '>='
81
+ - - ! '>'
101
82
  - !ruby/object:Gem::Version
102
- version: '0'
83
+ version: 1.3.1
103
84
  requirements: []
104
85
  rubyforge_project:
105
86
  rubygems_version: 1.8.23
@@ -107,13 +88,6 @@ signing_key:
107
88
  specification_version: 3
108
89
  summary: Shushu client lib
109
90
  test_files:
110
- - test/models/b_event_test.rb
111
- - test/models/billable_unit_test.rb
112
- - test/models/line_item_test.rb
113
- - test/models/p_method_test.rb
114
- - test/models/r_code_test.rb
115
- - test/models/rev_rep_test.rb
116
- - test/models/unit_group_test.rb
117
- - test/presenters/line_item_presenter_test.rb
118
- - test/presenters/report_presenter_test.rb
119
- - test/services/line_item_builder_test.rb
91
+ - test/models/billable_event_test.rb
92
+ - test/models/rate_code_test.rb
93
+ - test/reports_test.rb
@@ -1,13 +0,0 @@
1
- module Shushu
2
- module Account
3
- extend self
4
-
5
- def create
6
- Shushu.handle_req {RestClient.post(accounts_url, {}, Shushu.headers)}
7
- end
8
-
9
- def accounts_url
10
- [Shushu.url, "/accounts"].join
11
- end
12
- end
13
- end
@@ -1,25 +0,0 @@
1
- module Shushu
2
- module AcctOwn
3
- extend self
4
-
5
- def act(args)
6
- pmid , eid = args.delete(:payment_method_id), args.delete(:entity_id)
7
- args[:state] = "active"
8
- Shushu.handle_req do
9
- RestClient.put(acct_own_url(pmid, eid), args, Shushu.headers)
10
- end
11
- end
12
-
13
- def deact(args)
14
- pmid, eid = args.delete(:payment_method_id), args.delete(:entity_id)
15
- args[:state] = "inactive"
16
- Shushu.handle_req do
17
- RestClient.put(acct_own_url(pmid, eid), args, Shushu.headers)
18
- end
19
- end
20
-
21
- def acct_own_url(payment_method_id, entity_id)
22
- [Shushu.url, "/payment_methods/#{payment_method_id}/account_ownerships/#{entity_id}"].join
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- module Shushu
2
- class BillableUnit
3
- attr_accessor(
4
- :hid,
5
- :from,
6
- :to,
7
- :qty,
8
- :rate,
9
- :rate_period,
10
- :product_group,
11
- :product_name
12
- )
13
-
14
- def initialize(args_hash)
15
- @hid = args_hash["hid"]
16
- @from = args_hash["from"]
17
- @to = args_hash["to"]
18
- @qty = args_hash["qty"].to_f
19
- @rate = args_hash["rate"].to_i
20
- @rate_period = args_hash["rate_period"]
21
- @product_name = args_hash["product_name"]
22
- @product_group = args_hash["product_group"]
23
- end
24
-
25
- def id
26
- #TODO remove stub
27
- Time.now.to_i
28
- end
29
-
30
- def total
31
- @rate * @qty
32
- end
33
-
34
- end
35
- end
@@ -1,19 +0,0 @@
1
- module Shushu
2
- class LineItem
3
-
4
- attr_reader :unit_groups
5
-
6
- def initialize(unit_groups)
7
- @unit_groups = unit_groups
8
- end
9
-
10
- def app_name
11
- @unit_groups.first.hid
12
- end
13
-
14
- def total
15
- @unit_groups.map(&:total).reduce(:+)
16
- end
17
-
18
- end
19
- end
@@ -1,20 +0,0 @@
1
- module Shushu
2
- module PMethod
3
- extend self
4
-
5
- def create(args)
6
- Shushu.handle_req {RestClient.post(p_method_url, args, Shushu.headers)}
7
- end
8
-
9
- def update(args)
10
- id = args.delete(:id)
11
- Shushu.handle_req {RestClient.put(p_method_url(id), args, Shushu.headers)}
12
- end
13
-
14
- def p_method_url(id=nil)
15
- url = [Shushu.url, "/payment_methods"].join
16
- id.nil? ? url : url << "/#{id}"
17
- end
18
-
19
- end
20
- end
data/lib/models/r_code.rb DELETED
@@ -1,23 +0,0 @@
1
- module Shushu
2
- module RCode
3
- extend self
4
-
5
- def create(args)
6
- if args[:slug].nil?
7
- Shushu.handle_req do
8
- RestClient.post(rate_codes_url, args, Shushu.headers)
9
- end
10
- else
11
- Shushu.handle_req do
12
- url = [rate_codes_url, args.delete(:slug)].join("/")
13
- RestClient.put(url, args, Shushu.headers)
14
- end
15
- end
16
- end
17
-
18
- def rate_codes_url
19
- [Shushu.url, "/rate_codes"].join
20
- end
21
-
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- module Shushu
2
- module RevRep
3
- extend self
4
-
5
- def get(from, to)
6
- Shushu.handle_req do
7
- RestClient.get([Shushu.url, "/rev_report"].join, {:params => {:from => from.utc.to_s, :to => to.utc.to_s}})
8
- end
9
- end
10
-
11
- end
12
- end
13
-
@@ -1,59 +0,0 @@
1
- module Shushu
2
- class UnitGroup
3
- InvalidUnitGroup = Class.new(ShushuException)
4
-
5
- attr_reader :units
6
-
7
- def initialize(units)
8
- @units = units
9
- check_rates
10
- end
11
-
12
- def check_rates
13
- if @units.map(&:rate).uniq.length > 1
14
- raise(InvalidUnitGroup, "Rates must be homogenius.")
15
- end
16
- end
17
-
18
- def total
19
- rate * qty
20
- end
21
-
22
- def qty
23
- @units.map(&:qty).reduce(:+)
24
- end
25
-
26
- def rate
27
- sample_unit.rate
28
- end
29
-
30
- def rate_period
31
- sample_unit.rate_period
32
- end
33
-
34
- def name
35
- sample_unit.product_name
36
- end
37
-
38
- def hid
39
- sample_unit.hid
40
- end
41
-
42
- def product_name
43
- sample_unit.product_name
44
- end
45
-
46
- def product_group
47
- sample_unit.product_group
48
- end
49
-
50
- def description
51
- sample_unit.product_name
52
- end
53
-
54
- def sample_unit
55
- @sample_unit ||= @units.sample
56
- end
57
-
58
- end
59
- end
@@ -1,25 +0,0 @@
1
- module Shushu
2
- class BasePresenter
3
-
4
- def money(cents)
5
- add_commas(pennies_to_dollar(cents.to_i))
6
- end
7
-
8
- def add_commas(str)
9
- str.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse
10
- end
11
-
12
- def pennies_to_dollar(qty)
13
- sprintf("%.2f", qty / 100.0)
14
- end
15
-
16
- def trunc_hours(hrs)
17
- sprintf("%.3f", hrs)
18
- end
19
-
20
- def date_range(s, f)
21
- s.strftime('%d %b %H:%M ') + " - " + f.strftime('%d %b %H:%M ')
22
- end
23
-
24
- end
25
- end
@@ -1,49 +0,0 @@
1
- module Shushu
2
- class LineItemPresenter < BasePresenter
3
-
4
- def initialize(line_item)
5
- @line_item = line_item
6
- @unit_groups = @line_item.unit_groups
7
- @unit_group_presenters = @unit_groups.map {|ug| UnitGroupPresenter.new(ug)}
8
- end
9
-
10
- def total
11
- money(@line_item.total)
12
- end
13
-
14
- def name
15
- @line_item.app_name
16
- end
17
-
18
- def unit_group_rate(product_group)
19
- unit_group_presenters(product_group).sample.rate
20
- end
21
-
22
- def unit_group_total(product_group)
23
- money(
24
- unit_group_presenters(product_group).
25
- map(&:unit_group).
26
- map(&:total).
27
- reduce(:+)
28
- )
29
- end
30
-
31
- def unit_group_qty(product_group)
32
- trunc_hours(
33
- unit_group_presenters(product_group).
34
- map(&:unit_group).
35
- map(&:qty).
36
- reduce(:+)
37
- )
38
- end
39
-
40
- def unit_group_presenters(product_group=nil)
41
- if product_group
42
- @unit_group_presenters.select {|ugp| ugp.product_group == product_group}
43
- else
44
- @unit_group_presenters
45
- end
46
- end
47
-
48
- end
49
- end
@@ -1,23 +0,0 @@
1
- module Shushu
2
- class ReportPresenter < BasePresenter
3
-
4
- def initialize(report, line_item_builder=LineItemBuilder)
5
- @report = report
6
- @units = @report.billable_units
7
- @builder = line_item_builder
8
- end
9
-
10
- def total
11
- money(@report.total)
12
- end
13
-
14
- def line_item_presenters
15
- @line_item_presenters ||= begin
16
- @builder.build(@units).map do |li|
17
- LineItemPresenter.new(li)
18
- end
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,63 +0,0 @@
1
- module Shushu
2
- class UnitGroupPresenter < BasePresenter
3
-
4
- attr_reader :unit_group
5
-
6
- def initialize(unit_group)
7
- @unit_group = unit_group
8
- end
9
-
10
- def id
11
- [:hid, :name].map {|m| unit_group.send(m)}.join("_").gsub("-", "_")
12
- end
13
-
14
- def unit_presenters
15
- @unit_presenters ||= @unit_group.units.map {|u| UnitPresenter.new(u)}
16
- end
17
-
18
- def daily_report_url
19
- #TODO remove chart stub
20
- #payments_uri("/billable_units/daily")
21
- "/billable_units/daily"
22
- end
23
-
24
- def compacted_reports
25
- #TODO remove chart stub
26
- #BillableUnitReporter.compacted(@unit_group.units)
27
- []
28
- end
29
-
30
- def total
31
- money(@unit_group.total)
32
- end
33
-
34
- def qty
35
- trunc_hours(@unit_group.qty)
36
- end
37
-
38
- def rate
39
- @unit_group.rate
40
- end
41
-
42
- def name
43
- @unit_group.name
44
- end
45
-
46
- def description
47
- @unit_group.description
48
- end
49
-
50
- def product_name
51
- @unit_group.product_name
52
- end
53
-
54
- def product_group
55
- @unit_group.product_group
56
- end
57
-
58
- def unit_of_measure
59
- @unit_group.rate_period
60
- end
61
-
62
- end
63
- end
@@ -1,34 +0,0 @@
1
- module Shushu
2
- class UnitPresenter < BasePresenter
3
-
4
- def initialize(unit)
5
- @unit = unit
6
- end
7
-
8
- def total
9
- money(@unit.total)
10
- end
11
-
12
- def rate
13
- [money(@unit.rate), @unit.rate_period].join("/")
14
- end
15
-
16
- def qty
17
- trunc_hours(@unit.qty)
18
- end
19
-
20
- def start
21
- @unit.from
22
- end
23
-
24
- def end
25
- @unit.to
26
- end
27
-
28
- def description
29
- @unit.product_name
30
- end
31
-
32
- end
33
- end
34
-
@@ -1,17 +0,0 @@
1
- module Shushu
2
- module LineItemBuilder
3
- extend self
4
-
5
- # Give build() a collection of units and it will return a
6
- # collection of line_items. Each line_item will have a collection
7
- # of unit_groups wich will hold a collection of units
8
-
9
- def build(units)
10
- units.group_by(&:hid).map do |hid, units_by_hid|
11
- units_by_hid.group_by(&:product_name).map do |product_name, units_by_name|
12
- UnitGroup.new(units_by_name)
13
- end
14
- end.map {|unit_groups| LineItem.new(unit_groups)}.flatten
15
- end
16
- end
17
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class BEventTest < ShushuTest
4
- def setup
5
- Shushu.url = "http://example.com"
6
- end
7
-
8
- def test_open
9
- our_params = {
10
- :hid => "app123",
11
- :entity_id => 1,
12
- :rate_code => "RT01",
13
- :time => Time.utc(2012,1).to_s,
14
- :product_name => "web",
15
- :description => "some command",
16
- :qty => 1
17
- }
18
- api_resp_body = Shushu::HttpHelpers.enc_json(our_params)
19
- FakeWeb.register_uri(:put,
20
- (Shushu.url + "/resources/app123/billable_events/1"),
21
- :body => api_resp_body
22
- )
23
- event = Shushu::BEvent.open(our_params)
24
- assert_equal(1, event["entity_id"])
25
- end
26
- end
27
-
@@ -1,8 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class BillableUnitTest < ShushuTest
4
- def test_total
5
- unit1 = Shushu::BillableUnit.new("rate" => 10, "qty" => 10)
6
- assert_equal(100, unit1.total)
7
- end
8
- end
@@ -1,10 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class LineItemTest < ShushuTest
4
- def test_total
5
- unit1 = Shushu::BillableUnit.new("rate" => 10, "qty" => 10)
6
- unit_group1 = Shushu::UnitGroup.new([unit1])
7
- line_item = Shushu::LineItem.new([unit_group1])
8
- assert_equal(100, line_item.total)
9
- end
10
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class PMethodTest < ShushuTest
4
-
5
- def test_create
6
- params = {
7
- :card_token => "abc123"
8
- }
9
- api_resp_body = Shushu::HttpHelpers.enc_json(params)
10
- Shushu.url = "http://provider:password@shushu.heroku.com"
11
- FakeWeb.register_uri(:post, (Shushu.url + "/payment_methods"), :body => api_resp_body)
12
- response = Shushu::PMethod.create(params)
13
- assert_equal("abc123", response["card_token"])
14
- end
15
-
16
- def test_update
17
- params = {
18
- :id => "1",
19
- :card_token => "abc123"
20
- }
21
- api_resp_body = Shushu::HttpHelpers.enc_json(params)
22
- Shushu.url = "http://provider:password@shushu.heroku.com"
23
- FakeWeb.register_uri(:put, (Shushu.url + "/payment_methods/1"), :body => api_resp_body)
24
- response = Shushu::PMethod.update(params)
25
- assert_equal("abc123", response["card_token"])
26
- assert_equal("1", response["id"])
27
- end
28
-
29
- end
@@ -1,12 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class RevRepTest < ShushuTest
4
- def test_for_month
5
- api_resp_body = Shushu::HttpHelpers.enc_json({:ok => true})
6
- Shushu.url = "http://provider:password@shushu.heroku.com"
7
- url = Shushu.url + "/rev_report?from=2011-01-01+00%3A00%3A00+UTC&to=2011-02-01+00%3A00%3A00+UTC"
8
- FakeWeb.register_uri(:get, url, :body => api_resp_body)
9
- Shushu::RevRep.get(Time.utc(2011,1), Time.utc(2011,2))
10
- end
11
- end
12
-
@@ -1,17 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class UnitGroupTest < ShushuTest
4
- def test_total
5
- unit1 = Shushu::BillableUnit.new("rate" => 10, "qty" => 10)
6
- unit_group1 = Shushu::UnitGroup.new([unit1])
7
- assert_equal(100, unit_group1.total)
8
- end
9
-
10
- def test_check_rates
11
- unit1 = Shushu::BillableUnit.new("rate" => 10, "qty" => 10)
12
- unit2 = Shushu::BillableUnit.new("rate" => 9, "qty" => 10)
13
- unit_group1 = Shushu::UnitGroup.new([unit1])
14
- unit_group2 = Shushu::UnitGroup.new([unit2])
15
- assert_raises(Shushu::UnitGroup::InvalidUnitGroup) {Shushu::UnitGroup.new([unit1, unit2])}
16
- end
17
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class LineItemPresenterTest < ShushuTest
4
- def test_unit_group_total
5
- unit1 = Shushu::BillableUnit.new("rate" => 1000, "qty" => 10, "product_group" => "dyno")
6
- unit_group1 = Shushu::UnitGroup.new([unit1])
7
- line_item = Shushu::LineItem.new([unit_group1])
8
- lip = Shushu::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 = Shushu::BillableUnit.new("rate" => 1000, "qty" => 10, "product_group" => "dyno")
14
- unit2 = Shushu::BillableUnit.new("rate" => 1000, "qty" => 1, "product_group" => "dyno")
15
- unit_group1 = Shushu::UnitGroup.new([unit1, unit2])
16
- line_item = Shushu::LineItem.new([unit_group1])
17
- lip = Shushu::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 = Shushu::BillableUnit.new("product_group" => "dyno")
23
- unit2 = Shushu::BillableUnit.new("product_group" => "dyno")
24
- unit3 = Shushu::BillableUnit.new("product_group" => "addon")
25
- unit_group1 = Shushu::UnitGroup.new([unit1, unit2])
26
- unit_group2 = Shushu::UnitGroup.new([unit3])
27
- line_item = Shushu::LineItem.new([unit_group1, unit_group2])
28
- lip = Shushu::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
-