chargify_api_ares 0.2.5 → 0.3.1
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.
- data/VERSION +1 -1
- data/chargify_api_ares.gemspec +6 -4
- data/lib/chargify_api_ares.rb +25 -2
- data/samples/metered_components.rb +3 -1
- data/spec/factories.rb +13 -0
- data/spec/product_spec.rb +0 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/subscriptions_component_spec.rb +82 -0
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/chargify_api_ares.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{chargify_api_ares}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose", "Nathan Verni"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-16}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{mklett@grasshopper.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,8 @@ Gem::Specification.new do |s|
|
|
35
35
|
"spec/mocks/fake_resource.rb",
|
36
36
|
"spec/product_spec.rb",
|
37
37
|
"spec/spec_helper.rb",
|
38
|
-
"spec/subscription_spec.rb"
|
38
|
+
"spec/subscription_spec.rb",
|
39
|
+
"spec/subscriptions_component_spec.rb"
|
39
40
|
]
|
40
41
|
s.homepage = %q{http://github.com/grasshopperlabs/chargify_api_ares}
|
41
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -50,7 +51,8 @@ Gem::Specification.new do |s|
|
|
50
51
|
"spec/mocks/fake_resource.rb",
|
51
52
|
"spec/product_spec.rb",
|
52
53
|
"spec/spec_helper.rb",
|
53
|
-
"spec/subscription_spec.rb"
|
54
|
+
"spec/subscription_spec.rb",
|
55
|
+
"spec/subscriptions_component_spec.rb"
|
54
56
|
]
|
55
57
|
|
56
58
|
if s.respond_to? :specification_version then
|
data/lib/chargify_api_ares.rb
CHANGED
@@ -56,8 +56,15 @@ module Chargify
|
|
56
56
|
yield self
|
57
57
|
|
58
58
|
Base.user = api_key
|
59
|
-
Base.password = 'X'
|
60
|
-
|
59
|
+
Base.password = 'X'
|
60
|
+
|
61
|
+
if site.blank?
|
62
|
+
Base.site = "https://#{subdomain}.chargify.com"
|
63
|
+
Subscription::Component.site = "https://#{subdomain}.chargify.com/subscriptions/:subscription_id"
|
64
|
+
else
|
65
|
+
Base.site = site
|
66
|
+
Subscription::Component.site = site + "/subscriptions/:subscription_id"
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
@@ -98,12 +105,28 @@ module Chargify
|
|
98
105
|
destroy
|
99
106
|
end
|
100
107
|
|
108
|
+
def component(id)
|
109
|
+
Component.find(id, :params => {:subscription_id => self.id})
|
110
|
+
end
|
111
|
+
|
112
|
+
def components(params = {})
|
113
|
+
params.merge!({:subscription_id => self.id})
|
114
|
+
Component.find(:all, :params => params)
|
115
|
+
end
|
116
|
+
|
101
117
|
# Perform a one-time charge on an existing subscription.
|
102
118
|
# For more information, please see the one-time charge API docs available
|
103
119
|
# at: http://support.chargify.com/faqs/api/api-charges
|
104
120
|
def charge(attrs = {})
|
105
121
|
post :charges, :charge => attrs
|
106
122
|
end
|
123
|
+
|
124
|
+
class Component < Base
|
125
|
+
# All Subscription Components are considered already existing records, but the id isn't used
|
126
|
+
def id
|
127
|
+
self.component_id
|
128
|
+
end
|
129
|
+
end
|
107
130
|
end
|
108
131
|
|
109
132
|
class Product < Base
|
@@ -13,7 +13,9 @@ Chargify.configure do |c|
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
#
|
17
|
+
# This assumes you have a product family with a metered component setup
|
18
|
+
#
|
17
19
|
product_family = Chargify::ProductFamily.find(:first)
|
18
20
|
component = Chargify::Component.find(:first, :params => {:product_family_id => product_family.id})
|
19
21
|
subscription = Chargify::Subscription.find(:first)
|
data/spec/factories.rb
CHANGED
@@ -47,3 +47,16 @@ Factory.define :component, :class => Chargify::Component do |f|
|
|
47
47
|
f.name { Faker::Company.bs }
|
48
48
|
f.unit_name 'unit'
|
49
49
|
end
|
50
|
+
|
51
|
+
Factory.define :quantity_based_component, :class => Chargify::Component do |f|
|
52
|
+
f.name { Faker::Company.bs }
|
53
|
+
f.unit_name 'unit'
|
54
|
+
f.pricing_scheme 'tiered'
|
55
|
+
f.component_type 'quantity_based_component'
|
56
|
+
end
|
57
|
+
|
58
|
+
Factory.define :subscriptions_component, :class => Chargify::Subscription::Component do |f|
|
59
|
+
f.name { Faker::Company.bs }
|
60
|
+
f.unit_name 'unit'
|
61
|
+
f.component_type 'quantity_based_component'
|
62
|
+
end
|
data/spec/product_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe Chargify::Product do
|
|
6
6
|
before do
|
7
7
|
@handle = 'handle1'
|
8
8
|
@existing_product = Factory(:product, :handle => @handle, :id => Factory.next(:product_id))
|
9
|
-
puts @existing_product.attributes.to_xml
|
10
9
|
FakeWeb.register_uri(:get, "#{test_domain}/products/lookup.xml?handle=#{@existing_product.handle}", :body => @existing_product.attributes.to_xml)
|
11
10
|
end
|
12
11
|
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Chargify::Subscription::Component do
|
4
|
+
before(:each) do
|
5
|
+
@subscription = Chargify::Subscription.new(:id => 1)
|
6
|
+
@sc1 = Chargify::Subscription::Component.new(
|
7
|
+
:subscription_id => @subscription.id,
|
8
|
+
:component_id => 1,
|
9
|
+
:allocated_quantity => 0,
|
10
|
+
:name => "Paying Customers",
|
11
|
+
:unit_name => "customers",
|
12
|
+
:component_type => "quantity_based_component",
|
13
|
+
:pricing_scheme => "stairstep"
|
14
|
+
)
|
15
|
+
@sc2 = Chargify::Subscription::Component.new(
|
16
|
+
:subscription_id => @subscription.id,
|
17
|
+
:component_id => 2,
|
18
|
+
:unit_balance => 0,
|
19
|
+
:name => "Text Messages",
|
20
|
+
:unit_name => "text message",
|
21
|
+
:component_type => "metered_component"
|
22
|
+
)
|
23
|
+
@subscriptions_components = [@sc1, @sc2]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "listing subscription components" do
|
27
|
+
before(:each) do
|
28
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
29
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components.xml", :body => @subscriptions_components.to_xml(:root => 'components'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns an array of components from Chargify::Subscription::Component.find(:all, :params => {:subscription_id => @subscription.id})" do
|
33
|
+
Chargify::Subscription::Component.find(:all, :params => {:subscription_id => @subscription.id}).should == @subscriptions_components
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns an array of components from Chargify::Subscription.find(2).components" do
|
37
|
+
subscription = Chargify::Subscription.find(@subscription.id)
|
38
|
+
subscription.components.should == @subscriptions_components
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "reading a subscription component" do
|
43
|
+
before(:each) do
|
44
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
45
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1.to_xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the subscription's component resource from Chargify::Subscription::Component.find(1, :params => {:subscription_id => 1})" do
|
49
|
+
Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id}).should == @sc1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns the subscription's component resource from Chargify::Subscription.find(1).component(1)" do
|
53
|
+
subscription = Chargify::Subscription.find(@subscription.id)
|
54
|
+
subscription.component(@sc1.component_id).should == @sc1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "updating a subscription component" do
|
59
|
+
before(:each) do
|
60
|
+
@new_allocated_quantity = @sc1.allocated_quantity + 5
|
61
|
+
|
62
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
63
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1.to_xml)
|
64
|
+
|
65
|
+
@sc1_prime = @sc1
|
66
|
+
@sc1_prime.allocated_quantity = @new_allocated_quantity
|
67
|
+
|
68
|
+
FakeWeb.register_uri(:put, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1_prime.to_xml)
|
69
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1_prime.to_xml)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "updates the subscription's component allocated quantity" do
|
73
|
+
component = Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id})
|
74
|
+
component.allocated_quantity = @new_allocated_quantity
|
75
|
+
|
76
|
+
result = component.save
|
77
|
+
result.should be_true
|
78
|
+
|
79
|
+
Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id}).should == @sc1_prime
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Klett
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-04-16 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- spec/product_spec.rb
|
51
51
|
- spec/spec_helper.rb
|
52
52
|
- spec/subscription_spec.rb
|
53
|
+
- spec/subscriptions_component_spec.rb
|
53
54
|
has_rdoc: true
|
54
55
|
homepage: http://github.com/grasshopperlabs/chargify_api_ares
|
55
56
|
licenses: []
|
@@ -89,3 +90,4 @@ test_files:
|
|
89
90
|
- spec/product_spec.rb
|
90
91
|
- spec/spec_helper.rb
|
91
92
|
- spec/subscription_spec.rb
|
93
|
+
- spec/subscriptions_component_spec.rb
|