charger 0.1.0 → 0.1.1

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/charger.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_runtime_dependency('virtus')
21
21
  gem.add_runtime_dependency('activesupport')
22
+ gem.add_runtime_dependency('activemodel')
22
23
  gem.add_runtime_dependency('multi_json')
23
24
  gem.add_runtime_dependency('rest-client')
24
25
 
data/lib/charger.rb CHANGED
@@ -1,3 +1,32 @@
1
+ require 'virtus'
2
+ require 'active_support'
3
+ require 'active_model'
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ require 'charger/exception'
8
+ require 'charger/resource'
9
+ require 'charger/request'
10
+ require 'charger/price'
11
+ require 'charger/component'
12
+ require 'charger/component/metered'
13
+ require 'charger/component/on_off'
14
+ require 'charger/component/quantity_based'
15
+ require 'charger/credit_card'
16
+ require 'charger/customer'
17
+ require 'charger/event'
18
+ require 'charger/line_item'
19
+ require 'charger/product_family'
20
+ require 'charger/product'
21
+ require 'charger/transaction'
22
+ require 'charger/statement'
23
+ require 'charger/subscription'
24
+ require 'charger/line_item/metered'
25
+ require 'charger/line_item/on_off'
26
+ require 'charger/line_item/quantity_based'
27
+ require 'charger/client'
28
+ require 'charger/configuration'
29
+
1
30
  module Charger
2
31
  class << self
3
32
  # The hash of configurations
@@ -10,18 +10,26 @@ module Charger
10
10
 
11
11
  def get resource, headers={}
12
12
  JSON.parse(RestClient.get(resource_url(resource), rest_headers(headers)))
13
+ rescue RestClient::Exception => e
14
+ raise Charger::Exception.new(e.response)
13
15
  end
14
16
 
15
17
  def post resource, payload, headers={}
16
18
  JSON.parse(RestClient.post(resource_url(resource), payload, rest_headers(headers)))
19
+ rescue RestClient::Exception => e
20
+ raise Charger::Exception.new(e.response)
17
21
  end
18
22
 
19
23
  def put resource, payload, headers={}
20
24
  JSON.parse(RestClient.put(resource_url(resource), payload, rest_headers(headers)))
25
+ rescue RestClient::Exception => e
26
+ raise Charger::Exception.new(e.response)
21
27
  end
22
28
 
23
29
  def delete resource, headers={}
24
30
  JSON.parse(RestClient.delete(resource_url(resource), rest_headers(headers)))
31
+ rescue RestClient::Exception => e
32
+ raise Charger::Exception.new(e.response)
25
33
  end
26
34
 
27
35
  private
@@ -8,7 +8,7 @@ module Charger
8
8
  attribute :unit_name, String
9
9
  attribute :unit_price, Float
10
10
  attribute :pricing_scheme, String
11
- attribute :prices, Array[Component::Price]
11
+ attribute :prices, Array[Price]
12
12
  attribute :product_family_id, Integer
13
13
  attribute :kind, String
14
14
  attribute :archived, Boolean
@@ -0,0 +1,10 @@
1
+ module Charger
2
+ class Exception < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize response
6
+ @response = response
7
+ super
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,6 @@
1
1
  module Charger
2
2
 
3
- class Component::Price
3
+ class Price
4
4
  include Virtus
5
5
 
6
6
  attribute :ending_quantity, Integer
@@ -1,3 +1,3 @@
1
1
  module Charger
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Client do
4
+ let(:client) { Charger::Client.new('abc123', 'testing') }
5
+ subject { client }
6
+
7
+ describe 'attributes' do
8
+ it { should respond_to :api_key }
9
+ it { should respond_to :subdomain }
10
+ end
11
+
12
+
13
+ describe '#get' do
14
+ it { should respond_to :get }
15
+
16
+ context 'when Chargify responds with an error' do
17
+ before { RestClient.stub(:get).and_raise(RestClient::Exception) }
18
+
19
+ it 'should raise Charger::Exception' do
20
+ expect { client.get 'resource' }.to raise_error(Charger::Exception)
21
+ end
22
+ end
23
+
24
+
25
+ context 'when Chargify responds with success' do
26
+ before { RestClient.stub(:get).and_return("{\"foo\":\"bar\",\"baz\":\"qux\"}")}
27
+ subject { client.get 'resource' }
28
+ it { should be_a(Hash) }
29
+ end
30
+ end
31
+
32
+
33
+ describe '#post' do
34
+ it { should respond_to :post }
35
+
36
+ context 'when Chargify responds with an error' do
37
+ before { RestClient.stub(:post).and_raise(RestClient::Exception) }
38
+
39
+ it 'should raise Charger::Exception' do
40
+ expect { client.post 'resource', { :some_data => 'value' } }.to raise_error(Charger::Exception)
41
+ end
42
+ end
43
+
44
+ context 'when Chargify responds with success' do
45
+ before { RestClient.stub(:post).and_return("{\"foo\":\"bar\",\"baz\":\"qux\"}")}
46
+ subject { client.post 'resource', { :some_data => 'value' } }
47
+ it { should be_a(Hash) }
48
+ end
49
+ end
50
+
51
+
52
+ describe '#put' do
53
+ it { should respond_to :put }
54
+
55
+ context 'when Chargify responds with an error' do
56
+ before { RestClient.stub(:put).and_raise(RestClient::Exception) }
57
+
58
+ it 'should raise Charger::Exception' do
59
+ expect { client.put 'resource/1', { :some_data => 'value' } }.to raise_error(Charger::Exception)
60
+ end
61
+ end
62
+
63
+ context 'when Chargify responds with success' do
64
+ before { RestClient.stub(:put).and_return("{\"foo\":\"bar\",\"baz\":\"qux\"}")}
65
+ subject { client.put 'resource/1', { :some_data => 'value' } }
66
+ it { should be_a(Hash) }
67
+ end
68
+ end
69
+
70
+
71
+ describe '#delete' do
72
+ it { should respond_to :delete }
73
+
74
+ context 'when Chargify responds with an error' do
75
+ before { RestClient.stub(:delete).and_raise(RestClient::Exception) }
76
+ it 'should raise Charger::Exception' do
77
+ expect { client.delete 'resource/1' }.to raise_error(Charger::Exception)
78
+ end
79
+ end
80
+
81
+ context 'when Chargify responds with success' do
82
+ before { RestClient.stub(:delete).and_return("{\"foo\":\"bar\",\"baz\":\"qux\"}")}
83
+ subject { client.delete 'resource/1' }
84
+ it { should be_a(Hash) }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Component do
4
+ subject { Charger::Component.new }
5
+
6
+ describe 'attributes' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :name }
9
+ it { should respond_to :unit_name }
10
+ it { should respond_to :unit_price }
11
+ it { should respond_to :pricing_scheme }
12
+ it { should respond_to :prices }
13
+ it { should respond_to :product_family_id }
14
+ it { should respond_to :kind }
15
+ it { should respond_to :archived }
16
+ end
17
+
18
+
19
+ describe '#total_for' do
20
+ it { should respond_to :total_for}
21
+ end
22
+
23
+
24
+ describe '.find_by_product_family_id' do
25
+ subject { Charger::Component }
26
+ it { should respond_to :find_by_product_family_id }
27
+ end
28
+
29
+
30
+ describe '.find' do
31
+ subject { Charger::Component }
32
+ it { should respond_to :find }
33
+ end
34
+
35
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Configuration do
4
+ subject { Charger::Configuration.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :api_key }
8
+ it { should respond_to :subdomain }
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::CreditCard do
4
+ subject { Charger::CreditCard.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :payment_profile_id }
9
+ it { should respond_to :card_type }
10
+ it { should respond_to :expiration_month }
11
+ it { should respond_to :expiration_year }
12
+ it { should respond_to :first_name }
13
+ it { should respond_to :last_name }
14
+ it { should respond_to :masked_card_number }
15
+ it { should respond_to :customer_id }
16
+ it { should respond_to :customer_vault_token }
17
+ it { should respond_to :vault_token }
18
+ it { should respond_to :current_vault }
19
+ it { should respond_to :billing_address }
20
+ it { should respond_to :billing_address_2 }
21
+ it { should respond_to :billing_city }
22
+ it { should respond_to :billing_state }
23
+ it { should respond_to :billing_zip }
24
+ it { should respond_to :billing_country }
25
+ end
26
+
27
+
28
+ describe '#persisted?' do
29
+ context 'when id is not set' do
30
+ it 'should return false' do
31
+ expect(subject.persisted?).to eq(false)
32
+ end
33
+ end
34
+
35
+ context 'when id is set' do
36
+ before { subject.id = 1 }
37
+ it 'should return true' do
38
+ expect(subject.persisted?).to eq(true)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Customer do
4
+ subject { Charger::Customer.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :first_name }
9
+ it { should respond_to :last_name }
10
+ end
11
+
12
+
13
+ describe '#persisted?' do
14
+ context 'when the id is set' do
15
+ before { subject.id = 1 }
16
+ it 'should return true' do
17
+ expect(subject.persisted?).to eq(true)
18
+ end
19
+ end
20
+ context 'when the id is not set' do
21
+ it 'should return false' do
22
+ expect(subject.persisted?).to eq(false)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Event do
4
+ subject { Charger::Event.new }
5
+
6
+ describe 'fields' do
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Exception do
4
+ subject { Charger::Exception.new }
5
+
6
+ describe 'fields' do
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::LineItem do
4
+ subject { Charger::LineItem.new }
5
+
6
+ describe 'fields' do
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Price do
4
+ subject { Charger::Price.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :ending_quantity }
8
+ it { should respond_to :starting_quantity }
9
+ it { should respond_to :unit_price }
10
+ end
11
+
12
+ describe '#between_quantities?' do
13
+ pending 'write these'
14
+ end
15
+
16
+
17
+ describe '#remaining_quantity' do
18
+ pending 'write these'
19
+ end
20
+
21
+
22
+ describe '#total' do
23
+ pending 'write these'
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::ProductFamily do
4
+ subject { Charger::ProductFamily.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :name }
9
+ it { should respond_to :handle }
10
+ it { should respond_to :accounting_code }
11
+ it { should respond_to :description }
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Product do
4
+ subject { Charger::Product.new }
5
+
6
+ describe 'fields' do
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Statement do
4
+ subject { Charger::Statement.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :subscription_id }
9
+ it { should respond_to :opened_at }
10
+ it { should respond_to :closed_at }
11
+ it { should respond_to :settled_at }
12
+ it { should respond_to :text_view }
13
+ it { should respond_to :basic_html_view }
14
+ it { should respond_to :html_view }
15
+ it { should respond_to :future_payments }
16
+ it { should respond_to :starting_balance_in_cents }
17
+ it { should respond_to :ending_balance_in_cents }
18
+ it { should respond_to :customer_first_name }
19
+ it { should respond_to :customer_last_name }
20
+ it { should respond_to :customer_organization }
21
+ it { should respond_to :customer_shipping_address }
22
+ it { should respond_to :customer_shipping_address_2 }
23
+ it { should respond_to :customer_shipping_city }
24
+ it { should respond_to :customer_shipping_state }
25
+ it { should respond_to :customer_shipping_country }
26
+ it { should respond_to :customer_shipping_zip }
27
+ it { should respond_to :customer_billing_address }
28
+ it { should respond_to :customer_billing_address_2 }
29
+ it { should respond_to :customer_billing_city }
30
+ it { should respond_to :customer_billing_state }
31
+ it { should respond_to :customer_billing_country }
32
+ it { should respond_to :customer_billing_zip }
33
+ it { should respond_to :transactions }
34
+ it { should respond_to :events }
35
+ it { should respond_to :created_at }
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Subscription do
4
+ subject { Charger::Subscription.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :id }
8
+ it { should respond_to :state }
9
+ it { should respond_to :balance_cents }
10
+ it { should respond_to :current_period_started_at }
11
+ it { should respond_to :current_period_ends_at }
12
+ it { should respond_to :next_assessment_at }
13
+ it { should respond_to :trial_started_at }
14
+ it { should respond_to :trial_ended_at }
15
+ it { should respond_to :activated_at }
16
+ it { should respond_to :expires_at }
17
+ it { should respond_to :created_at }
18
+ it { should respond_to :updated_at }
19
+ it { should respond_to :customer }
20
+ it { should respond_to :product }
21
+ it { should respond_to :credit_card }
22
+ it { should respond_to :cancellation_message }
23
+ it { should respond_to :canceled_at }
24
+ it { should respond_to :signup_revenue }
25
+ it { should respond_to :signup_payment_id }
26
+ it { should respond_to :cancel_at_end_of_peroid }
27
+ it { should respond_to :delayed_cancel_at }
28
+ it { should respond_to :previous_state }
29
+ it { should respond_to :coupon_code }
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger::Transaction do
4
+ subject { Charger::Transaction.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :transaction_type }
8
+ it { should respond_to :id }
9
+ it { should respond_to :amount_in_cents }
10
+ it { should respond_to :created_at }
11
+ it { should respond_to :ending_balance_in_cents }
12
+ it { should respond_to :memo }
13
+ it { should respond_to :subscription_id }
14
+ it { should respond_to :product_id }
15
+ it { should respond_to :success }
16
+ it { should respond_to :payment_id }
17
+ it { should respond_to :kind }
18
+ it { should respond_to :gateway_transaction_id }
19
+ end
20
+
21
+ describe '#subscription' do
22
+ it { should respond_to :subscription }
23
+ end
24
+
25
+
26
+ describe '#subscription=' do
27
+ it { should respond_to :subscription= }
28
+ end
29
+
30
+
31
+ describe '#reload' do
32
+ it { should respond_to :reload }
33
+ end
34
+
35
+
36
+ describe '.find' do
37
+ subject { Charger::Transaction }
38
+ it { should respond_to :find }
39
+ end
40
+
41
+
42
+ describe '.page' do
43
+ subject { Charger::Transaction }
44
+ it { should respond_to :page }
45
+ end
46
+
47
+
48
+ describe '.all' do
49
+ subject { Charger::Transaction }
50
+ it { should respond_to :all }
51
+ end
52
+
53
+
54
+ describe '.find_by_subscription_id' do
55
+ subject { Charger::Transaction }
56
+ it { should respond_to :find_by_subscription_id }
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Charger do
4
+ context '.configure' do
5
+ subject { Charger }
6
+ it { should respond_to :configure }
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ require 'charger'
2
+
3
+ RSpec.configure do |config|
4
+ config.mock_with :rspec
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activemodel
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: multi_json
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +195,7 @@ extensions: []
179
195
  extra_rdoc_files: []
180
196
  files:
181
197
  - .gitignore
198
+ - .rspec
182
199
  - .rvmrc
183
200
  - Gemfile
184
201
  - LICENSE.txt
@@ -190,16 +207,17 @@ files:
190
207
  - lib/charger/component.rb
191
208
  - lib/charger/component/metered.rb
192
209
  - lib/charger/component/on_off.rb
193
- - lib/charger/component/price.rb
194
210
  - lib/charger/component/quantity_based.rb
195
211
  - lib/charger/configuration.rb
196
212
  - lib/charger/credit_card.rb
197
213
  - lib/charger/customer.rb
198
214
  - lib/charger/event.rb
215
+ - lib/charger/exception.rb
199
216
  - lib/charger/line_item.rb
200
217
  - lib/charger/line_item/metered.rb
201
218
  - lib/charger/line_item/on_off.rb
202
219
  - lib/charger/line_item/quantity_based.rb
220
+ - lib/charger/price.rb
203
221
  - lib/charger/product.rb
204
222
  - lib/charger/product_family.rb
205
223
  - lib/charger/request.rb
@@ -208,6 +226,22 @@ files:
208
226
  - lib/charger/subscription.rb
209
227
  - lib/charger/transaction.rb
210
228
  - lib/charger/version.rb
229
+ - spec/charger/client_spec.rb
230
+ - spec/charger/component_spec.rb
231
+ - spec/charger/configuration_spec.rb
232
+ - spec/charger/credit_card_spec.rb
233
+ - spec/charger/customer_spec.rb
234
+ - spec/charger/event_spec.rb
235
+ - spec/charger/exception_spec.rb
236
+ - spec/charger/line_item_spec.rb
237
+ - spec/charger/price_spec.rb
238
+ - spec/charger/product_family_spec.rb
239
+ - spec/charger/product_spec.rb
240
+ - spec/charger/statement_spec.rb
241
+ - spec/charger/subscription_spec.rb
242
+ - spec/charger/transaction_spec.rb
243
+ - spec/charger_spec.rb
244
+ - spec/spec_helper.rb
211
245
  homepage: https://github.com/warmwaffles/charger
212
246
  licenses: []
213
247
  post_install_message:
@@ -222,7 +256,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
256
  version: '0'
223
257
  segments:
224
258
  - 0
225
- hash: 792757683206972101
259
+ hash: -1973324211123935991
226
260
  required_rubygems_version: !ruby/object:Gem::Requirement
227
261
  none: false
228
262
  requirements:
@@ -231,11 +265,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
265
  version: '0'
232
266
  segments:
233
267
  - 0
234
- hash: 792757683206972101
268
+ hash: -1973324211123935991
235
269
  requirements: []
236
270
  rubyforge_project:
237
271
  rubygems_version: 1.8.24
238
272
  signing_key:
239
273
  specification_version: 3
240
274
  summary: Utilizes Chargify's REST API
241
- test_files: []
275
+ test_files:
276
+ - spec/charger/client_spec.rb
277
+ - spec/charger/component_spec.rb
278
+ - spec/charger/configuration_spec.rb
279
+ - spec/charger/credit_card_spec.rb
280
+ - spec/charger/customer_spec.rb
281
+ - spec/charger/event_spec.rb
282
+ - spec/charger/exception_spec.rb
283
+ - spec/charger/line_item_spec.rb
284
+ - spec/charger/price_spec.rb
285
+ - spec/charger/product_family_spec.rb
286
+ - spec/charger/product_spec.rb
287
+ - spec/charger/statement_spec.rb
288
+ - spec/charger/subscription_spec.rb
289
+ - spec/charger/transaction_spec.rb
290
+ - spec/charger_spec.rb
291
+ - spec/spec_helper.rb