chargify 0.2.5 → 0.2.6

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/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  ## MAC OS
2
2
  .DS_Store
3
-
3
+ dist
4
4
  ## TEXTMATE
5
5
  *.tmproj
6
6
  tmtags
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ dist/*
@@ -4,8 +4,6 @@ Ruby wrapper for the chargify.com SAAS and billing API
4
4
 
5
5
  ## Installation
6
6
 
7
- sudo gem install gemcutter
8
- gem tumble
9
7
  sudo gem install chargify
10
8
 
11
9
  ## Example Usage
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -1,4 +1,10 @@
1
1
  # Changelog
2
+
3
+ ## 0.2.6 May 27, 2010
4
+ * Fix #charge_subscription to submit it's body as json [@will](http://github.com/will) and [@ignat](http://github.com/ignat)
5
+ * API coverage for quantity components [@will](http://github.com/will)
6
+ * API coverage for site and subscription transactions [@ignat](http://github.com/ignat)
7
+
2
8
  ## 0.2.5 May 24, 2010
3
9
  * Require fix from [@will](http://github.com/will)
4
10
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chargify}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wynn Netherland", "Nash Kabbara"]
12
- s.date = %q{2010-05-24}
12
+ s.date = %q{2010-05-27}
13
13
  s.description = %q{Ruby wrapper for the chargify.com SAAS and billing API}
14
14
  s.email = %q{wynn.netherland@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -61,6 +61,7 @@ Gem::Specification.new do |s|
61
61
  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
62
62
  s.add_development_dependency(%q<mocha>, ["~> 0.9.8"])
63
63
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.5"])
64
+ s.add_development_dependency(%q<redgreen>, [">= 1.2.2"])
64
65
  else
65
66
  s.add_dependency(%q<hashie>, ["~> 0.1.3"])
66
67
  s.add_dependency(%q<httparty>, ["~> 0.5.2"])
@@ -9,5 +9,5 @@ Hash.send :include, Hashie::HashExtensions
9
9
  require File.join(directory, 'chargify', 'client')
10
10
 
11
11
  module Chargify
12
- VERSION = "0.2.5".freeze
12
+ VERSION = "0.2.6".freeze
13
13
  end
@@ -32,19 +32,19 @@ module Chargify
32
32
 
33
33
  # options: page
34
34
  def list_customers(options={})
35
- customers = self.class.get("/customers.json", :query => options)
35
+ customers = get("/customers.json", :query => options)
36
36
  customers.map{|c| Hashie::Mash.new c['customer']}
37
37
  end
38
38
 
39
39
  def customer_by_id(chargify_id)
40
- request = self.class.get("/customers/#{chargify_id}.json")
40
+ request = get("/customers/#{chargify_id}.json")
41
41
  success = request.code == 200
42
42
  response = Hashie::Mash.new(request).customer if success
43
43
  Hashie::Mash.new(response || {}).update(:success? => success)
44
44
  end
45
45
 
46
46
  def customer_by_reference(reference_id)
47
- request = self.class.get("/customers/lookup.json?reference=#{reference_id}")
47
+ request = get("/customers/lookup.json?reference=#{reference_id}")
48
48
  success = request.code == 200
49
49
  response = Hashie::Mash.new(request).customer if success
50
50
  Hashie::Mash.new(response || {}).update(:success? => success)
@@ -61,7 +61,7 @@ module Chargify
61
61
  # * reference (Optional, but encouraged) The unique identifier used within your own application for this customer
62
62
  #
63
63
  def create_customer(info={})
64
- response = Hashie::Mash.new(self.class.post("/customers.json", :body => {:customer => info}.to_json))
64
+ response = Hashie::Mash.new(post("/customers.json", :body => {:customer => info}))
65
65
  return response.customer if response.customer
66
66
  response
67
67
  end
@@ -76,20 +76,18 @@ module Chargify
76
76
  def update_customer(info={})
77
77
  info.stringify_keys!
78
78
  chargify_id = info.delete('id')
79
- response = Hashie::Mash.new(self.class.put("/customers/#{chargify_id}.json", :body => {:customer => info}))
79
+ response = Hashie::Mash.new(put("/customers/#{chargify_id}.json", :body => {:customer => info}))
80
80
  return response.customer unless response.customer.to_a.empty?
81
81
  response
82
82
  end
83
83
 
84
84
  def customer_subscriptions(chargify_id)
85
- subscriptions = self.class.get("/customers/#{chargify_id}/subscriptions.json")
85
+ subscriptions = get("/customers/#{chargify_id}/subscriptions.json")
86
86
  subscriptions.map{|s| Hashie::Mash.new s['subscription']}
87
87
  end
88
88
 
89
-
90
-
91
89
  def subscription(subscription_id)
92
- raw_response = self.class.get("/subscriptions/#{subscription_id}.json")
90
+ raw_response = get("/subscriptions/#{subscription_id}.json")
93
91
  return nil if raw_response.code != 200
94
92
  Hashie::Mash.new(raw_response).subscription
95
93
  end
@@ -97,7 +95,7 @@ module Chargify
97
95
  # Returns all elements outputted by Chargify plus:
98
96
  # response.success? -> true if response code is 201, false otherwise
99
97
  def create_subscription(subscription_attributes={})
100
- raw_response = self.class.post("/subscriptions.json", :body => {:subscription => subscription_attributes}.to_json)
98
+ raw_response = post("/subscriptions.json", :body => {:subscription => subscription_attributes})
101
99
  created = true if raw_response.code == 201
102
100
  response = Hashie::Mash.new(raw_response)
103
101
  (response.subscription || response).update(:success? => created)
@@ -106,7 +104,7 @@ module Chargify
106
104
  # Returns all elements outputted by Chargify plus:
107
105
  # response.success? -> true if response code is 200, false otherwise
108
106
  def update_subscription(sub_id, subscription_attributes = {})
109
- raw_response = self.class.put("/subscriptions/#{sub_id}.json", :body => {:subscription => subscription_attributes}.to_json)
107
+ raw_response = put("/subscriptions/#{sub_id}.json", :body => {:subscription => subscription_attributes})
110
108
  updated = true if raw_response.code == 200
111
109
  response = Hashie::Mash.new(raw_response)
112
110
  (response.subscription || response).update(:success? => updated)
@@ -115,21 +113,21 @@ module Chargify
115
113
  # Returns all elements outputted by Chargify plus:
116
114
  # response.success? -> true if response code is 200, false otherwise
117
115
  def cancel_subscription(sub_id, message="")
118
- raw_response = self.class.delete("/subscriptions/#{sub_id}.json", :body => {:subscription => {:cancellation_message => message} }.to_json)
116
+ raw_response = delete("/subscriptions/#{sub_id}.json", :body => {:subscription => {:cancellation_message => message} })
119
117
  deleted = true if raw_response.code == 200
120
118
  response = Hashie::Mash.new(raw_response)
121
119
  (response.subscription || response).update(:success? => deleted)
122
120
  end
123
121
 
124
122
  def reactivate_subscription(sub_id)
125
- raw_response = self.class.put("/subscriptions/#{sub_id}/reactivate.json", :body => "")
123
+ raw_response = put("/subscriptions/#{sub_id}/reactivate.json", :body => "")
126
124
  reactivated = true if raw_response.code == 200
127
125
  response = Hashie::Mash.new(raw_response) rescue Hashie::Mash.new
128
126
  (response.subscription || response).update(:success? => reactivated)
129
127
  end
130
128
 
131
129
  def charge_subscription(sub_id, subscription_attributes={})
132
- raw_response = self.class.post("/subscriptions/#{sub_id}/charges.json", :body => { :charge => subscription_attributes })
130
+ raw_response = post("/subscriptions/#{sub_id}/charges.json", :body => { :charge => subscription_attributes })
133
131
  success = raw_response.code == 201
134
132
  if raw_response.code == 404
135
133
  raw_response = {}
@@ -140,31 +138,85 @@ module Chargify
140
138
  end
141
139
 
142
140
  def migrate_subscription(sub_id, product_id)
143
- raw_response = self.class.post("/subscriptions/#{sub_id}/migrations.json", :body => {:product_id => product_id }.to_json)
141
+ raw_response = post("/subscriptions/#{sub_id}/migrations.json", :body => {:product_id => product_id })
144
142
  success = true if raw_response.code == 200
145
143
  response = Hashie::Mash.new(raw_response)
146
144
  (response.subscription || {}).update(:success? => success)
147
145
  end
148
146
 
149
147
  def list_products
150
- products = self.class.get("/products.json")
148
+ products = get("/products.json")
151
149
  products.map{|p| Hashie::Mash.new p['product']}
152
150
  end
153
151
 
154
152
  def product(product_id)
155
- Hashie::Mash.new( self.class.get("/products/#{product_id}.json")).product
153
+ Hashie::Mash.new( get("/products/#{product_id}.json")).product
156
154
  end
157
155
 
158
156
  def product_by_handle(handle)
159
- Hashie::Mash.new(self.class.get("/products/handle/#{handle}.json")).product
157
+ Hashie::Mash.new(get("/products/handle/#{handle}.json")).product
160
158
  end
161
159
 
162
160
  def list_subscription_usage(subscription_id, component_id)
163
- raw_response = self.class.get("/subscriptions/#{subscription_id}/components/#{component_id}/usages.json")
161
+ raw_response = get("/subscriptions/#{subscription_id}/components/#{component_id}/usages.json")
164
162
  success = raw_response.code == 200
165
163
  response = Hashie::Mash.new(raw_response)
166
164
  response.update(:success? => success)
167
165
  end
168
166
 
167
+ def subscription_transactions(sub_id, options={})
168
+ transactions = get("/subscriptions/#{sub_id}/transactions.json", :query => options)
169
+ transactions.map{|t| Hashie::Mash.new t['transaction']}
170
+ end
171
+
172
+ def site_transactions(options={})
173
+ transactions = get("/transactions.json", :query => options)
174
+ transactions.map{|t| Hashie::Mash.new t['transaction']}
175
+ end
176
+
177
+ def list_components(subscription_id)
178
+ components = get("/subscriptions/#{subscription_id}/components.json")
179
+ components.map{|c| Hashie::Mash.new c['component']}
180
+ end
181
+
182
+ def subscription_component(subscription_id, component_id)
183
+ response = get("/subscriptions/#{subscription_id}/components/#{component_id}.json")
184
+ Hashie::Mash.new(response).component
185
+ end
186
+
187
+ def update_subscription_component_allocated_quantity(subscription_id, component_id, quantity)
188
+ response = put("/subscriptions/#{subscription_id}/components/#{component_id}.json", :body => {:component => {:allocated_quantity => quantity}})
189
+ response[:success?] = response.code == 200
190
+ Hashie::Mash.new(response)
191
+ end
192
+
193
+
194
+
195
+ private
196
+
197
+ def post(path, options={})
198
+ jsonify_body!(options)
199
+ self.class.post(path, options)
200
+ end
201
+
202
+ def put(path, options={})
203
+ jsonify_body!(options)
204
+ self.class.put(path, options)
205
+ end
206
+
207
+ def delete(path, options={})
208
+ jsonify_body!(options)
209
+ self.class.delete(path, options)
210
+ end
211
+
212
+ def get(path, options={})
213
+ jsonify_body!(options)
214
+ self.class.get(path, options)
215
+ end
216
+
217
+ def jsonify_body!(options)
218
+ options[:body] = options[:body].to_json if options[:body]
219
+
220
+ end
169
221
  end
170
222
  end
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  class ChargifyTest < Test::Unit::TestCase
4
- context "When hitting the Chargify API" do
4
+ context "Chargify API client" do
5
5
  setup do
6
6
  @client = Chargify::Client.new('OU812', 'pengwynn')
7
7
  end
@@ -250,7 +250,7 @@ class ChargifyTest < Test::Unit::TestCase
250
250
  setup do
251
251
  stub_post "https://OU812:x@pengwynn.chargify.com/subscriptions/123/charges.json", "charge_subscription.json", 201
252
252
  @options = {
253
- :meno => "This is the description of the one time charge.",
253
+ :memo => "This is the description of the one time charge.",
254
254
  :amount => 1.00,
255
255
  :amount_in_cents => 100
256
256
  }
@@ -324,6 +324,27 @@ class ChargifyTest < Test::Unit::TestCase
324
324
  product.accounting_code.should == 'TSMO'
325
325
  end
326
326
 
327
+ context "for quantity based components" do
328
+ should "list components" do
329
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components.json", "components.json"
330
+ components = @client.list_components(123)
331
+ components.first.allocated_quantity.should == 42
332
+ components.last.allocated_quantity.should == 2
333
+ end
334
+
335
+ should "show a specific component" do
336
+ stub_get "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/16.json", "component.json"
337
+ component = @client.subscription_component 123, 16
338
+ component.name.should == "Extra Rubies"
339
+ component.allocated_quantity.should == 42
340
+ end
341
+
342
+ should "update the allocated_quantity for a component" do
343
+ stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/components/16.json", "component.json"
344
+ response = @client.update_subscription_component_allocated_quantity 123, 16, 20_000_000
345
+ response.success?.should == true
346
+ end
347
+ end
327
348
 
328
349
  end
329
350
  end
@@ -5,6 +5,7 @@ require 'shoulda'
5
5
  require 'matchy'
6
6
  require 'mocha'
7
7
  require 'fakeweb'
8
+ require 'redgreen'
8
9
 
9
10
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
11
  $LOAD_PATH.unshift(File.dirname(__FILE__))
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wynn Netherland
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-24 00:00:00 -05:00
18
+ date: 2010-05-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -102,6 +102,20 @@ dependencies:
102
102
  version: 1.2.5
103
103
  type: :development
104
104
  version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: redgreen
107
+ prerelease: false
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 1
114
+ - 2
115
+ - 2
116
+ version: 1.2.2
117
+ type: :development
118
+ version_requirements: *id007
105
119
  description: Ruby wrapper for the chargify.com SAAS and billing API
106
120
  email: wynn.netherland@gmail.com
107
121
  executables: []