cameroncox-mousetrap 0.5.3.10 → 0.6.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/.gitignore +1 -0
- data/Rakefile +96 -3
- data/VERSION +1 -1
- data/lib/mousetrap.rb +4 -1
- data/lib/mousetrap/customer.rb +48 -12
- data/lib/mousetrap/invoice.rb +13 -6
- data/lib/mousetrap/plan.rb +4 -5
- data/lib/mousetrap/resource.rb +12 -0
- data/lib/mousetrap/subscription.rb +31 -24
- data/mousetrap.gemspec +10 -9
- data/script/authenticate.rb +1 -1
- data/script/console +15 -1
- data/spec/factories.rb +5 -1
- data/spec/integration/smoke_test.rb +10 -0
- data/spec/mousetrap/customer_spec.rb +63 -22
- metadata +58 -22
data/.gitignore
CHANGED
data/Rakefile
CHANGED
|
@@ -4,13 +4,13 @@ require 'rake'
|
|
|
4
4
|
begin
|
|
5
5
|
require 'jeweler'
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
|
7
|
-
gem.name = "
|
|
7
|
+
gem.name = "mousetrap"
|
|
8
8
|
gem.summary = %Q{CheddarGetter API Client in Ruby}
|
|
9
9
|
gem.description = %Q{CheddarGetter API Client in Ruby}
|
|
10
10
|
gem.email = "jonlarkowski@gmail.com"
|
|
11
|
-
gem.homepage = "http://github.com/
|
|
11
|
+
gem.homepage = "http://github.com/hashrocket/mousetrap"
|
|
12
12
|
gem.authors = ["Jon Larkowski", "Sandro Turriate", "Wolfram Arnold", "Corey Grusden"]
|
|
13
|
-
gem.add_dependency 'httparty', '>= 0.
|
|
13
|
+
gem.add_dependency 'httparty', '>= 0.6.1'
|
|
14
14
|
gem.add_development_dependency "activesupport", '>= 2.3.3'
|
|
15
15
|
gem.add_development_dependency "rspec", '>= 1.2.9'
|
|
16
16
|
gem.add_development_dependency 'factory_girl', '>= 1.2.3'
|
|
@@ -49,3 +49,96 @@ Rake::RDocTask.new do |rdoc|
|
|
|
49
49
|
rdoc.rdoc_files.include('README*')
|
|
50
50
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
51
51
|
end
|
|
52
|
+
|
|
53
|
+
require 'rake/gempackagetask'
|
|
54
|
+
|
|
55
|
+
gem_spec = Gem::Specification.new do |s|
|
|
56
|
+
s.name = %q{cameroncox-mousetrap}
|
|
57
|
+
s.version = "0.6.1"
|
|
58
|
+
|
|
59
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
60
|
+
s.authors = ["Jon Larkowski", "Sandro Turriate", "Wolfram Arnold", "Corey Grusden"]
|
|
61
|
+
s.date = %q{2010-07-16}
|
|
62
|
+
s.description = %q{CheddarGetter API Client in Ruby}
|
|
63
|
+
s.email = %q{jonlarkowski@gmail.com}
|
|
64
|
+
s.extra_rdoc_files = [
|
|
65
|
+
"README.textile"
|
|
66
|
+
]
|
|
67
|
+
s.files = [
|
|
68
|
+
".document",
|
|
69
|
+
".gitignore",
|
|
70
|
+
"MIT-LICENSE",
|
|
71
|
+
"README.textile",
|
|
72
|
+
"Rakefile",
|
|
73
|
+
"VERSION",
|
|
74
|
+
"lib/mousetrap.rb",
|
|
75
|
+
"lib/mousetrap/customer.rb",
|
|
76
|
+
"lib/mousetrap/invoice.rb",
|
|
77
|
+
"lib/mousetrap/plan.rb",
|
|
78
|
+
"lib/mousetrap/resource.rb",
|
|
79
|
+
"lib/mousetrap/subscription.rb",
|
|
80
|
+
"mousetrap.gemspec",
|
|
81
|
+
"script/authenticate.rb",
|
|
82
|
+
"script/cheddar_getter.example.yml",
|
|
83
|
+
"script/console",
|
|
84
|
+
"spec/factories.rb",
|
|
85
|
+
"spec/integration/settings.example.yml",
|
|
86
|
+
"spec/integration/smoke_test.rb",
|
|
87
|
+
"spec/integration/spike.rb",
|
|
88
|
+
"spec/mousetrap/customer_spec.rb",
|
|
89
|
+
"spec/mousetrap/plan_spec.rb",
|
|
90
|
+
"spec/mousetrap/resource_spec.rb",
|
|
91
|
+
"spec/mousetrap/subscription_spec.rb",
|
|
92
|
+
"spec/mousetrap_spec.rb",
|
|
93
|
+
"spec/spec.opts",
|
|
94
|
+
"spec/spec_helper.rb",
|
|
95
|
+
"spec/support/fixtures.rb",
|
|
96
|
+
"spec/support/random_data.rb"
|
|
97
|
+
]
|
|
98
|
+
s.homepage = %q{http://github.com/cameroncox/mousetrap}
|
|
99
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
100
|
+
s.require_paths = ["lib"]
|
|
101
|
+
s.rubygems_version = %q{1.3.7}
|
|
102
|
+
s.summary = %q{CheddarGetter API Client in Ruby}
|
|
103
|
+
s.test_files = [
|
|
104
|
+
"spec/factories.rb",
|
|
105
|
+
"spec/integration/smoke_test.rb",
|
|
106
|
+
"spec/integration/spike.rb",
|
|
107
|
+
"spec/mousetrap/customer_spec.rb",
|
|
108
|
+
"spec/mousetrap/plan_spec.rb",
|
|
109
|
+
"spec/mousetrap/resource_spec.rb",
|
|
110
|
+
"spec/mousetrap/subscription_spec.rb",
|
|
111
|
+
"spec/mousetrap_spec.rb",
|
|
112
|
+
"spec/spec_helper.rb",
|
|
113
|
+
"spec/support/fixtures.rb",
|
|
114
|
+
"spec/support/random_data.rb"
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
if s.respond_to? :specification_version then
|
|
118
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
119
|
+
s.specification_version = 3
|
|
120
|
+
|
|
121
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
122
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
|
123
|
+
s.add_development_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
124
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
|
125
|
+
s.add_development_dependency(%q<factory_girl>, [">= 1.2.3"])
|
|
126
|
+
else
|
|
127
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
|
128
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
129
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
130
|
+
s.add_dependency(%q<factory_girl>, [">= 1.2.3"])
|
|
131
|
+
end
|
|
132
|
+
else
|
|
133
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
|
134
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
135
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
136
|
+
s.add_dependency(%q<factory_girl>, [">= 1.2.3"])
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
Rake::GemPackageTask.new(gem_spec) do |p|
|
|
141
|
+
p.gem_spec = gem_spec
|
|
142
|
+
p.need_tar = true
|
|
143
|
+
p.need_zip = true
|
|
144
|
+
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.6.1
|
data/lib/mousetrap.rb
CHANGED
|
@@ -6,11 +6,14 @@ require 'httparty'
|
|
|
6
6
|
module Mousetrap
|
|
7
7
|
API_UNSUPPORTED = "CheddarGetter API doesn't support this."
|
|
8
8
|
|
|
9
|
+
class ApiDown < Exception
|
|
10
|
+
end
|
|
11
|
+
|
|
9
12
|
autoload :Customer, 'mousetrap/customer'
|
|
10
13
|
autoload :Plan, 'mousetrap/plan'
|
|
11
14
|
autoload :Resource, 'mousetrap/resource'
|
|
12
|
-
autoload :Subscription, 'mousetrap/subscription'
|
|
13
15
|
autoload :Invoice, 'mousetrap/invoice'
|
|
16
|
+
autoload :Subscription, 'mousetrap/subscription'
|
|
14
17
|
|
|
15
18
|
class << self
|
|
16
19
|
attr_accessor :product_code
|
data/lib/mousetrap/customer.rb
CHANGED
|
@@ -7,7 +7,48 @@ module Mousetrap
|
|
|
7
7
|
:first_name,
|
|
8
8
|
:last_name,
|
|
9
9
|
:company,
|
|
10
|
-
:subscription
|
|
10
|
+
:subscription,
|
|
11
|
+
:charges,
|
|
12
|
+
:items
|
|
13
|
+
|
|
14
|
+
def update_tracked_item_quantity(item_code, quantity = 1)
|
|
15
|
+
tracked_item_resource = if quantity == quantity.abs
|
|
16
|
+
'add-item-quantity'
|
|
17
|
+
else
|
|
18
|
+
'remove-item-quantity'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
attributes = {
|
|
22
|
+
:itemCode => item_code,
|
|
23
|
+
:quantity => quantity.abs
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
response = self.class.put_resource 'customers', tracked_item_resource, code, attributes
|
|
27
|
+
|
|
28
|
+
raise response['error'] if response['error']
|
|
29
|
+
response
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_item_quantity(item_code, quantity = 1)
|
|
33
|
+
update_tracked_item_quantity(item_code, quantity)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def remove_item_quantity(item_code, quantity = 1)
|
|
37
|
+
update_tracked_item_quantity(item_code, -quantity)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_custom_charge(item_code, amount = 1.0, quantity = 1, description = nil)
|
|
41
|
+
attributes = {
|
|
42
|
+
:chargeCode => item_code,
|
|
43
|
+
:eachAmount => amount,
|
|
44
|
+
:quantity => quantity,
|
|
45
|
+
:description => description
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
response = self.class.put_resource 'customers', 'add-charge', code, attributes
|
|
49
|
+
raise response['error'] if response['error']
|
|
50
|
+
response
|
|
51
|
+
end
|
|
11
52
|
|
|
12
53
|
def subscription_attributes=(attributes)
|
|
13
54
|
self.subscription = Subscription.new attributes
|
|
@@ -20,20 +61,12 @@ module Mousetrap
|
|
|
20
61
|
:email => email,
|
|
21
62
|
:first_name => first_name,
|
|
22
63
|
:last_name => last_name,
|
|
23
|
-
:company => company
|
|
64
|
+
:company => company,
|
|
65
|
+
:charges => charges,
|
|
66
|
+
:items => items
|
|
24
67
|
}
|
|
25
68
|
end
|
|
26
69
|
|
|
27
|
-
def add_item_quantity(item_code, quantity = 1)
|
|
28
|
-
attrs = { :itemCode => item_code, :quantity => quantity }
|
|
29
|
-
self.class.put_resource 'customers', 'add-item-quantity', code, attrs
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def remove_item_quantity(item_code, quantity = 1)
|
|
33
|
-
attrs = { :itemCode => item_code, :quantity => quantity }
|
|
34
|
-
self.class.put_resource 'customers', 'remove-item-quantity', code, attrs
|
|
35
|
-
end
|
|
36
|
-
|
|
37
70
|
def attributes_for_api
|
|
38
71
|
# TODO: superclass?
|
|
39
72
|
self.class.attributes_for_api(attributes, new_record?)
|
|
@@ -124,6 +157,9 @@ module Mousetrap
|
|
|
124
157
|
:lastName => attributes[:last_name],
|
|
125
158
|
:company => attributes[:company]
|
|
126
159
|
}
|
|
160
|
+
|
|
161
|
+
mutated_hash.merge!(:charges => attributes[:charges]) if attributes[:charges]
|
|
162
|
+
mutated_hash.merge!(:items => attributes[:items]) if attributes[:items]
|
|
127
163
|
mutated_hash.merge!(:code => attributes[:code]) if new_record
|
|
128
164
|
mutated_hash
|
|
129
165
|
end
|
data/lib/mousetrap/invoice.rb
CHANGED
|
@@ -6,6 +6,10 @@ module Mousetrap
|
|
|
6
6
|
:billing_date,
|
|
7
7
|
:created_at
|
|
8
8
|
|
|
9
|
+
def initialize(hash = {})
|
|
10
|
+
super(self.class.attributes_from_api(hash))
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
protected
|
|
10
14
|
|
|
11
15
|
def self.plural_resource_name
|
|
@@ -16,11 +20,14 @@ module Mousetrap
|
|
|
16
20
|
'invoice'
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
def attributes
|
|
24
|
+
{
|
|
25
|
+
:id => id,
|
|
26
|
+
:number => number,
|
|
27
|
+
:billing_date => billing_date,
|
|
28
|
+
:created_at => created_at
|
|
29
|
+
}
|
|
30
|
+
end
|
|
24
31
|
|
|
25
32
|
def self.attributes_from_api(attributes)
|
|
26
33
|
{
|
|
@@ -31,4 +38,4 @@ module Mousetrap
|
|
|
31
38
|
}
|
|
32
39
|
end
|
|
33
40
|
end
|
|
34
|
-
end
|
|
41
|
+
end
|
data/lib/mousetrap/plan.rb
CHANGED
|
@@ -6,7 +6,6 @@ module Mousetrap
|
|
|
6
6
|
:items,
|
|
7
7
|
:recurring_charge_amount
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
def self.all
|
|
11
10
|
response = get_resources plural_resource_name
|
|
12
11
|
return [] unless response['plans']
|
|
@@ -25,10 +24,10 @@ module Mousetrap
|
|
|
25
24
|
|
|
26
25
|
def self.attributes_from_api(attributes)
|
|
27
26
|
{
|
|
28
|
-
:code
|
|
29
|
-
:name
|
|
30
|
-
:items
|
|
31
|
-
:recurring_charge_amount
|
|
27
|
+
:code => attributes['code'],
|
|
28
|
+
:name => attributes['name'],
|
|
29
|
+
:items => attributes['items'],
|
|
30
|
+
:recurring_charge_amount => attributes['recurringChargeAmount']
|
|
32
31
|
}
|
|
33
32
|
end
|
|
34
33
|
end
|
data/lib/mousetrap/resource.rb
CHANGED
|
@@ -89,10 +89,14 @@ module Mousetrap
|
|
|
89
89
|
|
|
90
90
|
def self.get_resource(resource, code)
|
|
91
91
|
get resource_path(resource, 'get', code)
|
|
92
|
+
rescue Errno::ECONNREFUSED
|
|
93
|
+
raise_api_is_down
|
|
92
94
|
end
|
|
93
95
|
|
|
94
96
|
def self.get_resources(resource)
|
|
95
97
|
get resource_path(resource, 'get')
|
|
98
|
+
rescue Errno::ECONNREFUSED
|
|
99
|
+
raise_api_is_down
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
def self.member_action(resource, action, code, attributes = nil)
|
|
@@ -103,11 +107,15 @@ module Mousetrap
|
|
|
103
107
|
else
|
|
104
108
|
post path
|
|
105
109
|
end
|
|
110
|
+
rescue Errno::ECONNREFUSED
|
|
111
|
+
raise_api_is_down
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
def self.post_resource(resource, action, attributes)
|
|
109
115
|
path = resource_path(resource, action)
|
|
110
116
|
post path, :body => attributes
|
|
117
|
+
rescue Errno::ECONNREFUSED
|
|
118
|
+
raise_api_is_down
|
|
111
119
|
end
|
|
112
120
|
|
|
113
121
|
def self.put_resource(resource, action, code, attributes)
|
|
@@ -118,6 +126,10 @@ module Mousetrap
|
|
|
118
126
|
raise NotImplementedError, API_UNSUPPORTED
|
|
119
127
|
end
|
|
120
128
|
|
|
129
|
+
def self.raise_api_is_down
|
|
130
|
+
raise ApiDown, "CheddarGetter is currently down"
|
|
131
|
+
end
|
|
132
|
+
|
|
121
133
|
def self.resource_path(resource, action, code = nil)
|
|
122
134
|
path = "/xml/#{resource}/#{action}/productCode/#{uri_encode(Mousetrap.product_code)}"
|
|
123
135
|
path += "/code/#{uri_encode(code)}" if code
|
|
@@ -8,8 +8,14 @@ module Mousetrap
|
|
|
8
8
|
:credit_card_number,
|
|
9
9
|
:credit_card_expiration_month,
|
|
10
10
|
:credit_card_expiration_year,
|
|
11
|
+
:credit_card_code,
|
|
12
|
+
:billing_country,
|
|
13
|
+
:billing_address,
|
|
14
|
+
:billing_city,
|
|
15
|
+
:billing_state,
|
|
11
16
|
:billing_zip_code,
|
|
12
17
|
:plan,
|
|
18
|
+
|
|
13
19
|
:customer_code # belongs to customer
|
|
14
20
|
|
|
15
21
|
# Attributes that come _from_ the API.
|
|
@@ -20,8 +26,8 @@ module Mousetrap
|
|
|
20
26
|
:credit_card_expiration_date,
|
|
21
27
|
:credit_card_last_four_digits,
|
|
22
28
|
:credit_card_type,
|
|
23
|
-
:
|
|
24
|
-
:
|
|
29
|
+
:invoices,
|
|
30
|
+
:items
|
|
25
31
|
|
|
26
32
|
def self.[](code)
|
|
27
33
|
raise_api_unsupported_error
|
|
@@ -39,6 +45,16 @@ module Mousetrap
|
|
|
39
45
|
raise_api_unsupported_error
|
|
40
46
|
end
|
|
41
47
|
|
|
48
|
+
def current_invoice
|
|
49
|
+
invoice_attributes = if invoices['invoice'].kind_of?(Array)
|
|
50
|
+
invoices['invoice'][0]
|
|
51
|
+
else
|
|
52
|
+
invoices['invoice']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
Invoice.new(invoice_attributes)
|
|
56
|
+
end
|
|
57
|
+
|
|
42
58
|
def attributes
|
|
43
59
|
{
|
|
44
60
|
:id => id,
|
|
@@ -48,30 +64,15 @@ module Mousetrap
|
|
|
48
64
|
:credit_card_number => credit_card_number,
|
|
49
65
|
:credit_card_expiration_month => credit_card_expiration_month,
|
|
50
66
|
:credit_card_expiration_year => credit_card_expiration_year,
|
|
67
|
+
:credit_card_code => credit_card_code,
|
|
68
|
+
:billing_country => billing_country,
|
|
69
|
+
:billing_address => billing_address,
|
|
70
|
+
:billing_city => billing_city,
|
|
71
|
+
:billing_state => billing_state,
|
|
51
72
|
:billing_zip_code => billing_zip_code,
|
|
52
73
|
}
|
|
53
74
|
end
|
|
54
75
|
|
|
55
|
-
def current_invoice
|
|
56
|
-
invoice_record = if invoices['invoice'].kind_of?(Array)
|
|
57
|
-
Invoice.new({
|
|
58
|
-
:id => invoices['invoice'][0]['id'],
|
|
59
|
-
:number => invoices['invoice'][0]['number'],
|
|
60
|
-
:created_at => invoices['invoice'][0]['createdDatetime'],
|
|
61
|
-
:billing_date => invoices['invoice'][0]['billingDatetime']
|
|
62
|
-
})
|
|
63
|
-
else
|
|
64
|
-
Invoice.new({
|
|
65
|
-
:id => invoices['invoice']['id'],
|
|
66
|
-
:number => invoices['invoice']['number'],
|
|
67
|
-
:created_at => invoices['invoice']['createdDatetime'],
|
|
68
|
-
:billing_date => invoices['invoice']['billingDatetime']
|
|
69
|
-
})
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
invoice_record
|
|
73
|
-
end
|
|
74
|
-
|
|
75
76
|
def attributes_for_api
|
|
76
77
|
self.class.attributes_for_api(attributes)
|
|
77
78
|
end
|
|
@@ -115,6 +116,7 @@ module Mousetrap
|
|
|
115
116
|
:credit_card_expiration_date,
|
|
116
117
|
:credit_card_last_four_digits,
|
|
117
118
|
:credit_card_type,
|
|
119
|
+
:credit_card_verification_code,
|
|
118
120
|
:items,
|
|
119
121
|
:invoices
|
|
120
122
|
|
|
@@ -134,6 +136,11 @@ module Mousetrap
|
|
|
134
136
|
:ccNumber => attributes[:credit_card_number],
|
|
135
137
|
:ccExpMonth => ("%02d" % attributes[:credit_card_expiration_month] if attributes[:credit_card_expiration_month]),
|
|
136
138
|
:ccExpYear => attributes[:credit_card_expiration_year],
|
|
139
|
+
:ccCardCode => attributes[:credit_card_code],
|
|
140
|
+
:ccCountry => attributes[:billing_country],
|
|
141
|
+
:ccAddress => attributes[:billing_address],
|
|
142
|
+
:ccCity => attributes[:billing_city],
|
|
143
|
+
:ccState => attributes[:billing_state],
|
|
137
144
|
:ccZip => attributes[:billing_zip_code]
|
|
138
145
|
}
|
|
139
146
|
end
|
|
@@ -146,8 +153,8 @@ module Mousetrap
|
|
|
146
153
|
:credit_card_expiration_date => attributes['ccExpirationDate'],
|
|
147
154
|
:credit_card_last_four_digits => attributes['ccLastFour'],
|
|
148
155
|
:credit_card_type => attributes['ccType'],
|
|
149
|
-
:
|
|
150
|
-
:
|
|
156
|
+
:invoices => attributes['invoices'],
|
|
157
|
+
:items => attributes['items']
|
|
151
158
|
}
|
|
152
159
|
end
|
|
153
160
|
end
|
data/mousetrap.gemspec
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name = %q{mousetrap}
|
|
8
|
-
s.version = "0.
|
|
7
|
+
s.name = %q{cameroncox-mousetrap}
|
|
8
|
+
s.version = "0.6.1"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Jon Larkowski", "Sandro Turriate", "Wolfram Arnold", "Corey Grusden"]
|
|
12
|
-
s.date = %q{
|
|
12
|
+
s.date = %q{2010-07-16}
|
|
13
13
|
s.description = %q{CheddarGetter API Client in Ruby}
|
|
14
14
|
s.email = %q{jonlarkowski@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
"VERSION",
|
|
25
25
|
"lib/mousetrap.rb",
|
|
26
26
|
"lib/mousetrap/customer.rb",
|
|
27
|
+
"lib/mousetrap/invoice.rb",
|
|
27
28
|
"lib/mousetrap/plan.rb",
|
|
28
29
|
"lib/mousetrap/resource.rb",
|
|
29
30
|
"lib/mousetrap/subscription.rb",
|
|
@@ -45,10 +46,10 @@ Gem::Specification.new do |s|
|
|
|
45
46
|
"spec/support/fixtures.rb",
|
|
46
47
|
"spec/support/random_data.rb"
|
|
47
48
|
]
|
|
48
|
-
s.homepage = %q{http://github.com/
|
|
49
|
+
s.homepage = %q{http://github.com/cameroncox/mousetrap}
|
|
49
50
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
50
51
|
s.require_paths = ["lib"]
|
|
51
|
-
s.rubygems_version = %q{1.3.
|
|
52
|
+
s.rubygems_version = %q{1.3.7}
|
|
52
53
|
s.summary = %q{CheddarGetter API Client in Ruby}
|
|
53
54
|
s.test_files = [
|
|
54
55
|
"spec/factories.rb",
|
|
@@ -68,19 +69,19 @@ Gem::Specification.new do |s|
|
|
|
68
69
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
69
70
|
s.specification_version = 3
|
|
70
71
|
|
|
71
|
-
if Gem::Version.new(Gem::
|
|
72
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0.
|
|
72
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
73
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
|
73
74
|
s.add_development_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
74
75
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
|
75
76
|
s.add_development_dependency(%q<factory_girl>, [">= 1.2.3"])
|
|
76
77
|
else
|
|
77
|
-
s.add_dependency(%q<httparty>, [">= 0.
|
|
78
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
|
78
79
|
s.add_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
79
80
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
80
81
|
s.add_dependency(%q<factory_girl>, [">= 1.2.3"])
|
|
81
82
|
end
|
|
82
83
|
else
|
|
83
|
-
s.add_dependency(%q<httparty>, [">= 0.
|
|
84
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
|
84
85
|
s.add_dependency(%q<activesupport>, [">= 2.3.3"])
|
|
85
86
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
86
87
|
s.add_dependency(%q<factory_girl>, [">= 1.2.3"])
|
data/script/authenticate.rb
CHANGED
data/script/console
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift << File.join(File.dirname(__FILE__), "..", "lib")
|
|
4
|
+
|
|
5
|
+
require 'mousetrap'
|
|
6
|
+
require 'irb'
|
|
7
|
+
require 'yaml'
|
|
8
|
+
|
|
9
|
+
config_file = File.join(File.dirname(__FILE__), "..", "mousetrap_config.yml")
|
|
10
|
+
raise "#{config_file} must exist" unless File.exists?(config_file)
|
|
11
|
+
config = YAML.load_file(config_file)
|
|
12
|
+
Mousetrap.product_code = config['product_code']
|
|
13
|
+
Mousetrap.authenticate(config['username'], config['password'])
|
|
14
|
+
|
|
15
|
+
IRB.start
|
data/spec/factories.rb
CHANGED
|
@@ -19,7 +19,11 @@ Factory.define :subscription, :class => Mousetrap::Subscription, :default_strate
|
|
|
19
19
|
f.credit_card_number '4111111111111111'
|
|
20
20
|
f.credit_card_expiration_month '12'
|
|
21
21
|
f.credit_card_expiration_year '2012'
|
|
22
|
-
f.
|
|
22
|
+
f.billing_address "400 W 7th St\n#200"
|
|
23
|
+
f.billing_city 'Bloomington'
|
|
24
|
+
f.billing_state 'IN'
|
|
25
|
+
f.billing_country 'US'
|
|
26
|
+
f.billing_zip_code '47404'
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
Factory.define :alternate_subscription, :parent => :subscription, :default_strategy => :stub do |f|
|
|
@@ -115,6 +115,16 @@ describe "The Wrapper Gem" do
|
|
|
115
115
|
it_should_behave_like "a Customer record from CheddarGetter"
|
|
116
116
|
it_should_behave_like "an active Subscription record from CheddarGetter"
|
|
117
117
|
end
|
|
118
|
+
|
|
119
|
+
describe "When I create a customer with international card" do
|
|
120
|
+
before :all do
|
|
121
|
+
attributes = Factory.attributes_for :alt_new_customer
|
|
122
|
+
@customer = Mousetrap::Customer.create attributes_for
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it_should_behave_like "a Customer record from CheddarGetter"
|
|
126
|
+
it_should_behave_like "an active Subscription record from CheddarGetter"
|
|
127
|
+
end
|
|
118
128
|
end
|
|
119
129
|
|
|
120
130
|
describe ".destroy_all" do
|
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
|
2
2
|
|
|
3
3
|
describe Mousetrap::Customer do
|
|
4
4
|
include Fixtures
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def customer_attributes_for_api(customer)
|
|
7
7
|
{
|
|
8
8
|
:firstName => customer.first_name,
|
|
@@ -18,6 +18,10 @@ describe Mousetrap::Customer do
|
|
|
18
18
|
:ccExpMonth => customer.subscription.credit_card_expiration_month,
|
|
19
19
|
:ccExpYear => customer.subscription.credit_card_expiration_year,
|
|
20
20
|
:ccZip => customer.subscription.billing_zip_code,
|
|
21
|
+
:ccCountry => customer.subscription.billing_country,
|
|
22
|
+
:ccAddress => customer.subscription.billing_address,
|
|
23
|
+
:ccCity => customer.subscription.billing_city,
|
|
24
|
+
:ccState => customer.subscription.billing_state
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
end
|
|
@@ -265,7 +269,7 @@ describe Mousetrap::Customer do
|
|
|
265
269
|
|
|
266
270
|
it "posts a new customer" do
|
|
267
271
|
@customer.class.should_receive(:post_resource).with('customers', 'new', 'some_attributes').and_return({:id => 'some_id'})
|
|
268
|
-
@customer.class.stub :build_resource_from
|
|
272
|
+
@customer.class.stub :build_resource_from => stub(:id => 'some_id')
|
|
269
273
|
@customer.send :create
|
|
270
274
|
end
|
|
271
275
|
|
|
@@ -276,7 +280,7 @@ describe Mousetrap::Customer do
|
|
|
276
280
|
|
|
277
281
|
it "builds a customer from the CheddarGetter return values" do
|
|
278
282
|
@customer.class.stub :post_resource => 'some response'
|
|
279
|
-
@customer.class.should_receive(:build_resource_from).with('some response').and_return(:id => 'some_id')
|
|
283
|
+
@customer.class.should_receive(:build_resource_from).with('some response').and_return(stub(:id => 'some_id'))
|
|
280
284
|
@customer.send :create
|
|
281
285
|
end
|
|
282
286
|
|
|
@@ -319,20 +323,57 @@ describe Mousetrap::Customer do
|
|
|
319
323
|
end
|
|
320
324
|
end
|
|
321
325
|
end
|
|
326
|
+
|
|
327
|
+
describe '#add_custom_charge' do
|
|
328
|
+
context "when there's a subscription instance" do
|
|
329
|
+
before :all do
|
|
330
|
+
@customer = Factory(:new_customer)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it "should not raise an error with CheddarGetter" do
|
|
334
|
+
@customer.class.should_receive(:put_resource).with('customers', 'add-charge', @customer.code, { :eachAmount => 45.00, :chargeCode => 'BOGUS', :quantity => 1, :description => nil }).and_return({ :id => 'some_id' })
|
|
335
|
+
@customer.add_custom_charge('BOGUS', 45.00, 1, nil)
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
context "with there is not a subscription" do
|
|
340
|
+
before :all do
|
|
341
|
+
@customer = Mousetrap::Customer.new
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
it "should raise an error with CheddarGetter" do
|
|
345
|
+
@customer.class.stub :put_resource => { 'error' => 'some error message' }
|
|
346
|
+
expect { @customer.add_custom_charge('BOGUS') }.to raise_error('some error message')
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# describe '#update_tracked_item_quantity' do
|
|
352
|
+
# context "when there's a subscription instance" do
|
|
353
|
+
# before do
|
|
354
|
+
# @customer = Factory(:new_customer)
|
|
355
|
+
# end
|
|
356
|
+
#
|
|
357
|
+
# it "should not raise an error with CheddarGetter" do
|
|
358
|
+
# @customer.class.should_receive(:put_resource).with('customers', 'add-item-quantity', @customer.code, { :quantity => 1, :itemCode => 'BOGUS' }).and_return({ :id => 'some_id' })
|
|
359
|
+
# @customer.update_tracked_item_quantity('BOGUS', 1).should_not raise_error
|
|
360
|
+
# end
|
|
361
|
+
# end
|
|
362
|
+
# end
|
|
322
363
|
end
|
|
323
364
|
|
|
324
365
|
|
|
325
366
|
__END__
|
|
326
367
|
|
|
327
|
-
customers:
|
|
328
|
-
customer:
|
|
329
|
-
company:
|
|
368
|
+
customers:
|
|
369
|
+
customer:
|
|
370
|
+
company:
|
|
330
371
|
lastName: cgejerpkyw
|
|
331
372
|
code: krylmrreef@example.com
|
|
332
|
-
subscriptions:
|
|
333
|
-
subscription:
|
|
334
|
-
plans:
|
|
335
|
-
plan:
|
|
373
|
+
subscriptions:
|
|
374
|
+
subscription:
|
|
375
|
+
plans:
|
|
376
|
+
plan:
|
|
336
377
|
name: Test
|
|
337
378
|
setupChargeAmount: "42.00"
|
|
338
379
|
code: TEST
|
|
@@ -348,18 +389,18 @@ customers:
|
|
|
348
389
|
description: This is my test plan. There are many like it, but this one is mine.
|
|
349
390
|
billingFrequencyPer: month
|
|
350
391
|
setupChargeCode: TEST_SETUP
|
|
351
|
-
gatewayToken:
|
|
392
|
+
gatewayToken:
|
|
352
393
|
id: 7ccea6de-0a4d-102d-a92d-40402145ee8b
|
|
353
394
|
createdDatetime: "2009-10-14T20:08:14+00:00"
|
|
354
395
|
ccType: visa
|
|
355
396
|
ccLastFour: "1111"
|
|
356
397
|
ccExpirationDate: "2012-12-31T00:00:00+00:00"
|
|
357
|
-
canceledDatetime:
|
|
358
|
-
invoices:
|
|
359
|
-
invoice:
|
|
398
|
+
canceledDatetime:
|
|
399
|
+
invoices:
|
|
400
|
+
invoice:
|
|
360
401
|
- number: "5"
|
|
361
|
-
transactions:
|
|
362
|
-
transaction:
|
|
402
|
+
transactions:
|
|
403
|
+
transaction:
|
|
363
404
|
response: approved
|
|
364
405
|
code: ""
|
|
365
406
|
amount: "42.00"
|
|
@@ -367,17 +408,17 @@ customers:
|
|
|
367
408
|
id: 7ce53c78-0a4d-102d-a92d-40402145ee8b
|
|
368
409
|
createdDatetime: "2009-10-14T20:08:14+00:00"
|
|
369
410
|
transactedDatetime: "2009-10-14T20:08:14+00:00"
|
|
370
|
-
parentId:
|
|
371
|
-
charges:
|
|
372
|
-
charge:
|
|
411
|
+
parentId:
|
|
412
|
+
charges:
|
|
413
|
+
charge:
|
|
373
414
|
code: TEST_SETUP
|
|
374
415
|
quantity: "1"
|
|
375
416
|
id: 7ce2cb6e-0a4d-102d-a92d-40402145ee8b
|
|
376
417
|
createdDatetime: "2009-10-14T20:08:14+00:00"
|
|
377
418
|
type: setup
|
|
378
419
|
eachAmount: "42.00"
|
|
379
|
-
description:
|
|
380
|
-
gatewayAccount:
|
|
420
|
+
description:
|
|
421
|
+
gatewayAccount:
|
|
381
422
|
id: ""
|
|
382
423
|
billingDatetime: "2009-10-14T20:08:14+00:00"
|
|
383
424
|
id: 7cd25072-0a4d-102d-a92d-40402145ee8b
|
|
@@ -388,7 +429,7 @@ customers:
|
|
|
388
429
|
id: 7cd4253c-0a4d-102d-a92d-40402145ee8b
|
|
389
430
|
createdDatetime: "2009-10-14T20:08:14+00:00"
|
|
390
431
|
type: subscription
|
|
391
|
-
gatewayToken:
|
|
432
|
+
gatewayToken:
|
|
392
433
|
id: 7ccd6e5e-0a4d-102d-a92d-40402145ee8b
|
|
393
434
|
createdDatetime: "2009-10-14T20:08:14+00:00"
|
|
394
435
|
modifiedDatetime: "2009-10-14T20:08:14+00:00"
|
metadata
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cameroncox-mousetrap
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 5
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 6
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.6.1
|
|
5
11
|
platform: ruby
|
|
6
12
|
authors:
|
|
7
13
|
- Jon Larkowski
|
|
@@ -12,49 +18,73 @@ autorequire:
|
|
|
12
18
|
bindir: bin
|
|
13
19
|
cert_chain: []
|
|
14
20
|
|
|
15
|
-
date: 2010-
|
|
21
|
+
date: 2010-07-16 00:00:00 -04:00
|
|
16
22
|
default_executable:
|
|
17
23
|
dependencies:
|
|
18
24
|
- !ruby/object:Gem::Dependency
|
|
19
25
|
name: httparty
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
prerelease: false
|
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
23
29
|
requirements:
|
|
24
30
|
- - ">="
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
hash: 5
|
|
33
|
+
segments:
|
|
34
|
+
- 0
|
|
35
|
+
- 6
|
|
36
|
+
- 1
|
|
37
|
+
version: 0.6.1
|
|
38
|
+
type: :runtime
|
|
39
|
+
version_requirements: *id001
|
|
28
40
|
- !ruby/object:Gem::Dependency
|
|
29
41
|
name: activesupport
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
prerelease: false
|
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
44
|
+
none: false
|
|
33
45
|
requirements:
|
|
34
46
|
- - ">="
|
|
35
47
|
- !ruby/object:Gem::Version
|
|
48
|
+
hash: 5
|
|
49
|
+
segments:
|
|
50
|
+
- 2
|
|
51
|
+
- 3
|
|
52
|
+
- 3
|
|
36
53
|
version: 2.3.3
|
|
37
|
-
|
|
54
|
+
type: :development
|
|
55
|
+
version_requirements: *id002
|
|
38
56
|
- !ruby/object:Gem::Dependency
|
|
39
57
|
name: rspec
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
prerelease: false
|
|
59
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
60
|
+
none: false
|
|
43
61
|
requirements:
|
|
44
62
|
- - ">="
|
|
45
63
|
- !ruby/object:Gem::Version
|
|
64
|
+
hash: 13
|
|
65
|
+
segments:
|
|
66
|
+
- 1
|
|
67
|
+
- 2
|
|
68
|
+
- 9
|
|
46
69
|
version: 1.2.9
|
|
47
|
-
|
|
70
|
+
type: :development
|
|
71
|
+
version_requirements: *id003
|
|
48
72
|
- !ruby/object:Gem::Dependency
|
|
49
73
|
name: factory_girl
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
prerelease: false
|
|
75
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
76
|
+
none: false
|
|
53
77
|
requirements:
|
|
54
78
|
- - ">="
|
|
55
79
|
- !ruby/object:Gem::Version
|
|
80
|
+
hash: 25
|
|
81
|
+
segments:
|
|
82
|
+
- 1
|
|
83
|
+
- 2
|
|
84
|
+
- 3
|
|
56
85
|
version: 1.2.3
|
|
57
|
-
|
|
86
|
+
type: :development
|
|
87
|
+
version_requirements: *id004
|
|
58
88
|
description: CheddarGetter API Client in Ruby
|
|
59
89
|
email: jonlarkowski@gmail.com
|
|
60
90
|
executables: []
|
|
@@ -103,21 +133,27 @@ rdoc_options:
|
|
|
103
133
|
require_paths:
|
|
104
134
|
- lib
|
|
105
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
|
+
none: false
|
|
106
137
|
requirements:
|
|
107
138
|
- - ">="
|
|
108
139
|
- !ruby/object:Gem::Version
|
|
140
|
+
hash: 3
|
|
141
|
+
segments:
|
|
142
|
+
- 0
|
|
109
143
|
version: "0"
|
|
110
|
-
version:
|
|
111
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
|
+
none: false
|
|
112
146
|
requirements:
|
|
113
147
|
- - ">="
|
|
114
148
|
- !ruby/object:Gem::Version
|
|
149
|
+
hash: 3
|
|
150
|
+
segments:
|
|
151
|
+
- 0
|
|
115
152
|
version: "0"
|
|
116
|
-
version:
|
|
117
153
|
requirements: []
|
|
118
154
|
|
|
119
155
|
rubyforge_project:
|
|
120
|
-
rubygems_version: 1.3.
|
|
156
|
+
rubygems_version: 1.3.7
|
|
121
157
|
signing_key:
|
|
122
158
|
specification_version: 3
|
|
123
159
|
summary: CheddarGetter API Client in Ruby
|