jsmestad-chargify 0.3.0.pre5

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 (43) hide show
  1. data/.gitignore +23 -0
  2. data/Gemfile +20 -0
  3. data/LICENSE +20 -0
  4. data/README.markdown +38 -0
  5. data/Rakefile +38 -0
  6. data/VERSION +1 -0
  7. data/changelog.md +24 -0
  8. data/jsmestad-chargify.gemspec +97 -0
  9. data/lib/chargify.rb +22 -0
  10. data/lib/chargify/base.rb +88 -0
  11. data/lib/chargify/config.rb +86 -0
  12. data/lib/chargify/customer.rb +72 -0
  13. data/lib/chargify/error.rb +23 -0
  14. data/lib/chargify/parser.rb +13 -0
  15. data/lib/chargify/product.rb +26 -0
  16. data/lib/chargify/subscription.rb +93 -0
  17. data/lib/chargify/transaction.rb +14 -0
  18. data/spec/fixtures/charge_subscription.json +5 -0
  19. data/spec/fixtures/charge_subscription_missing_parameters.json +4 -0
  20. data/spec/fixtures/component.json +11 -0
  21. data/spec/fixtures/components.json +24 -0
  22. data/spec/fixtures/customer.json +12 -0
  23. data/spec/fixtures/customers.json +12 -0
  24. data/spec/fixtures/deleted_subscription.json +1 -0
  25. data/spec/fixtures/invalid_subscription.json +48 -0
  26. data/spec/fixtures/list_metered_subscriptions.json +3 -0
  27. data/spec/fixtures/migrate_subscription.json +51 -0
  28. data/spec/fixtures/new_customer.json +12 -0
  29. data/spec/fixtures/product.json +17 -0
  30. data/spec/fixtures/products.json +17 -0
  31. data/spec/fixtures/subscription.json +49 -0
  32. data/spec/fixtures/subscription_not_found.json +1 -0
  33. data/spec/fixtures/subscriptions.json +49 -0
  34. data/spec/spec.opts +1 -0
  35. data/spec/spec_helper.rb +26 -0
  36. data/spec/support/fakeweb_stubs.rb +33 -0
  37. data/spec/unit/chargify/config_spec.rb +147 -0
  38. data/spec/unit/chargify/customer_spec.rb +111 -0
  39. data/spec/unit/chargify/parser_spec.rb +7 -0
  40. data/spec/unit/chargify/product_spec.rb +35 -0
  41. data/spec/unit/chargify/subscription_spec.rb +304 -0
  42. data/spec/unit/chargify/transaction_spec.rb +11 -0
  43. metadata +154 -0
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Parser do
4
+ subject { Chargify::Parser.send(:new, 'body', :json) }
5
+
6
+ it { should respond_to(:parse) }
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Product do
4
+
5
+ describe '.all' do
6
+
7
+ it "should return a list of products" do
8
+ stub_get "https://OU812:x@pengwynn.chargify.com/products.json", "products.json"
9
+ products = Chargify::Product.all
10
+ products.first.accounting_code.should == 'TSMO'
11
+ end
12
+
13
+ end
14
+
15
+ describe '.find' do
16
+
17
+ it "should return info for a product" do
18
+ stub_get "https://OU812:x@pengwynn.chargify.com/products/8.json", "product.json"
19
+ product = Chargify::Product.find(8)
20
+ product.accounting_code.should == 'TSMO'
21
+ end
22
+
23
+ end
24
+
25
+ describe '.find_by_handle' do
26
+
27
+ it "should return info for a product by its handle" do
28
+ stub_get "https://OU812:x@pengwynn.chargify.com/products/handle/tweetsaver.json", "product.json"
29
+ product = Chargify::Product.find_by_handle('tweetsaver')
30
+ product.accounting_code.should == 'TSMO'
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,304 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Subscription do
4
+
5
+ before(:all) do
6
+ Chargify::Config.setup do |config|
7
+ config[:api_key] = 'OU812'
8
+ config[:subdomain] = 'pengwynn'
9
+ end
10
+ end
11
+
12
+ describe '.find' do
13
+
14
+ it "should return info for a subscription" do
15
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/13.json", "subscription.json"
16
+ subscription = Chargify::Subscription.find(13)
17
+ subscription.customer.reference.should == 'bradleyjoyce'
18
+ end
19
+
20
+ it "should return nil if a subscription is not found" do
21
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/18.json", "subscription_not_found.json", 404
22
+ subscription = Chargify::Subscription.find(18)
23
+ subscription.should == nil
24
+ end
25
+
26
+ end
27
+
28
+ describe '.create' do
29
+
30
+ it "should create a customer subscription" do
31
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "subscription.json"
32
+ options = {
33
+ :product_handle => 'monthly',
34
+ :customer_reference => 'bradleyjoyce',
35
+ :customer_attributes => {
36
+ :first_name => "Wynn",
37
+ :last_name => "Netherland",
38
+ :email => "wynn@example.com"
39
+ }
40
+ }
41
+ subscription = Chargify::Subscription.create(options)
42
+ subscription.customer.organization.should == 'Squeejee'
43
+ end
44
+
45
+ it "should create a customer subscription with a coupon code" do
46
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "subscription.json"
47
+ options = {
48
+ :product_handle => 'monthly',
49
+ :customer_reference => 'bradleyjoyce',
50
+ :customer_attributes => {
51
+ :first_name => "Wynn",
52
+ :last_name => "Netherland",
53
+ :email => "wynn@example.com"
54
+ },
55
+ :coupon_code => "EARLYBIRD"
56
+ }
57
+ subscription = Chargify::Subscription.create(options)
58
+ #subscription.coupon.should == 'Squeejee'
59
+ end
60
+
61
+ it "should set success? to true when subscription is created successfully" do
62
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "subscription.json", 201
63
+ options = {
64
+ :product_handle => 'monthly',
65
+ :customer_reference => 'bradleyjoyce',
66
+ :customer_attributes => {
67
+ :first_name => "Wynn",
68
+ :last_name => "Netherland",
69
+ :email => "wynn@example.com"
70
+ }
71
+ }
72
+ subscription = Chargify::Subscription.create(options)
73
+ subscription.success?.should == true
74
+ end
75
+
76
+ it "should set success? to nil when subscription is not created successfully" do
77
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "subscription.json", 400
78
+ options = {
79
+ :product_handle => 'monthly',
80
+ :customer_reference => 'bradleyjoyce',
81
+ :customer_attributes => {
82
+ :first_name => "Wynn",
83
+ :last_name => "Netherland",
84
+ :email => "wynn@example.com"
85
+ }
86
+ }
87
+ subscription = Chargify::Subscription.create(options)
88
+ subscription.success?.should == nil
89
+ end
90
+
91
+ it "should raise UnexpectedResponseError when reponse is invalid JSON" do
92
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "invalid_subscription.json"
93
+ options = {
94
+ :product_handle => 'monthly',
95
+ :customer_reference => 'bradleyjoyce',
96
+ :customer_attributes => {
97
+ :first_name => "Wynn",
98
+ :last_name => "Netherland",
99
+ :email => "wynn@example.com"
100
+ }
101
+ }
102
+ lambda {
103
+ Chargify::Subscription.create(options)
104
+ }.should raise_error(Chargify::Error::UnexpectedResponse)
105
+ end
106
+ end
107
+
108
+ describe '.update' do
109
+
110
+ it "should update a customer subscription" do
111
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "subscription.json"
112
+ options = {
113
+ :product_handle => 'monthly',
114
+ :customer_reference => 'bradleyjoyce',
115
+ :customer_attributes => {
116
+ :first_name => "Wynn",
117
+ :last_name => "Netherland",
118
+ :email => "wynn@example.com"
119
+ }
120
+ }
121
+ subscription = Chargify::Subscription.update(123, options)
122
+ subscription.customer.organization.should == 'Squeejee'
123
+ end
124
+
125
+ it "should set success? to true when subscription is updated successfully" do
126
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "subscription.json", 200
127
+ options = {
128
+ :product_handle => 'monthly',
129
+ :customer_reference => 'bradleyjoyce',
130
+ :customer_attributes => {
131
+ :first_name => "Wynn",
132
+ :last_name => "Netherland",
133
+ :email => "wynn@example.com"
134
+ }
135
+ }
136
+ subscription = Chargify::Subscription.update(123, options)
137
+ subscription.success?.should == true
138
+ end
139
+
140
+ it "should set success? to false when subscription is not updated successfully" do
141
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "subscription.json", 500
142
+ options = {
143
+ :product_handle => 'monthly',
144
+ :customer_reference => 'bradleyjoyce',
145
+ :customer_attributes => {
146
+ :first_name => "Wynn",
147
+ :last_name => "Netherland",
148
+ :email => "wynn@example.com"
149
+ }
150
+ }
151
+ subscription = Chargify::Subscription.update(123, options)
152
+ subscription.success?.should == nil
153
+ end
154
+
155
+ end
156
+
157
+ describe '.reactivate' do
158
+
159
+ it "should reactivate a subscription" do
160
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription.json", 200
161
+ subscription = Chargify::Subscription.reactivate(123)
162
+
163
+ subscription.state.should == "active"
164
+ end
165
+
166
+ it "should set success? to nil when subscription is not reactivated successfully" do
167
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription_not_found.json", 500
168
+ subscription = Chargify::Subscription.reactivate(123)
169
+
170
+ subscription.success?.should == nil
171
+ end
172
+
173
+ it "should set success? to false when subscription is reactivated successfully" do
174
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription.json", 200
175
+ subscription = Chargify::Subscription.reactivate(123)
176
+
177
+ subscription.success?.should == true
178
+ end
179
+
180
+ end
181
+
182
+ describe '.cancel' do
183
+
184
+ it "should cancel subscription" do
185
+ stub_delete "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "deleted_subscription.json", 200
186
+ subscription = Chargify::Subscription.cancel(123)
187
+
188
+ subscription.state.should == "canceled"
189
+ end
190
+
191
+ it "should set success? to nil when subscription is not cancelled successfully" do
192
+ stub_delete "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "deleted_subscription.json", 500
193
+ subscription = Chargify::Subscription.cancel(123)
194
+
195
+ subscription.success?.should == nil
196
+ end
197
+
198
+ it "should set success? to true when subscription is cancelled successfully" do
199
+ stub_delete "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "deleted_subscription.json", 200
200
+ subscription = Chargify::Subscription.cancel(123)
201
+
202
+ subscription.success?.should == true
203
+ end
204
+
205
+ end
206
+
207
+
208
+ describe '.charge' do
209
+
210
+ before do
211
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions/123/charges.json", "charge_subscription.json", 201
212
+ @options = {
213
+ :memo => "This is the description of the one time charge.",
214
+ :amount => 1.00,
215
+ :amount_in_cents => 100
216
+ }
217
+ end
218
+
219
+ it "should accept :amount as a parameter" do
220
+ subscription = Chargify::Subscription.charge(123, @options)
221
+
222
+ subscription.amount_in_cents.should == @options[:amount]*100
223
+ subscription.success?.should == true
224
+ end
225
+
226
+ it "should accept :amount_in_cents as a parameter" do
227
+ subscription = Chargify::Subscription.charge(123, @options)
228
+
229
+ subscription.amount_in_cents.should == @options[:amount_in_cents]
230
+ subscription.success?.should == true
231
+ end
232
+
233
+ it "should have success? as false if parameters are missing" do
234
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions/123/charges.json", "charge_subscription_missing_parameters.json", 422
235
+
236
+ subscription = Chargify::Subscription.charge(123, {})
237
+ subscription.success?.should == false
238
+ end
239
+
240
+ it "should have success? as false if the subscription is not found" do
241
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions/9999/charges.json", "", 404
242
+
243
+ subscription = Chargify::Subscription.charge(9999, @options)
244
+ subscription.success?.should == false
245
+ end
246
+
247
+ end
248
+
249
+ describe '.migrate' do
250
+
251
+ it "should migrate a subscription from one product to another" do
252
+ stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions/123/migrations.json", "migrate_subscription.json"
253
+
254
+ subscription = Chargify::Subscription.migrate(123, 354);
255
+ subscription.success?.should == true
256
+ subscription.product.id.should == 354
257
+ end
258
+
259
+ end
260
+
261
+ describe '.components' do
262
+
263
+ it "should list components" do
264
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components.json", "components.json"
265
+ components = Chargify::Subscription.components(123)
266
+ components.first.allocated_quantity.should == 42
267
+ components.last.allocated_quantity.should == 2
268
+ end
269
+
270
+ end
271
+
272
+ describe '.find_component' do
273
+
274
+ it "should show a specific component" do
275
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/16.json", "component.json"
276
+ component = Chargify::Subscription.find_component(123, 16)
277
+ component.name.should == "Extra Rubies"
278
+ component.allocated_quantity.should == 42
279
+ end
280
+
281
+ end
282
+
283
+ describe '.update_component' do
284
+
285
+ it "should update the allocated_quantity for a component" do
286
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/16.json", "component.json"
287
+ response = Chargify::Subscription.update_component(123, 16, 20_000_000)
288
+ response.success?.should == true
289
+ end
290
+
291
+ end
292
+
293
+ describe '.component_usage' do
294
+
295
+ it "should list usage for a subscription" do
296
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/456/usages.json", "list_metered_subscriptions.json", 200
297
+
298
+ subscription = Chargify::Subscription.component_usage(123, 456)
299
+ subscription.success?.should == true
300
+ end
301
+
302
+ end
303
+
304
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chargify::Transaction do
4
+
5
+ describe '.all' do
6
+
7
+ it "should return all transactions"
8
+
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsmestad-chargify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ - pre5
10
+ version: 0.3.0.pre5
11
+ platform: ruby
12
+ authors:
13
+ - Wynn Netherland
14
+ - Justin Smestad
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-07-11 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :runtime
24
+ name: httparty
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ - 6
32
+ - 1
33
+ version: 0.6.1
34
+ requirement: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :runtime
38
+ name: hashie
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 1
46
+ - 8
47
+ version: 0.1.8
48
+ requirement: *id002
49
+ prerelease: false
50
+ - !ruby/object:Gem::Dependency
51
+ type: :runtime
52
+ name: json
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirement: *id003
61
+ prerelease: false
62
+ description:
63
+ email: justin.smestad@gmail.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.markdown
71
+ files:
72
+ - .gitignore
73
+ - Gemfile
74
+ - LICENSE
75
+ - README.markdown
76
+ - Rakefile
77
+ - VERSION
78
+ - changelog.md
79
+ - jsmestad-chargify.gemspec
80
+ - lib/chargify.rb
81
+ - lib/chargify/base.rb
82
+ - lib/chargify/config.rb
83
+ - lib/chargify/customer.rb
84
+ - lib/chargify/error.rb
85
+ - lib/chargify/parser.rb
86
+ - lib/chargify/product.rb
87
+ - lib/chargify/subscription.rb
88
+ - lib/chargify/transaction.rb
89
+ - spec/fixtures/charge_subscription.json
90
+ - spec/fixtures/charge_subscription_missing_parameters.json
91
+ - spec/fixtures/component.json
92
+ - spec/fixtures/components.json
93
+ - spec/fixtures/customer.json
94
+ - spec/fixtures/customers.json
95
+ - spec/fixtures/deleted_subscription.json
96
+ - spec/fixtures/invalid_subscription.json
97
+ - spec/fixtures/list_metered_subscriptions.json
98
+ - spec/fixtures/migrate_subscription.json
99
+ - spec/fixtures/new_customer.json
100
+ - spec/fixtures/product.json
101
+ - spec/fixtures/products.json
102
+ - spec/fixtures/subscription.json
103
+ - spec/fixtures/subscription_not_found.json
104
+ - spec/fixtures/subscriptions.json
105
+ - spec/spec.opts
106
+ - spec/spec_helper.rb
107
+ - spec/support/fakeweb_stubs.rb
108
+ - spec/unit/chargify/config_spec.rb
109
+ - spec/unit/chargify/customer_spec.rb
110
+ - spec/unit/chargify/parser_spec.rb
111
+ - spec/unit/chargify/product_spec.rb
112
+ - spec/unit/chargify/subscription_spec.rb
113
+ - spec/unit/chargify/transaction_spec.rb
114
+ has_rdoc: true
115
+ homepage: http://github.com/jsmestad/chargify
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options:
120
+ - --charset=UTF-8
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">"
133
+ - !ruby/object:Gem::Version
134
+ segments:
135
+ - 1
136
+ - 3
137
+ - 1
138
+ version: 1.3.1
139
+ requirements: []
140
+
141
+ rubyforge_project:
142
+ rubygems_version: 1.3.6
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Ruby wrapper for the Chargify API
146
+ test_files:
147
+ - spec/spec_helper.rb
148
+ - spec/support/fakeweb_stubs.rb
149
+ - spec/unit/chargify/config_spec.rb
150
+ - spec/unit/chargify/customer_spec.rb
151
+ - spec/unit/chargify/parser_spec.rb
152
+ - spec/unit/chargify/product_spec.rb
153
+ - spec/unit/chargify/subscription_spec.rb
154
+ - spec/unit/chargify/transaction_spec.rb