chargify 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -7
- data/changelog.md +6 -1
- data/chargify.gemspec +18 -72
- data/lib/chargify.rb +1 -1
- data/lib/chargify/client.rb +13 -0
- data/test/chargify_test.rb +21 -2
- data/test/fixtures/charge_subscription.json +5 -0
- data/test/fixtures/charge_subscription_missing_parameters.json +4 -0
- data/test/fixtures/component.json +11 -0
- data/test/fixtures/components.json +24 -0
- data/test/fixtures/list_metered_subscriptions.json +3 -0
- data/test/fixtures/migrate_subscription.json +51 -0
- data/test/helper.rb +4 -4
- metadata +30 -60
- data/VERSION +0 -1
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require "mg"
|
2
|
-
require 'active_support/inflector'
|
3
2
|
require 'shoulda/tasks'
|
4
3
|
|
5
|
-
|
6
4
|
MG.new("chargify.gemspec")
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
test.libs << 'lib' << 'test'
|
12
|
-
test.pattern = 'test/**/*_test.rb'
|
6
|
+
desc 'Run tests'
|
7
|
+
task :test do
|
8
|
+
sh 'testrb -I.:lib test/*_test.rb'
|
13
9
|
end
|
14
10
|
|
15
11
|
task :default => :test
|
data/changelog.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.0 May 21, 2011
|
4
|
+
* Add api calls: adjust_subscription and subscription_statements
|
5
|
+
* Get tests to work on 1.9.2
|
6
|
+
* Updated development dependencies
|
7
|
+
|
3
8
|
## 0.2.6 May 27, 2010
|
4
9
|
* Fix #charge_subscription to submit it's body as json [@will](http://github.com/will) and [@ignat](http://github.com/ignat)
|
5
10
|
* API coverage for quantity components [@will](http://github.com/will)
|
@@ -18,4 +23,4 @@
|
|
18
23
|
|
19
24
|
## 0.1.0 November 18, 2009
|
20
25
|
|
21
|
-
* Initial version
|
26
|
+
* Initial version
|
data/chargify.gemspec
CHANGED
@@ -1,82 +1,28 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
3
|
+
require File.dirname(__FILE__) + '/lib/chargify.rb'
|
4
|
+
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = %q{chargify}
|
8
|
-
s.version =
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
|
+
s.version = Chargify::VERSION.dup
|
11
8
|
s.authors = ["Wynn Netherland", "Nash Kabbara"]
|
12
|
-
s.date = %q{2010-05-24}
|
13
|
-
s.description = %q{Ruby wrapper for the chargify.com SAAS and billing API}
|
14
9
|
s.email = %q{wynn.netherland@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.markdown"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.markdown",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"changelog.md",
|
27
|
-
"chargify.gemspec",
|
28
|
-
"lib/chargify.rb",
|
29
|
-
"lib/chargify/client.rb",
|
30
|
-
"test/fixtures/customer.json",
|
31
|
-
"test/fixtures/customers.json",
|
32
|
-
"test/fixtures/deleted_subscription.json",
|
33
|
-
"test/fixtures/invalid_subscription.json",
|
34
|
-
"test/fixtures/new_customer.json",
|
35
|
-
"test/fixtures/product.json",
|
36
|
-
"test/fixtures/products.json",
|
37
|
-
"test/fixtures/subscription.json",
|
38
|
-
"test/fixtures/subscription_not_found.json",
|
39
|
-
"test/fixtures/subscriptions.json",
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/chargify_test.rb"
|
42
|
-
]
|
43
10
|
s.homepage = %q{http://github.com/pengwynn/chargify}
|
44
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
-
s.require_paths = ["lib"]
|
46
|
-
s.rubygems_version = %q{1.3.6}
|
47
11
|
s.summary = %q{Ruby wrapper for the chargify.com SAAS and billing API}
|
48
|
-
s.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
s.specification_version = 3
|
12
|
+
s.description = %q{Ruby wrapper for the chargify.com SAAS and billing API using httparty}
|
13
|
+
s.extra_rdoc_files = [ "LICENSE", "README.markdown" ]
|
14
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
15
|
+
s.required_rubygems_version = ">= 1.3.6"
|
16
|
+
s.files = %w{.document .gitignore LICENSE README.markdown Rakefile changelog.md chargify.gemspec} +
|
17
|
+
Dir.glob(['{lib,test}/**/*.rb', 'test/fixtures/*.json'])
|
18
|
+
s.test_files = [ "test/helper.rb", "test/chargify_test.rb" ]
|
56
19
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
else
|
66
|
-
s.add_dependency(%q<hashie>, ["~> 0.1.3"])
|
67
|
-
s.add_dependency(%q<httparty>, ["~> 0.5.2"])
|
68
|
-
s.add_dependency(%q<shoulda>, [">= 2.10.1"])
|
69
|
-
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
70
|
-
s.add_dependency(%q<mocha>, ["~> 0.9.8"])
|
71
|
-
s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
|
72
|
-
end
|
73
|
-
else
|
74
|
-
s.add_dependency(%q<hashie>, ["~> 0.1.3"])
|
75
|
-
s.add_dependency(%q<httparty>, ["~> 0.5.2"])
|
76
|
-
s.add_dependency(%q<shoulda>, [">= 2.10.1"])
|
77
|
-
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
78
|
-
s.add_dependency(%q<mocha>, ["~> 0.9.8"])
|
79
|
-
s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
|
80
|
-
end
|
20
|
+
s.add_runtime_dependency(%q<hashie>, ["~> 1.0.0"])
|
21
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.7.4"])
|
22
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.10.1"])
|
23
|
+
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
24
|
+
s.add_development_dependency(%q<mocha>, ["~> 0.9.8"])
|
25
|
+
s.add_development_dependency(%q<fakeweb>, [">= 1.2.5"])
|
26
|
+
s.add_development_dependency('mg', ['>= 0.0.8'])
|
27
|
+
s.add_development_dependency('test-unit', ['>= 2.3.0'])
|
81
28
|
end
|
82
|
-
|
data/lib/chargify.rb
CHANGED
data/lib/chargify/client.rb
CHANGED
@@ -144,6 +144,14 @@ module Chargify
|
|
144
144
|
(response.subscription || {}).update(:success? => success)
|
145
145
|
end
|
146
146
|
|
147
|
+
def adjust_subscription(sub_id, attributes = {})
|
148
|
+
raw_response = post("/subscriptions/#{sub_id}/adjustments.json",
|
149
|
+
:body => { :adjustment => attributes })
|
150
|
+
created = true if raw_response.code == 201
|
151
|
+
response = Hashie::Mash.new(raw_response)
|
152
|
+
(response.adjustment || response).update(:success? => created)
|
153
|
+
end
|
154
|
+
|
147
155
|
def list_products
|
148
156
|
products = get("/products.json")
|
149
157
|
products.map{|p| Hashie::Mash.new p['product']}
|
@@ -169,6 +177,11 @@ module Chargify
|
|
169
177
|
transactions.map{|t| Hashie::Mash.new t['transaction']}
|
170
178
|
end
|
171
179
|
|
180
|
+
def subscription_statements(sub_id, options={})
|
181
|
+
statements = get("/subscriptions/#{sub_id}/statements.json", :query => options)
|
182
|
+
statements.map{|t| Hashie::Mash.new t['statement']}
|
183
|
+
end
|
184
|
+
|
172
185
|
def site_transactions(options={})
|
173
186
|
transactions = get("/transactions.json", :query => options)
|
174
187
|
transactions.map{|t| Hashie::Mash.new t['transaction']}
|
data/test/chargify_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'helper'
|
1
|
+
require 'test/helper'
|
2
2
|
|
3
3
|
class ChargifyTest < Test::Unit::TestCase
|
4
4
|
context "Chargify API client" do
|
@@ -305,7 +305,14 @@ class ChargifyTest < Test::Unit::TestCase
|
|
305
305
|
subscription.success?.should == true
|
306
306
|
subscription.product.id.should == 354
|
307
307
|
end
|
308
|
-
|
308
|
+
|
309
|
+
should "adjust a subscription" do
|
310
|
+
@client.expects(:post).with("/subscriptions/123/adjustments.json", :body => {:adjustment => {}}).
|
311
|
+
returns(Hashie::Mash.new(:adjustment => {}, :code => 201))
|
312
|
+
response = @client.adjust_subscription 123
|
313
|
+
response.success?.should == true
|
314
|
+
end
|
315
|
+
|
309
316
|
should "return a list of products" do
|
310
317
|
stub_get "https://OU812:x@pengwynn.chargify.com/products.json", "products.json"
|
311
318
|
products = @client.list_products
|
@@ -385,6 +392,18 @@ class ChargifyTest < Test::Unit::TestCase
|
|
385
392
|
end
|
386
393
|
end
|
387
394
|
|
395
|
+
should "return a list of transactions" do
|
396
|
+
@client.expects(:get).with("/subscriptions/123/transactions.json", :query => {}).
|
397
|
+
returns([{:transaction => {}}])
|
398
|
+
@client.subscription_transactions 123
|
399
|
+
end
|
400
|
+
|
401
|
+
should "return a list of statements" do
|
402
|
+
@client.expects(:get).with("/subscriptions/123/statements.json", :query => {}).
|
403
|
+
returns([{:statement => {}}])
|
404
|
+
@client.subscription_statements 123
|
405
|
+
end
|
406
|
+
|
388
407
|
context "aliased methods" do
|
389
408
|
setup do
|
390
409
|
stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/16.json", "component.json"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"component": {
|
4
|
+
"kind": "quantity_based_component",
|
5
|
+
"name": "Extra Rubies",
|
6
|
+
"allocated_quantity": 42,
|
7
|
+
"subscription_id": 16,
|
8
|
+
"pricing_scheme": "per_unit",
|
9
|
+
"component_id": 84,
|
10
|
+
"unit_name": "band"
|
11
|
+
}
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"component": {
|
15
|
+
"kind": "quantity_based_component",
|
16
|
+
"name": "IP addresses",
|
17
|
+
"allocated_quantity": 2,
|
18
|
+
"subscription_id": 16,
|
19
|
+
"pricing_scheme": "per_unit",
|
20
|
+
"component_id": 24,
|
21
|
+
"unit_name": "address"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
{
|
2
|
+
"subscription": {
|
3
|
+
"id": 123,
|
4
|
+
"state": "active",
|
5
|
+
"balance_in_cents": "auto generated",
|
6
|
+
"current_period_started_at": "auto generated",
|
7
|
+
"current_period_ends_at": "auto generated",
|
8
|
+
"activated_at": "auto generated",
|
9
|
+
"trial_ended_at": "auto generated",
|
10
|
+
"trial_started_at": "auto generated",
|
11
|
+
"expires_at": "auto generated",
|
12
|
+
"created_at": "auto generated",
|
13
|
+
"updated_at": "auto generated",
|
14
|
+
"cancellation_message": null,
|
15
|
+
"customer": {
|
16
|
+
"id": "auto generated",
|
17
|
+
"first_name": "your value",
|
18
|
+
"last_name": "your value",
|
19
|
+
"email": "your value",
|
20
|
+
"organization": "your value",
|
21
|
+
"reference": "your value",
|
22
|
+
"updated_at": "auto generated",
|
23
|
+
"created_at": "auto generated"
|
24
|
+
},
|
25
|
+
"product": {
|
26
|
+
"id": 354,
|
27
|
+
"name": "[@products.last.name]",
|
28
|
+
"handle": 354,
|
29
|
+
"price_in_cents": 1000,
|
30
|
+
"accounting_code": "[@products.last.accounting_code]",
|
31
|
+
"description": "your value",
|
32
|
+
"interval": 3600,
|
33
|
+
"interval_unit": "[@products.last.interval_unit]",
|
34
|
+
"product_family": {
|
35
|
+
"id": 15,
|
36
|
+
"name": "[@products.last.product_family.name]",
|
37
|
+
"handle": "[@products.last.product_family.handle]",
|
38
|
+
"accounting_code": "[@products.last.product_family.accounting_code]",
|
39
|
+
"description": "your value"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"credit_card": {
|
43
|
+
"first_name": "your value",
|
44
|
+
"last_name": "your value",
|
45
|
+
"masked_card_number": "your value",
|
46
|
+
"card_type": "auto generated",
|
47
|
+
"expiration_month": "your value",
|
48
|
+
"expiration_year": "your value"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
data/test/helper.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
unless ENV['NO_RUBYGEMS']
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'test-unit'
|
4
|
+
end
|
1
5
|
require 'test/unit'
|
2
6
|
require 'pathname'
|
3
7
|
|
@@ -5,10 +9,6 @@ require 'shoulda'
|
|
5
9
|
require 'matchy'
|
6
10
|
require 'mocha'
|
7
11
|
require 'fakeweb'
|
8
|
-
require 'redgreen'
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
12
|
require 'chargify'
|
13
13
|
|
14
14
|
class Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 8
|
10
|
-
version: 0.2.8
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Wynn Netherland
|
@@ -16,7 +11,7 @@ autorequire:
|
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
13
|
|
19
|
-
date:
|
14
|
+
date: 2011-05-21 00:00:00 -04:00
|
20
15
|
default_executable:
|
21
16
|
dependencies:
|
22
17
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +22,7 @@ dependencies:
|
|
27
22
|
requirements:
|
28
23
|
- - ~>
|
29
24
|
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
segments:
|
32
|
-
- 0
|
33
|
-
- 1
|
34
|
-
- 3
|
35
|
-
version: 0.1.3
|
25
|
+
version: 1.0.0
|
36
26
|
type: :runtime
|
37
27
|
version_requirements: *id001
|
38
28
|
- !ruby/object:Gem::Dependency
|
@@ -43,12 +33,7 @@ dependencies:
|
|
43
33
|
requirements:
|
44
34
|
- - ~>
|
45
35
|
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
- 5
|
50
|
-
- 2
|
51
|
-
version: 0.5.2
|
36
|
+
version: 0.7.4
|
52
37
|
type: :runtime
|
53
38
|
version_requirements: *id002
|
54
39
|
- !ruby/object:Gem::Dependency
|
@@ -59,11 +44,6 @@ dependencies:
|
|
59
44
|
requirements:
|
60
45
|
- - ">="
|
61
46
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 37
|
63
|
-
segments:
|
64
|
-
- 2
|
65
|
-
- 10
|
66
|
-
- 1
|
67
47
|
version: 2.10.1
|
68
48
|
type: :development
|
69
49
|
version_requirements: *id003
|
@@ -75,11 +55,6 @@ dependencies:
|
|
75
55
|
requirements:
|
76
56
|
- - "="
|
77
57
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 15
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
- 4
|
82
|
-
- 0
|
83
58
|
version: 0.4.0
|
84
59
|
type: :development
|
85
60
|
version_requirements: *id004
|
@@ -91,11 +66,6 @@ dependencies:
|
|
91
66
|
requirements:
|
92
67
|
- - ~>
|
93
68
|
- !ruby/object:Gem::Version
|
94
|
-
hash: 43
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
- 9
|
98
|
-
- 8
|
99
69
|
version: 0.9.8
|
100
70
|
type: :development
|
101
71
|
version_requirements: *id005
|
@@ -107,31 +77,32 @@ dependencies:
|
|
107
77
|
requirements:
|
108
78
|
- - ">="
|
109
79
|
- !ruby/object:Gem::Version
|
110
|
-
hash: 21
|
111
|
-
segments:
|
112
|
-
- 1
|
113
|
-
- 2
|
114
|
-
- 5
|
115
80
|
version: 1.2.5
|
116
81
|
type: :development
|
117
82
|
version_requirements: *id006
|
118
83
|
- !ruby/object:Gem::Dependency
|
119
|
-
name:
|
84
|
+
name: mg
|
120
85
|
prerelease: false
|
121
86
|
requirement: &id007 !ruby/object:Gem::Requirement
|
122
87
|
none: false
|
123
88
|
requirements:
|
124
89
|
- - ">="
|
125
90
|
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
segments:
|
128
|
-
- 1
|
129
|
-
- 2
|
130
|
-
- 2
|
131
|
-
version: 1.2.2
|
91
|
+
version: 0.0.8
|
132
92
|
type: :development
|
133
93
|
version_requirements: *id007
|
134
|
-
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: test-unit
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.3.0
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id008
|
105
|
+
description: Ruby wrapper for the chargify.com SAAS and billing API using httparty
|
135
106
|
email: wynn.netherland@gmail.com
|
136
107
|
executables: []
|
137
108
|
|
@@ -146,23 +117,28 @@ files:
|
|
146
117
|
- LICENSE
|
147
118
|
- README.markdown
|
148
119
|
- Rakefile
|
149
|
-
- VERSION
|
150
120
|
- changelog.md
|
151
121
|
- chargify.gemspec
|
152
|
-
- lib/chargify.rb
|
153
122
|
- lib/chargify/client.rb
|
123
|
+
- lib/chargify.rb
|
124
|
+
- test/chargify_test.rb
|
125
|
+
- test/helper.rb
|
126
|
+
- test/fixtures/charge_subscription.json
|
127
|
+
- test/fixtures/charge_subscription_missing_parameters.json
|
128
|
+
- test/fixtures/component.json
|
129
|
+
- test/fixtures/components.json
|
154
130
|
- test/fixtures/customer.json
|
155
131
|
- test/fixtures/customers.json
|
156
132
|
- test/fixtures/deleted_subscription.json
|
157
133
|
- test/fixtures/invalid_subscription.json
|
134
|
+
- test/fixtures/list_metered_subscriptions.json
|
135
|
+
- test/fixtures/migrate_subscription.json
|
158
136
|
- test/fixtures/new_customer.json
|
159
137
|
- test/fixtures/product.json
|
160
138
|
- test/fixtures/products.json
|
161
139
|
- test/fixtures/subscription.json
|
162
140
|
- test/fixtures/subscription_not_found.json
|
163
141
|
- test/fixtures/subscriptions.json
|
164
|
-
- test/helper.rb
|
165
|
-
- test/chargify_test.rb
|
166
142
|
has_rdoc: true
|
167
143
|
homepage: http://github.com/pengwynn/chargify
|
168
144
|
licenses: []
|
@@ -177,23 +153,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
153
|
requirements:
|
178
154
|
- - ">="
|
179
155
|
- !ruby/object:Gem::Version
|
180
|
-
hash: 3
|
181
|
-
segments:
|
182
|
-
- 0
|
183
156
|
version: "0"
|
184
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
158
|
none: false
|
186
159
|
requirements:
|
187
160
|
- - ">="
|
188
161
|
- !ruby/object:Gem::Version
|
189
|
-
|
190
|
-
segments:
|
191
|
-
- 0
|
192
|
-
version: "0"
|
162
|
+
version: 1.3.6
|
193
163
|
requirements: []
|
194
164
|
|
195
165
|
rubyforge_project:
|
196
|
-
rubygems_version: 1.
|
166
|
+
rubygems_version: 1.6.2
|
197
167
|
signing_key:
|
198
168
|
specification_version: 3
|
199
169
|
summary: Ruby wrapper for the chargify.com SAAS and billing API
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.7
|