chargify_api_ares 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  gemspec.description = ""
7
7
  gemspec.email = "mklett@grasshopper.com"
8
8
  gemspec.homepage = "http://github.com/grasshopperlabs/chargify_api_ares"
9
- gemspec.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose"]
9
+ gemspec.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose","Nathan Verni"]
10
10
  Jeweler::GemcutterTasks.new
11
11
  end
12
12
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chargify_api_ares}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose"]
12
- s.date = %q{2010-03-05}
11
+ s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose", "Nathan Verni"]
12
+ s.date = %q{2010-03-18}
13
13
  s.description = %q{}
14
14
  s.email = %q{mklett@grasshopper.com}
15
15
  s.extra_rdoc_files = [
@@ -25,9 +25,11 @@ Gem::Specification.new do |s|
25
25
  "chargify_api_ares.gemspec",
26
26
  "lib/chargify_api_ares.rb",
27
27
  "samples/customers.rb",
28
+ "samples/metered_components.rb",
28
29
  "samples/products.rb",
29
30
  "samples/subscriptions.rb",
30
31
  "spec/base_spec.rb",
32
+ "spec/components_spec.rb",
31
33
  "spec/customer_spec.rb",
32
34
  "spec/factories.rb",
33
35
  "spec/mocks/fake_resource.rb",
@@ -42,6 +44,7 @@ Gem::Specification.new do |s|
42
44
  s.summary = %q{A Chargify API wrapper for Ruby using ActiveResource}
43
45
  s.test_files = [
44
46
  "spec/base_spec.rb",
47
+ "spec/components_spec.rb",
45
48
  "spec/customer_spec.rb",
46
49
  "spec/factories.rb",
47
50
  "spec/mocks/fake_resource.rb",
@@ -56,7 +56,7 @@ module Chargify
56
56
  yield self
57
57
 
58
58
  Base.user = api_key
59
- Base.password = 'X'
59
+ Base.password = 'X'
60
60
  Base.site = site.blank? ? "https://#{subdomain}.chargify.com" : site
61
61
  end
62
62
  end
@@ -83,7 +83,7 @@ module Chargify
83
83
  class Subscription < Base
84
84
  def self.find_by_customer_reference(reference)
85
85
  customer = Customer.find_by_reference(reference)
86
- find(:first, :params => {:customer_id => customer.id})
86
+ find(:first, :params => {:customer_id => customer.id})
87
87
  end
88
88
 
89
89
  # Strip off nested attributes of associations before saving, or type-mismatch errors will occur
@@ -111,4 +111,19 @@ module Chargify
111
111
  Product.new get(:lookup, :handle => handle)
112
112
  end
113
113
  end
114
+
115
+ class ProductFamily < Base
116
+ end
117
+
118
+ class Usage < Base
119
+ def subscription_id=(i)
120
+ self.prefix_options[:subscription_id] = i
121
+ end
122
+ def component_id=(i)
123
+ self.prefix_options[:component_id] = i
124
+ end
125
+ end
126
+
127
+ class Component < Base
128
+ end
114
129
  end
@@ -0,0 +1,33 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'chargify_api_ares'
4
+
5
+ # You could load your credentials from a file...
6
+ chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
7
+
8
+ Chargify.configure do |c|
9
+ c.subdomain = chargify_config['subdomain']
10
+ c.api_key = chargify_config['api_key']
11
+ if chargify_config['site']
12
+ c.site = chargify_config['site']
13
+ end
14
+ end
15
+
16
+
17
+ product_family = Chargify::ProductFamily.find(:first)
18
+ component = Chargify::Component.find(:first, :params => {:product_family_id => product_family.id})
19
+ subscription = Chargify::Subscription.find(:first)
20
+
21
+
22
+ u = Chargify::Usage.new
23
+ u.subscription_id = subscription.id
24
+ u.component_id = component.id
25
+ u.quantity = 5
26
+ d = DateTime.now.to_s
27
+ u.memo = d
28
+ puts d
29
+ u.save
30
+
31
+
32
+ x = Chargify::Usage.find(:last, :params => {:subscription_id => subscription.id, :component_id => component.id})
33
+ puts x.memo == d
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Chargify::Component do
4
+ describe "Recording usage" do
5
+ before do
6
+ @subscription = Factory(:subscription)
7
+ @component = Factory(:component)
8
+ @now = DateTime.now.to_s
9
+ puts test_domain
10
+ end
11
+
12
+ it "should create a usage record" do
13
+ u = Chargify::Usage.new
14
+ u.subscription_id = @subscription.id
15
+ u.component_id = @component.id
16
+ u.quantity = 5
17
+ u.memo = @now
18
+ u.save
19
+
20
+ component = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
21
+ component.memo.should == @now
22
+ component.quantity.should == 5
23
+ end
24
+ end
25
+
26
+ describe "Listing usages" do
27
+ before do
28
+ @subscription = Factory(:subscription)
29
+ @component = Factory(:component)
30
+ @now = DateTime.now.to_s
31
+ create_usage
32
+ end
33
+
34
+ it "should return all usages for a component and subscription" do
35
+ component = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
36
+ component.quantity.should == 5
37
+ end
38
+ end
39
+
40
+ def create_usage
41
+ u = Chargify::Usage.new
42
+ u.subscription_id = @subscription.id
43
+ u.component_id = @component.id
44
+ u.quantity = 5
45
+ u.memo = @now
46
+ u.save
47
+ end
48
+ end
49
+
@@ -41,4 +41,9 @@ Factory.define :subscription_with_extra_attrs, :parent => :subscription do |swea
41
41
  swea.customer Chargify::Customer.new
42
42
  swea.product Chargify::Product.new
43
43
  swea.credit_card "CREDIT CARD"
44
- end
44
+ end
45
+
46
+ Factory.define :component, :class => Chargify::Component do |f|
47
+ f.name { Faker::Company.bs }
48
+ f.unit_name 'unit'
49
+ end
metadata CHANGED
@@ -5,18 +5,19 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Klett
13
13
  - The Lab Rats @ Phase Two Labs
14
14
  - Brian Rose
15
+ - Nathan Verni
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-03-05 00:00:00 -05:00
20
+ date: 2010-03-18 00:00:00 -04:00
20
21
  default_executable:
21
22
  dependencies: []
22
23
 
@@ -38,9 +39,11 @@ files:
38
39
  - chargify_api_ares.gemspec
39
40
  - lib/chargify_api_ares.rb
40
41
  - samples/customers.rb
42
+ - samples/metered_components.rb
41
43
  - samples/products.rb
42
44
  - samples/subscriptions.rb
43
45
  - spec/base_spec.rb
46
+ - spec/components_spec.rb
44
47
  - spec/customer_spec.rb
45
48
  - spec/factories.rb
46
49
  - spec/mocks/fake_resource.rb
@@ -79,6 +82,7 @@ specification_version: 3
79
82
  summary: A Chargify API wrapper for Ruby using ActiveResource
80
83
  test_files:
81
84
  - spec/base_spec.rb
85
+ - spec/components_spec.rb
82
86
  - spec/customer_spec.rb
83
87
  - spec/factories.rb
84
88
  - spec/mocks/fake_resource.rb