chargify_api_ares 0.4.4 → 0.5.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.
Files changed (48) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +57 -0
  5. data/Guardfile +15 -0
  6. data/README.md +29 -37
  7. data/Rakefile +12 -5
  8. data/chargify_api_ares.gemspec +25 -63
  9. data/examples/coupons.rb +50 -0
  10. data/{samples → examples}/customers.rb +1 -1
  11. data/{samples → examples}/metered_components.rb +5 -2
  12. data/{samples → examples}/products.rb +1 -1
  13. data/{samples → examples}/subscriptions.rb +2 -2
  14. data/{samples → examples}/transactions.rb +2 -3
  15. data/lib/chargify_api_ares.rb +14 -314
  16. data/lib/chargify_api_ares/config.rb +16 -0
  17. data/lib/chargify_api_ares/resources/base.rb +14 -0
  18. data/lib/chargify_api_ares/resources/component.rb +4 -0
  19. data/lib/chargify_api_ares/resources/coupon.rb +19 -0
  20. data/lib/chargify_api_ares/resources/customer.rb +21 -0
  21. data/lib/chargify_api_ares/resources/payment_profile.rb +4 -0
  22. data/lib/chargify_api_ares/resources/product.rb +25 -0
  23. data/lib/chargify_api_ares/resources/product_family.rb +34 -0
  24. data/lib/chargify_api_ares/resources/site.rb +7 -0
  25. data/lib/chargify_api_ares/resources/statement.rb +4 -0
  26. data/lib/chargify_api_ares/resources/subscription.rb +123 -0
  27. data/lib/chargify_api_ares/resources/transaction.rb +17 -0
  28. data/lib/chargify_api_ares/resources/usage.rb +11 -0
  29. data/spec/factories.rb +28 -24
  30. data/spec/remote/remote.example.yml +6 -0
  31. data/spec/remote/remote_spec.rb +347 -452
  32. data/spec/remote/spec_helper.rb +11 -15
  33. data/spec/{base_spec.rb → resources/base_spec.rb} +1 -1
  34. data/spec/resources/coupon_spec.rb +35 -0
  35. data/spec/resources/customer_spec.rb +36 -0
  36. data/spec/resources/product_family_spec.rb +57 -0
  37. data/spec/resources/product_spec.rb +23 -0
  38. data/spec/{subscriptions_component_spec.rb → resources/subscription_component_spec.rb} +2 -2
  39. data/spec/{subscription_spec.rb → resources/subscription_spec.rb} +2 -2
  40. data/spec/resources/usage_spec.rb +44 -0
  41. data/spec/spec_helper.rb +6 -8
  42. data/spec/{mocks → support}/fake_resource.rb +0 -0
  43. metadata +148 -29
  44. data/VERSION +0 -1
  45. data/config/remote.example.yml +0 -7
  46. data/spec/components_spec.rb +0 -48
  47. data/spec/customer_spec.rb +0 -23
  48. data/spec/product_spec.rb +0 -23
@@ -5,7 +5,16 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
5
5
 
6
6
  require 'chargify_api_ares'
7
7
 
8
+ unless File.exists?(File.join(File.dirname(__FILE__), 'remote.yml'))
9
+ STDERR.puts "\nERROR: Make sure a remote.yml file exists at ./spec/remote/remote.yml\n\n"
10
+ abort
11
+ end
12
+
8
13
  RSpec.configure do |config|
14
+ config.filter_run :focused => true
15
+ config.run_all_when_everything_filtered = true
16
+ config.alias_example_to :fit, :focused => true
17
+ config.color_enabled = true
9
18
  config.before(:all) do
10
19
  Chargify.configure do |c|
11
20
  c.api_key = remote_configuration['api_key']
@@ -14,21 +23,8 @@ RSpec.configure do |config|
14
23
  end
15
24
  end
16
25
 
17
- def run_remote_tests?
18
- remote_configuration['run_tests'] === true
19
- end
20
-
21
- def remote_configuration
22
- @remote_configuration ||= load_remote_configuration_file
23
- end
24
-
25
26
  private
26
27
 
27
- def load_remote_configuration_file
28
- configuration_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'remote.yml'))
29
- if File.exist?(configuration_file)
30
- YAML.load_file(configuration_file)
31
- else
32
- {}
33
- end
28
+ def remote_configuration
29
+ @remote_configuration ||= YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), 'remote.yml')))
34
30
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe Chargify::Base do
4
4
 
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Coupon do
4
+ context '.find_by_product_family_id_and_code' do
5
+ let(:existing_coupon) { Factory.build(:coupon, :code => '20OFF') }
6
+
7
+ before(:each) do
8
+ FakeWeb.register_uri(:get, "#{test_domain}/coupons/lookup.xml?code=#{existing_coupon.code}&product_family_id=10", :body => existing_coupon.attributes.to_xml)
9
+ end
10
+
11
+ it "finds the correct coupon by product family and code" do
12
+ Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF').should == existing_coupon
13
+ end
14
+
15
+ it "is an instance of Chargify::Coupon" do
16
+ coupon = Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF')
17
+ coupon.should be_instance_of(Chargify::Coupon)
18
+ end
19
+ end
20
+
21
+ context '.find_all_by_product_family_id' do
22
+ let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
23
+ let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
24
+
25
+ before do
26
+ FakeWeb.register_uri(:get, "#{test_domain}/coupons.xml?product_family_id=5", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
27
+ end
28
+
29
+ it "returns all of the coupons for a product family" do
30
+ coupons = Chargify::Coupon.find_all_by_product_family_id(5)
31
+ coupons.count.should == 2
32
+ coupons.map{|c| c.should be_instance_of(Chargify::Coupon)}
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Customer do
4
+ context '.find_by_reference' do
5
+ let(:existing_customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
6
+
7
+ before(:each) do
8
+ FakeWeb.register_uri(:get, "#{test_domain}/customers/lookup.xml?reference=#{existing_customer.reference}", :body => existing_customer.attributes.to_xml)
9
+ end
10
+
11
+ it 'finds the correct customer by reference' do
12
+ customer = Chargify::Customer.find_by_reference('sigma')
13
+ customer.should == existing_customer
14
+ end
15
+
16
+ it 'is an instance of Chargify::Customer' do
17
+ customer = Chargify::Customer.find_by_reference('sigma')
18
+ customer.should be_instance_of(Chargify::Customer)
19
+ end
20
+ end
21
+
22
+ context "#subscriptions" do
23
+ let(:customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
24
+ let(:subscription_1) { Chargify::Customer::Subscription.create(:customer_id => customer.id, :balance_in_cents => 4999) }
25
+ let(:subscription_2) { Chargify::Customer::Subscription.create(:customer_id => customer.id, :balance_in_cents => 2499) }
26
+
27
+ before(:each) do
28
+ FakeWeb.register_uri(:get, "#{test_domain}/customers/#{customer.id}/subscriptions.xml", :body => [subscription_1.attributes, subscription_2.attributes].to_xml)
29
+ end
30
+
31
+ it "returns the subscriptions belonging to the customer" do
32
+ customer.subscriptions.should =~ [subscription_1, subscription_2]
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::ProductFamily do
4
+ context ".find_by_handle" do
5
+ let(:product_family) { Chargify::ProductFamily.create(:id => 1, :handle => 'farming') }
6
+
7
+ before(:each) do
8
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/lookup.xml?handle=#{product_family.handle}", :body => product_family.to_xml)
9
+ end
10
+
11
+ it "returns a product family" do
12
+ Chargify::ProductFamily.find_by_handle('farming').should == product_family
13
+ end
14
+ end
15
+
16
+ context "#products" do
17
+ let(:product_family) { Chargify::ProductFamily.create(:id => 10) }
18
+ let(:product_1) { Chargify::ProductFamily::Product.create(:product_family_id => product_family.id, :name => 'foo') }
19
+ let(:product_2) { Chargify::ProductFamily::Product.create(:product_family_id => product_family.id, :name => 'bar') }
20
+
21
+ before(:each) do
22
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{product_family.id}/products.xml", :body => [product_1.attributes, product_2.attributes].to_xml)
23
+ end
24
+
25
+ it "returns the products belonging to the product family" do
26
+ product_family.products.should =~ [product_1, product_2]
27
+ end
28
+ end
29
+
30
+ context "#coupons" do
31
+ let(:product_family) { Chargify::ProductFamily.create(:id => 10) }
32
+ let(:coupon_1) { Chargify::ProductFamily::Coupon.create(:product_family_id => product_family.id, :name => '50 percent off') }
33
+ let(:coupon_2) { Chargify::ProductFamily::Coupon.create(:product_family_id => product_family.id, :name => '25 percent off') }
34
+
35
+ before(:each) do
36
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{product_family.id}/coupons.xml", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
37
+ end
38
+
39
+ it "returns the coupons belonging to the product family" do
40
+ product_family.coupons.should =~ [coupon_1, coupon_2]
41
+ end
42
+ end
43
+
44
+ context "#components" do
45
+ let(:product_family) { Chargify::ProductFamily.create(:id => 10) }
46
+ let(:component_1) { Chargify::ProductFamily::Component.create(:product_family_id => product_family.id, :name => 'Spinwheel Component') }
47
+ let(:component_2) { Chargify::ProductFamily::Component.create(:product_family_id => product_family.id, :name => 'Flywheel Component') }
48
+
49
+ before(:each) do
50
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{product_family.id}/components.xml", :body => [component_1.attributes, component_2.attributes].to_xml)
51
+ end
52
+
53
+ it "returns the components belonging to the product family" do
54
+ product_family.components.should =~ [component_1, component_2]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Product do
4
+
5
+ context '.find_by_handle' do
6
+ let(:existing_product) { Chargify::Product.create(:id => 2, :handle => 'green-money') }
7
+
8
+ before(:each) do
9
+ FakeWeb.register_uri(:get, "#{test_domain}/products/lookup.xml?handle=#{existing_product.handle}", :body => existing_product.attributes.to_xml)
10
+ end
11
+
12
+ it 'finds the correct product by handle' do
13
+ product = Chargify::Product.find_by_handle('green-money')
14
+ product.should == existing_product
15
+ end
16
+
17
+ it 'is an instance of Chargify::Product' do
18
+ product = Chargify::Product.find_by_handle('green-money')
19
+ product.should be_instance_of(Chargify::Product)
20
+ end
21
+ end
22
+
23
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe Chargify::Subscription::Component do
4
4
  before(:each) do
@@ -79,4 +79,4 @@ describe Chargify::Subscription::Component do
79
79
  Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id}).should == @sc1_prime
80
80
  end
81
81
  end
82
- end
82
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe Chargify::Subscription do
4
4
 
@@ -25,7 +25,7 @@ describe Chargify::Subscription do
25
25
  @subscription.attributes['credit_card'].should be_blank
26
26
  end
27
27
 
28
- it 'doesn\'t strip other attrs' do
28
+ it "doesn't strip other attrs" do
29
29
  subscription = FactoryGirl.build(:subscription)
30
30
 
31
31
  lambda { subscription.save! }.should_not change(subscription, :attributes)
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Usage do
4
+ context "create" do
5
+ before do
6
+ @subscription = Factory(:subscription)
7
+ @component = Factory(:component)
8
+ @now = DateTime.now.to_s
9
+ end
10
+
11
+ it "should create a usage record" do
12
+ u = Chargify::Usage.new
13
+ u.subscription_id = @subscription.id
14
+ u.component_id = @component.id
15
+ u.quantity = 5
16
+ u.memo = @now
17
+ u.save
18
+
19
+ usage = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
20
+ usage.memo.should == @now
21
+ usage.quantity.should == 5
22
+ end
23
+ end
24
+
25
+ context "find" do
26
+ before do
27
+ @subscription = Factory(:subscription)
28
+ @component = Factory(:component)
29
+ @now = DateTime.now.to_s
30
+ end
31
+
32
+ it "should return the usage" do
33
+ u = Chargify::Usage.new
34
+ u.subscription_id = @subscription.id
35
+ u.component_id = @component.id
36
+ u.quantity = 5
37
+ u.memo = @now
38
+ u.save
39
+
40
+ usage = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
41
+ usage.quantity.should == 5
42
+ end
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,16 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
5
2
 
6
3
  require 'chargify_api_ares'
7
-
4
+ require 'rspec'
8
5
  require 'fakeweb'
9
- require 'mocks/fake_resource'
10
- ActiveResource::Base.send :include, ActiveResource::FakeResource
11
- FakeWeb.allow_net_connect = false
6
+ require 'support/fake_resource'
12
7
  require 'factory_girl'
13
8
  require 'faker'
14
9
  require 'factories'
15
10
 
11
+ ActiveResource::Base.send :include, ActiveResource::FakeResource
12
+ FakeWeb.allow_net_connect = false
13
+
16
14
  Chargify.configure do |c|
17
15
  c.subdomain = 'test'
18
16
  c.api_key = 'test'
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify_api_ares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,48 +12,163 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2011-10-25 00:00:00.000000000 -04:00
15
+ date: 2011-11-08 00:00:00.000000000 -05:00
16
16
  default_executable:
17
- dependencies: []
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: activeresource
20
+ requirement: &2160383880 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ! '>='
24
+ - !ruby/object:Gem::Version
25
+ version: 2.3.5
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: *2160383880
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: &2160383420 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 0.9.2
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: *2160383420
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: &2160382960 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.7.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: *2160382960
51
+ - !ruby/object:Gem::Dependency
52
+ name: factory_girl
53
+ requirement: &2160382500 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 2.1.0
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: *2160382500
62
+ - !ruby/object:Gem::Dependency
63
+ name: fakeweb
64
+ requirement: &2160382040 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: *2160382040
73
+ - !ruby/object:Gem::Dependency
74
+ name: faker
75
+ requirement: &2160381580 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: 1.0.1
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: *2160381580
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rspec
86
+ requirement: &2160381120 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: 0.5.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: *2160381120
95
+ - !ruby/object:Gem::Dependency
96
+ name: growl
97
+ requirement: &2160380660 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 1.0.3
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: *2160380660
106
+ - !ruby/object:Gem::Dependency
107
+ name: rb-fsevent
108
+ requirement: &2160380200 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: 0.4.2
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: *2160380200
18
117
  description: ''
19
118
  email: support@chargify.com
20
119
  executables: []
21
120
  extensions: []
22
- extra_rdoc_files:
23
- - LICENSE.txt
24
- - README.md
121
+ extra_rdoc_files: []
25
122
  files:
26
123
  - .gitignore
124
+ - .travis.yml
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - Guardfile
27
128
  - LICENSE.txt
28
129
  - README.md
29
130
  - Rakefile
30
- - VERSION
31
131
  - chargify_api_ares.gemspec
32
- - config/remote.example.yml
132
+ - examples/coupons.rb
133
+ - examples/customers.rb
134
+ - examples/metered_components.rb
135
+ - examples/products.rb
136
+ - examples/subscriptions.rb
137
+ - examples/transactions.rb
33
138
  - lib/chargify_api_ares.rb
34
- - samples/customers.rb
35
- - samples/metered_components.rb
36
- - samples/products.rb
37
- - samples/subscriptions.rb
38
- - samples/transactions.rb
39
- - spec/base_spec.rb
40
- - spec/components_spec.rb
41
- - spec/customer_spec.rb
139
+ - lib/chargify_api_ares/config.rb
140
+ - lib/chargify_api_ares/resources/base.rb
141
+ - lib/chargify_api_ares/resources/component.rb
142
+ - lib/chargify_api_ares/resources/coupon.rb
143
+ - lib/chargify_api_ares/resources/customer.rb
144
+ - lib/chargify_api_ares/resources/payment_profile.rb
145
+ - lib/chargify_api_ares/resources/product.rb
146
+ - lib/chargify_api_ares/resources/product_family.rb
147
+ - lib/chargify_api_ares/resources/site.rb
148
+ - lib/chargify_api_ares/resources/statement.rb
149
+ - lib/chargify_api_ares/resources/subscription.rb
150
+ - lib/chargify_api_ares/resources/transaction.rb
151
+ - lib/chargify_api_ares/resources/usage.rb
42
152
  - spec/factories.rb
43
- - spec/mocks/fake_resource.rb
44
- - spec/product_spec.rb
153
+ - spec/remote/remote.example.yml
45
154
  - spec/remote/remote_spec.rb
46
155
  - spec/remote/spec_helper.rb
156
+ - spec/resources/base_spec.rb
157
+ - spec/resources/coupon_spec.rb
158
+ - spec/resources/customer_spec.rb
159
+ - spec/resources/product_family_spec.rb
160
+ - spec/resources/product_spec.rb
161
+ - spec/resources/subscription_component_spec.rb
162
+ - spec/resources/subscription_spec.rb
163
+ - spec/resources/usage_spec.rb
47
164
  - spec/spec.opts
48
165
  - spec/spec_helper.rb
49
- - spec/subscription_spec.rb
50
- - spec/subscriptions_component_spec.rb
166
+ - spec/support/fake_resource.rb
51
167
  has_rdoc: true
52
168
  homepage: http://github.com/grasshopperlabs/chargify_api_ares
53
169
  licenses: []
54
170
  post_install_message:
55
- rdoc_options:
56
- - --charset=UTF-8
171
+ rdoc_options: []
57
172
  require_paths:
58
173
  - lib
59
174
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -75,14 +190,18 @@ signing_key:
75
190
  specification_version: 3
76
191
  summary: A Chargify API wrapper for Ruby using ActiveResource
77
192
  test_files:
78
- - spec/base_spec.rb
79
- - spec/components_spec.rb
80
- - spec/customer_spec.rb
81
193
  - spec/factories.rb
82
- - spec/mocks/fake_resource.rb
83
- - spec/product_spec.rb
194
+ - spec/remote/remote.example.yml
84
195
  - spec/remote/remote_spec.rb
85
196
  - spec/remote/spec_helper.rb
197
+ - spec/resources/base_spec.rb
198
+ - spec/resources/coupon_spec.rb
199
+ - spec/resources/customer_spec.rb
200
+ - spec/resources/product_family_spec.rb
201
+ - spec/resources/product_spec.rb
202
+ - spec/resources/subscription_component_spec.rb
203
+ - spec/resources/subscription_spec.rb
204
+ - spec/resources/usage_spec.rb
205
+ - spec/spec.opts
86
206
  - spec/spec_helper.rb
87
- - spec/subscription_spec.rb
88
- - spec/subscriptions_component_spec.rb
207
+ - spec/support/fake_resource.rb