chargify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +25 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/lib/chargify.rb +16 -0
- data/lib/chargify/client.rb +104 -0
- data/test/fixtures/customer.json +12 -0
- data/test/fixtures/customers.json +12 -0
- data/test/fixtures/new_customer.json +12 -0
- data/test/fixtures/product.json +17 -0
- data/test/fixtures/products.json +17 -0
- data/test/fixtures/subscription.json +49 -0
- data/test/fixtures/subscriptions.json +49 -0
- data/test/helper.rb +54 -0
- data/test/test_chargify.rb +96 -0
- metadata +132 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wynn Netherland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= chargify
|
2
|
+
|
3
|
+
Ruby wrapper for the chargify.com SAAS and billing API
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install gemcutter
|
8
|
+
gem tumble
|
9
|
+
sudo gem install chargify
|
10
|
+
|
11
|
+
|
12
|
+
== Note on Patches/Pull Requests
|
13
|
+
|
14
|
+
* Fork the project.
|
15
|
+
* Make your feature addition or bug fix.
|
16
|
+
* Add tests for it. This is important so I don't break it in a
|
17
|
+
future version unintentionally.
|
18
|
+
* Commit, do not mess with rakefile, version, or history.
|
19
|
+
(if you want to have your own version, that is fine but
|
20
|
+
bump version in a commit by itself I can ignore when I pull)
|
21
|
+
* Send me a pull request. Bonus points for topic branches.
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2009 Wynn Netherland. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "chargify"
|
8
|
+
gem.summary = %Q{Ruby wrapper for the chargify.com SAAS and billing API}
|
9
|
+
gem.description = %Q{Ruby wrapper for the chargify.com SAAS and billing API}
|
10
|
+
gem.email = "wynn.netherland@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/pengwynn/chargify"
|
12
|
+
gem.authors = ["Wynn Netherland"]
|
13
|
+
|
14
|
+
gem.add_dependency('hashie', '~> 0.1.3')
|
15
|
+
gem.add_dependency('httparty', '~> 0.4.5')
|
16
|
+
|
17
|
+
gem.add_development_dependency('thoughtbot-shoulda', '>= 2.10.1')
|
18
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
19
|
+
gem.add_development_dependency('mocha', '0.9.4')
|
20
|
+
gem.add_development_dependency('fakeweb', '>= 1.2.5')
|
21
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :test => :check_dependencies
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
Rake::RDocTask.new do |rdoc|
|
54
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "chargify #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/chargify.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'oauth', '~> 0.3.5'
|
4
|
+
require 'oauth'
|
5
|
+
|
6
|
+
gem 'hashie', '~> 0.1.3'
|
7
|
+
require 'hashie'
|
8
|
+
|
9
|
+
gem 'httparty', '~> 0.4.5'
|
10
|
+
require 'httparty'
|
11
|
+
|
12
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
13
|
+
|
14
|
+
Hash.send :include, Hashie::HashExtensions
|
15
|
+
|
16
|
+
require File.join(directory, 'chargify', 'client')
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Chargify
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
format :json
|
5
|
+
|
6
|
+
attr_reader :api_key, :subdomain
|
7
|
+
|
8
|
+
# Your API key can be generated on the settings screen.
|
9
|
+
def initialize(api_key, subdomain)
|
10
|
+
@api_key = api_key
|
11
|
+
@subdomain = subdomain
|
12
|
+
|
13
|
+
self.class.base_uri "https://#{@subdomain}.chargify.com"
|
14
|
+
self.class.basic_auth @api_key, 'x'
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# options: page
|
19
|
+
def list_customers(options={})
|
20
|
+
customers = self.class.get("/customers.json", :query => options)
|
21
|
+
customers.map{|c| Hashie::Mash.new c['customer']}
|
22
|
+
end
|
23
|
+
|
24
|
+
def customer(chargify_id)
|
25
|
+
Hashie::Mash.new(self.class.get("/customers/#{chargify_id}.json")).customer
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# * first_name (Required)
|
30
|
+
# * last_name (Required)
|
31
|
+
# * email (Required)
|
32
|
+
# * organization (Optional) Company/Organization name
|
33
|
+
# * reference (Optional, but encouraged) The unique identifier used within your own application for this customer
|
34
|
+
#
|
35
|
+
def create_customer(info={})
|
36
|
+
response = Hashie::Mash.new(self.class.post("/customers.json", :body => {:customer => info}))
|
37
|
+
return response.customer unless response.customer.blank?
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# * first_name (Required)
|
43
|
+
# * last_name (Required)
|
44
|
+
# * email (Required)
|
45
|
+
# * organization (Optional) Company/Organization name
|
46
|
+
# * reference (Optional, but encouraged) The unique identifier used within your own application for this customer
|
47
|
+
#
|
48
|
+
def update_customer(info={})
|
49
|
+
info.stringify_keys!
|
50
|
+
chargify_id = info.delete('id')
|
51
|
+
response = Hashie::Mash.new(self.class.put("/customers/#{chargify_id}.json", :body => {:customer => info}))
|
52
|
+
return response.customer unless response.customer.blank?
|
53
|
+
response
|
54
|
+
end
|
55
|
+
|
56
|
+
def customer_subscriptions(chargify_id)
|
57
|
+
subscriptions = self.class.get("/customers/#{chargify_id}/subscriptions.json")
|
58
|
+
subscriptions.map{|s| Hashie::Mash.new s['subscription']}
|
59
|
+
end
|
60
|
+
|
61
|
+
def subscription(subscription_id)
|
62
|
+
Hashie::Mash.new(self.class.get("/subscriptions/#{subscription_id}.json")).subscription
|
63
|
+
end
|
64
|
+
|
65
|
+
# When creating a subscription, you must specify a product, a customer, and payment (credit card) details.
|
66
|
+
#
|
67
|
+
# The product may be specified by product_id or by product_handle (API Handle).
|
68
|
+
#
|
69
|
+
# An existing customer may be specified by a customer_id (ID within Chargify) or a customer_reference (unique value within your app that you have shared with Chargify via the reference attribute on a customer). A new customer may be created by providing customer_attributes.
|
70
|
+
#
|
71
|
+
# * product_handle The API Handle of the product for which you are creating a subscription. Required, unless a product_id is given instead.
|
72
|
+
# * product_id The Product ID of the product for which you are creating a subscription. The product ID is not currently published, so we recommend using the API Handle instead.
|
73
|
+
# * customer_id The ID of an existing customer within Chargify. Required, unless a customer_reference or a set of customer_attributes is given.
|
74
|
+
# * customer_reference The reference value (provided by your app) of an existing customer within Chargify. Required, unless a customer_id or a set of customer_attributes is given.
|
75
|
+
# * customer_attributes
|
76
|
+
# o first_name The first name of the customer. Required when creating a customer via attributes.
|
77
|
+
# o last_name The last name of the customer. Required when creating a customer via attributes.
|
78
|
+
# o email The email address of the customer. Required when creating a customer via attributes.
|
79
|
+
# o organization The organization/company of the customer. Optional.
|
80
|
+
# o reference A customer "reference", or unique identifier from your app, stored in Chargify. Can be used so that you may reference your customers within Chargify using the same unique value you use in your application. Optional.
|
81
|
+
#
|
82
|
+
def create_subscription(options, customer_attributes={})
|
83
|
+
options.merge({:customer_attributes => customer_attributes}) unless customer_attributes.blank?
|
84
|
+
response = Hashie::Mash.new(self.class.post("/subscriptions.json", :body => options))
|
85
|
+
return response.subscription unless response.subscription.blank?
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
def list_products
|
90
|
+
products = self.class.get("/products.json")
|
91
|
+
products.map{|p| Hashie::Mash.new p['product']}
|
92
|
+
end
|
93
|
+
|
94
|
+
def product(product_id)
|
95
|
+
Hashie::Mash.new( self.class.get("/products/#{product_id}.json")).product
|
96
|
+
end
|
97
|
+
|
98
|
+
def product_by_handle(handle)
|
99
|
+
Hashie::Mash.new(self.class.get("/products/handle/#{handle}.json")).product
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"customer": {
|
3
|
+
"reference": "bradleyjoyce",
|
4
|
+
"updated_at": "2009-10-07T11:10:27-04:00",
|
5
|
+
"id": 16,
|
6
|
+
"organization": "Squeejee",
|
7
|
+
"first_name": "Bradley",
|
8
|
+
"last_name": "Joyce",
|
9
|
+
"email": "bradley@squeejee.com",
|
10
|
+
"created_at": "2009-10-07T11:10:27-04:00"
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
[{
|
2
|
+
"customer": {
|
3
|
+
"reference": "bradleyjoyce",
|
4
|
+
"updated_at": "2009-10-07T11:10:27-04:00",
|
5
|
+
"id": 16,
|
6
|
+
"organization": "Squeejee",
|
7
|
+
"first_name": "Bradley",
|
8
|
+
"last_name": "Joyce",
|
9
|
+
"email": "bradley@squeejee.com",
|
10
|
+
"created_at": "2009-10-07T11:10:27-04:00"
|
11
|
+
}
|
12
|
+
}]
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"customer": {
|
3
|
+
"created_at": "2009-11-18T10:56:22-05:00",
|
4
|
+
"email": "wynn.netherland@gmail.com",
|
5
|
+
"first_name": "Wynn",
|
6
|
+
"id": 333,
|
7
|
+
"last_name": "Netherland",
|
8
|
+
"organization": null,
|
9
|
+
"reference": null,
|
10
|
+
"updated_at": "2009-11-18T10:56:22-05:00"
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"product": {
|
3
|
+
"price_in_cents": 500,
|
4
|
+
"name": "Monthly",
|
5
|
+
"handle": "monthly",
|
6
|
+
"id": 8,
|
7
|
+
"accounting_code": "TSMO",
|
8
|
+
"product_family": {
|
9
|
+
"name": "TweetSaver",
|
10
|
+
"handle": "tweetsaver",
|
11
|
+
"id": 7,
|
12
|
+
"accounting_code": null
|
13
|
+
},
|
14
|
+
"interval_unit": "month",
|
15
|
+
"interval": 1
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
[{
|
2
|
+
"product": {
|
3
|
+
"price_in_cents": 500,
|
4
|
+
"name": "Monthly",
|
5
|
+
"handle": "monthly",
|
6
|
+
"id": 8,
|
7
|
+
"accounting_code": "TSMO",
|
8
|
+
"product_family": {
|
9
|
+
"name": "TweetSaver",
|
10
|
+
"handle": "tweetsaver",
|
11
|
+
"id": 7,
|
12
|
+
"accounting_code": null
|
13
|
+
},
|
14
|
+
"interval_unit": "month",
|
15
|
+
"interval": 1
|
16
|
+
}
|
17
|
+
}]
|
@@ -0,0 +1,49 @@
|
|
1
|
+
{
|
2
|
+
"subscription": {
|
3
|
+
"customer": {
|
4
|
+
"reference": "bradleyjoyce",
|
5
|
+
"updated_at": "2009-10-07T11:10:27-04:00",
|
6
|
+
"id": 16,
|
7
|
+
"organization": "Squeejee",
|
8
|
+
"first_name": "Bradley",
|
9
|
+
"last_name": "Joyce",
|
10
|
+
"email": "bradley@squeejee.com",
|
11
|
+
"created_at": "2009-10-07T11:10:27-04:00"
|
12
|
+
},
|
13
|
+
"cancellation_message": null,
|
14
|
+
"updated_at": "2009-10-07T11:10:56-04:00",
|
15
|
+
"expires_at": null,
|
16
|
+
"activated_at": "2009-10-23T16:16:59-04:00",
|
17
|
+
"current_period_started_at": "2009-11-14T11:10:56-05:00",
|
18
|
+
"credit_card": {
|
19
|
+
"card_type": "bogus",
|
20
|
+
"expiration_year": 2015,
|
21
|
+
"masked_card_number": "XXXX-XXXX-XXXX-1",
|
22
|
+
"first_name": "Bradley",
|
23
|
+
"last_name": "Joyce",
|
24
|
+
"expiration_month": 7
|
25
|
+
},
|
26
|
+
"trial_ended_at": "2009-10-14T11:10:56-04:00",
|
27
|
+
"id": 14,
|
28
|
+
"product": {
|
29
|
+
"price_in_cents": 500,
|
30
|
+
"name": "Monthly",
|
31
|
+
"handle": "monthly",
|
32
|
+
"id": 8,
|
33
|
+
"accounting_code": "TSMO",
|
34
|
+
"product_family": {
|
35
|
+
"name": "TweetSaver",
|
36
|
+
"handle": "tweetsaver",
|
37
|
+
"id": 7,
|
38
|
+
"accounting_code": null
|
39
|
+
},
|
40
|
+
"interval_unit": "month",
|
41
|
+
"interval": 1
|
42
|
+
},
|
43
|
+
"current_period_ends_at": "2009-12-14T11:10:56-05:00",
|
44
|
+
"trial_started_at": "2009-10-07T11:10:56-04:00",
|
45
|
+
"balance_in_cents": 0,
|
46
|
+
"state": "active",
|
47
|
+
"created_at": "2009-10-07T11:10:56-04:00"
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
[{
|
2
|
+
"subscription": {
|
3
|
+
"customer": {
|
4
|
+
"reference": "bradleyjoyce",
|
5
|
+
"updated_at": "2009-10-07T11:10:27-04:00",
|
6
|
+
"id": 16,
|
7
|
+
"organization": "Squeejee",
|
8
|
+
"first_name": "Bradley",
|
9
|
+
"last_name": "Joyce",
|
10
|
+
"email": "bradley@squeejee.com",
|
11
|
+
"created_at": "2009-10-07T11:10:27-04:00"
|
12
|
+
},
|
13
|
+
"cancellation_message": null,
|
14
|
+
"updated_at": "2009-10-07T11:10:56-04:00",
|
15
|
+
"expires_at": null,
|
16
|
+
"activated_at": "2009-10-23T16:16:59-04:00",
|
17
|
+
"current_period_started_at": "2009-11-14T11:10:56-05:00",
|
18
|
+
"credit_card": {
|
19
|
+
"card_type": "bogus",
|
20
|
+
"expiration_year": 2015,
|
21
|
+
"masked_card_number": "XXXX-XXXX-XXXX-1",
|
22
|
+
"first_name": "Bradley",
|
23
|
+
"last_name": "Joyce",
|
24
|
+
"expiration_month": 7
|
25
|
+
},
|
26
|
+
"trial_ended_at": "2009-10-14T11:10:56-04:00",
|
27
|
+
"id": 14,
|
28
|
+
"product": {
|
29
|
+
"price_in_cents": 500,
|
30
|
+
"name": "Monthly",
|
31
|
+
"handle": "monthly",
|
32
|
+
"id": 8,
|
33
|
+
"accounting_code": "TSMO",
|
34
|
+
"product_family": {
|
35
|
+
"name": "TweetSaver",
|
36
|
+
"handle": "tweetsaver",
|
37
|
+
"id": 7,
|
38
|
+
"accounting_code": null
|
39
|
+
},
|
40
|
+
"interval_unit": "month",
|
41
|
+
"interval": 1
|
42
|
+
},
|
43
|
+
"current_period_ends_at": "2009-12-14T11:10:56-05:00",
|
44
|
+
"trial_started_at": "2009-10-07T11:10:56-04:00",
|
45
|
+
"balance_in_cents": 0,
|
46
|
+
"state": "active",
|
47
|
+
"created_at": "2009-10-07T11:10:56-04:00"
|
48
|
+
}
|
49
|
+
}]
|
data/test/helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
gem 'thoughtbot-shoulda', '>= 2.10.1'
|
6
|
+
gem 'jnunemaker-matchy', '0.4.0'
|
7
|
+
gem 'mocha', '0.9.4'
|
8
|
+
gem 'fakeweb', '>= 1.2.5'
|
9
|
+
|
10
|
+
require 'shoulda'
|
11
|
+
require 'matchy'
|
12
|
+
require 'mocha'
|
13
|
+
require 'fakeweb'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'chargify'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
21
|
+
|
22
|
+
FakeWeb.allow_net_connect = false
|
23
|
+
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
end
|
27
|
+
|
28
|
+
def fixture_file(filename)
|
29
|
+
return '' if filename == ''
|
30
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
31
|
+
File.read(file_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def stub_get(url, filename, status=nil)
|
36
|
+
options = {:body => fixture_file(filename)}
|
37
|
+
options.merge!({:status => status}) unless status.nil?
|
38
|
+
|
39
|
+
FakeWeb.register_uri(:get, url, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def stub_post(url, filename, status=nil)
|
43
|
+
options = {:body => fixture_file(filename)}
|
44
|
+
options.merge!({:status => status}) unless status.nil?
|
45
|
+
|
46
|
+
FakeWeb.register_uri(:post, url, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_put(url, filename, status=nil)
|
50
|
+
options = {:body => fixture_file(filename)}
|
51
|
+
options.merge!({:status => status}) unless status.nil?
|
52
|
+
|
53
|
+
FakeWeb.register_uri(:put, url, options)
|
54
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestChargify < Test::Unit::TestCase
|
4
|
+
context "When hitting the Chargify API" do
|
5
|
+
setup do
|
6
|
+
@client = Chargify::Client.new('OU812', 'pengwynn')
|
7
|
+
end
|
8
|
+
|
9
|
+
should "return a list of customers" do
|
10
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/customers.json", "customers.json"
|
11
|
+
customers = @client.list_customers
|
12
|
+
customers.size.should == 1
|
13
|
+
customers.first.reference.should == 'bradleyjoyce'
|
14
|
+
customers.first.organization.should == 'Squeejee'
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
should "return info for a customer" do
|
19
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/customers/16.json", "customer.json"
|
20
|
+
customer = @client.customer(16)
|
21
|
+
customer.reference.should == 'bradleyjoyce'
|
22
|
+
customer.organization.should == 'Squeejee'
|
23
|
+
end
|
24
|
+
|
25
|
+
should "create a new customer" do
|
26
|
+
stub_post "https://OU812:x@pengwynn.chargify.com/customers.json", "new_customer.json"
|
27
|
+
info = {
|
28
|
+
:first_name => "Wynn",
|
29
|
+
:last_name => "Netherland",
|
30
|
+
:email => "wynn@example.com"
|
31
|
+
}
|
32
|
+
customer = @client.create_customer(info)
|
33
|
+
customer.first_name.should == "Wynn"
|
34
|
+
end
|
35
|
+
|
36
|
+
should "update a customer" do
|
37
|
+
stub_put "https://OU812:x@pengwynn.chargify.com/customers/16.json", "new_customer.json"
|
38
|
+
info = {
|
39
|
+
:id => 16,
|
40
|
+
:first_name => "Wynn",
|
41
|
+
:last_name => "Netherland",
|
42
|
+
:email => "wynn@example.com"
|
43
|
+
}
|
44
|
+
customer = @client.update_customer(info)
|
45
|
+
customer.first_name.should == "Wynn"
|
46
|
+
end
|
47
|
+
|
48
|
+
should "return a list of customer subscriptions" do
|
49
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/customers/16/subscriptions.json", "subscriptions.json"
|
50
|
+
subscriptions = @client.customer_subscriptions(16)
|
51
|
+
subscriptions.size.should == 1
|
52
|
+
subscriptions.first.customer.reference.should == "bradleyjoyce"
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
should "return info for a subscription" do
|
57
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/13.json", "subscription.json"
|
58
|
+
subscription = @client.subscription(13)
|
59
|
+
subscription.customer.reference.should == 'bradleyjoyce'
|
60
|
+
end
|
61
|
+
|
62
|
+
should "create a customer subscription" do
|
63
|
+
stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions.json", "subscription.json"
|
64
|
+
options = {
|
65
|
+
:product_handle => 'monthly',
|
66
|
+
:customer_reference => 'bradleyjoyce'
|
67
|
+
}
|
68
|
+
customer_attributes = {
|
69
|
+
:first_name => "Wynn",
|
70
|
+
:last_name => "Netherland",
|
71
|
+
:email => "wynn@example.com"
|
72
|
+
}
|
73
|
+
subscription = @client.create_subscription(options, customer_attributes)
|
74
|
+
subscription.customer.organization.should == 'Squeejee'
|
75
|
+
end
|
76
|
+
|
77
|
+
should "return a list of products" do
|
78
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/products.json", "products.json"
|
79
|
+
products = @client.list_products
|
80
|
+
products.first.accounting_code.should == 'TSMO'
|
81
|
+
end
|
82
|
+
|
83
|
+
should "return info for a product" do
|
84
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/products/8.json", "product.json"
|
85
|
+
product = @client.product(8)
|
86
|
+
product.accounting_code.should == 'TSMO'
|
87
|
+
end
|
88
|
+
|
89
|
+
should "return info for a product by its handle" do
|
90
|
+
stub_get "https://OU812:x@pengwynn.chargify.com/products/handle/tweetsaver.json", "product.json"
|
91
|
+
product = @client.product_by_handle('tweetsaver')
|
92
|
+
product.accounting_code.should == 'TSMO'
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chargify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wynn Netherland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-18 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hashie
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thoughtbot-shoulda
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.10.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: jnunemaker-matchy
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.4.0
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.9.4
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: fakeweb
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.2.5
|
74
|
+
version:
|
75
|
+
description: Ruby wrapper for the chargify.com SAAS and billing API
|
76
|
+
email: wynn.netherland@gmail.com
|
77
|
+
executables: []
|
78
|
+
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files:
|
82
|
+
- LICENSE
|
83
|
+
- README.markdown
|
84
|
+
files:
|
85
|
+
- .document
|
86
|
+
- .gitignore
|
87
|
+
- LICENSE
|
88
|
+
- README.markdown
|
89
|
+
- Rakefile
|
90
|
+
- VERSION
|
91
|
+
- lib/chargify.rb
|
92
|
+
- lib/chargify/client.rb
|
93
|
+
- test/fixtures/customer.json
|
94
|
+
- test/fixtures/customers.json
|
95
|
+
- test/fixtures/new_customer.json
|
96
|
+
- test/fixtures/product.json
|
97
|
+
- test/fixtures/products.json
|
98
|
+
- test/fixtures/subscription.json
|
99
|
+
- test/fixtures/subscriptions.json
|
100
|
+
- test/helper.rb
|
101
|
+
- test/test_chargify.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: http://github.com/pengwynn/chargify
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
version:
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
version:
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.3.5
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Ruby wrapper for the chargify.com SAAS and billing API
|
130
|
+
test_files:
|
131
|
+
- test/helper.rb
|
132
|
+
- test/test_chargify.rb
|