chargify2 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/chargify2.gemspec +105 -0
- data/lib/chargify2/direct.rb +14 -8
- data/lib/chargify2/resource.rb +1 -1
- data/spec/direct_response_parameters_spec.rb +75 -0
- data/spec/direct_secure_parameters_spec.rb +1 -1
- data/spec/direct_spec.rb +3 -65
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/chargify2.gemspec
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{chargify2}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Klett"]
|
12
|
+
s.date = %q{2011-04-20}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{michael@webadvocate.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"chargify2.gemspec",
|
29
|
+
"lib/chargify2.rb",
|
30
|
+
"lib/chargify2/client.rb",
|
31
|
+
"lib/chargify2/direct.rb",
|
32
|
+
"lib/chargify2/representations/call.rb",
|
33
|
+
"lib/chargify2/resource.rb",
|
34
|
+
"lib/chargify2/resources/call_resource.rb",
|
35
|
+
"lib/chargify2/utils.rb",
|
36
|
+
"spec/call_resource_spec.rb",
|
37
|
+
"spec/client_spec.rb",
|
38
|
+
"spec/direct_response_parameters_spec.rb",
|
39
|
+
"spec/direct_secure_parameters_spec.rb",
|
40
|
+
"spec/direct_spec.rb",
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/support/spec_helper_methods.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/chargify/chargify2}
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.7}
|
48
|
+
s.summary = %q{Chargify API V2 Ruby Wrapper}
|
49
|
+
s.test_files = [
|
50
|
+
"spec/call_resource_spec.rb",
|
51
|
+
"spec/client_spec.rb",
|
52
|
+
"spec/direct_response_parameters_spec.rb",
|
53
|
+
"spec/direct_secure_parameters_spec.rb",
|
54
|
+
"spec/direct_spec.rb",
|
55
|
+
"spec/spec_helper.rb",
|
56
|
+
"spec/support/spec_helper_methods.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
65
|
+
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
67
|
+
s.add_runtime_dependency(%q<hashery>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
69
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
70
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
72
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<vcr>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<capybara>, [">= 0"])
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
78
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
79
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
80
|
+
s.add_dependency(%q<hashery>, [">= 0"])
|
81
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
82
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
83
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
84
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
85
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
86
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
87
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
88
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
89
|
+
end
|
90
|
+
else
|
91
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
92
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
93
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
94
|
+
s.add_dependency(%q<hashery>, [">= 0"])
|
95
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
96
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
97
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
98
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
99
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
100
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
101
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
102
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
data/lib/chargify2/direct.rb
CHANGED
@@ -11,8 +11,8 @@ module Chargify2
|
|
11
11
|
SecureParameters.new(params, client)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def response_parameters(params = {})
|
15
|
+
ResponseParameters.new(params, client)
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.signature(message, secret)
|
@@ -90,14 +90,16 @@ module Chargify2
|
|
90
90
|
end
|
91
91
|
|
92
92
|
unless api_id && secret && api_id.to_s.length > 0 && secret.to_s.length > 0
|
93
|
-
|
93
|
+
raise ArgumentError.new("SecureParameters require connection to a Client - was one given?")
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
# There is no need to instantiate a
|
99
|
-
class
|
98
|
+
# There is no need to instantiate a ResponseParameters instance directly. Use Direct#response_parameters instead.
|
99
|
+
class ResponseParameters
|
100
100
|
attr_reader :api_id
|
101
|
+
attr_reader :timestamp
|
102
|
+
attr_reader :nonce
|
101
103
|
attr_reader :status_code
|
102
104
|
attr_reader :result_code
|
103
105
|
attr_reader :call_id
|
@@ -111,13 +113,17 @@ module Chargify2
|
|
111
113
|
@secret = client.api_secret
|
112
114
|
|
113
115
|
@status_code = args[:status_code]
|
116
|
+
@timestamp = args[:timestamp]
|
117
|
+
@nonce = args[:nonce]
|
114
118
|
@result_code = args[:result_code]
|
115
119
|
@call_id = args[:call_id]
|
116
120
|
@signature = args[:signature]
|
121
|
+
|
122
|
+
validate_args
|
117
123
|
end
|
118
124
|
|
119
125
|
def verified?
|
120
|
-
message = "#{api_id}#{status_code}#{result_code}#{call_id}"
|
126
|
+
message = "#{api_id}#{timestamp}#{nonce}#{status_code}#{result_code}#{call_id}"
|
121
127
|
Direct.signature(message, secret) == signature
|
122
128
|
end
|
123
129
|
|
@@ -128,8 +134,8 @@ module Chargify2
|
|
128
134
|
private
|
129
135
|
|
130
136
|
def validate_args
|
131
|
-
|
132
|
-
raise ArgumentError.new("
|
137
|
+
unless api_id && secret && api_id.to_s.length > 0 && secret.to_s.length > 0
|
138
|
+
raise ArgumentError.new("ResponseParameters require connection to a Client - was one given?")
|
133
139
|
end
|
134
140
|
end
|
135
141
|
end
|
data/lib/chargify2/resource.rb
CHANGED
@@ -45,7 +45,7 @@ module Chargify2
|
|
45
45
|
|
46
46
|
def self.read(id, query = {})
|
47
47
|
response = get("#{uri}/#{id}", :query => query.empty? ? nil : query)
|
48
|
-
response_hash = response
|
48
|
+
response_hash = response[representation.to_s.downcase.split('::').last] || {}
|
49
49
|
representation.new(response_hash.symbolize_keys)
|
50
50
|
end
|
51
51
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Chargify2
|
4
|
+
describe Direct::ResponseParameters do
|
5
|
+
let(:client) { Client.new(valid_client_credentials) }
|
6
|
+
|
7
|
+
it "raises an argument error if it could not get an api_id and secret from the passed client" do
|
8
|
+
lambda {
|
9
|
+
Direct::SecureParameters.new({}, OpenCascade.new)
|
10
|
+
}.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#verified?" do
|
14
|
+
before(:each) do
|
15
|
+
@api_id = valid_client_credentials[:api_id]
|
16
|
+
@timestamp = '1303245326'
|
17
|
+
@nonce = @api_id
|
18
|
+
@status_code = '200'
|
19
|
+
@result_code = '2000'
|
20
|
+
@call_id = 'blah'
|
21
|
+
|
22
|
+
# Used the generator here: http://hash.online-convert.com/sha1-generator
|
23
|
+
# ... with message: "1c016050-498a-012e-91b1-005056a216ab13032453261c016050-498a-012e-91b1-005056a216ab2002000blah"
|
24
|
+
# ... and secret: "p5lxQ804MYtwZecFWNOT"
|
25
|
+
# ... to get: "cfce3418f5fc4454a309fe01c918b90916d6c36a"
|
26
|
+
@signature = "cfce3418f5fc4454a309fe01c918b90916d6c36a"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns true when all of the expected params are present and the signature matches the calculated signature" do
|
30
|
+
rp = Direct::ResponseParameters.new({
|
31
|
+
'api_id' => @api_id,
|
32
|
+
'timestamp' => @timestamp,
|
33
|
+
'nonce' => @nonce,
|
34
|
+
'status_code' => @status_code,
|
35
|
+
'result_code' => @result_code,
|
36
|
+
'call_id' => @call_id,
|
37
|
+
'signature' => @signature
|
38
|
+
}, client)
|
39
|
+
|
40
|
+
rp.verified?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false when the calculated signature of the result params is different from the received signature" do
|
44
|
+
rp = Direct::ResponseParameters.new({
|
45
|
+
'api_id' => @api_id,
|
46
|
+
'timestamp' => @timestamp,
|
47
|
+
'nonce' => @nonce,
|
48
|
+
'status_code' => @status_code,
|
49
|
+
'result_code' => @result_code,
|
50
|
+
'call_id' => @call_id,
|
51
|
+
'signature' => 'foo'
|
52
|
+
}, client)
|
53
|
+
|
54
|
+
rp.verified?.should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns false when the calculated signature is correct but the api_id does not match the client's" do
|
58
|
+
other_client_credentials = valid_client_credentials.merge(:api_id => '1')
|
59
|
+
other_client = Client.new(other_client_credentials)
|
60
|
+
|
61
|
+
rp = Direct::ResponseParameters.new({
|
62
|
+
'api_id' => @api_id,
|
63
|
+
'timestamp' => @timestamp,
|
64
|
+
'nonce' => @nonce,
|
65
|
+
'status_code' => @status_code,
|
66
|
+
'result_code' => @result_code,
|
67
|
+
'call_id' => @call_id,
|
68
|
+
'signature' => @signature
|
69
|
+
}, other_client)
|
70
|
+
|
71
|
+
rp.verified?.should be_false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -12,7 +12,7 @@ module Chargify2
|
|
12
12
|
|
13
13
|
it "raises an argument error if it could not get an api_id and secret from the passed client" do
|
14
14
|
lambda {
|
15
|
-
Direct::SecureParameters.new({
|
15
|
+
Direct::SecureParameters.new({}, OpenCascade.new)
|
16
16
|
}.should raise_error(ArgumentError)
|
17
17
|
end
|
18
18
|
|
data/spec/direct_spec.rb
CHANGED
@@ -59,73 +59,11 @@ module Chargify2
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
describe "#
|
62
|
+
describe "#response_parameters" do
|
63
63
|
let(:direct) { Direct.new(client) }
|
64
64
|
|
65
|
-
it "generates a new
|
66
|
-
direct.
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe Direct::Result do
|
71
|
-
describe "#verified?" do
|
72
|
-
it "returns true when the calculated signature of the result params matches the received signature" do
|
73
|
-
api_id = '1c016050-498a-012e-91b1-005056a216ab'
|
74
|
-
status_code = '200'
|
75
|
-
result_code = '2000'
|
76
|
-
call_id = '1234'
|
77
|
-
|
78
|
-
# Used the generator here: http://hash.online-convert.com/sha1-generator
|
79
|
-
# ... with message: "1c016050-498a-012e-91b1-005056a216ab20020001234"
|
80
|
-
# ... and secret: "p5lxQ804MYtwZecFWNOT"
|
81
|
-
# ... to get: "9d1b9139d6c49720faa0b2b6207c95060e6695d4"
|
82
|
-
signature = "9d1b9139d6c49720faa0b2b6207c95060e6695d4"
|
83
|
-
|
84
|
-
r = Direct::Result.new({
|
85
|
-
'api_id' => api_id,
|
86
|
-
'status_code' => status_code,
|
87
|
-
'result_code' => result_code,
|
88
|
-
'call_id' => call_id,
|
89
|
-
'signature' => signature}, client)
|
90
|
-
|
91
|
-
r.verified?.should be_true
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns false when the calculated signature of the result params is different from the received signature" do
|
95
|
-
r = Direct::Result.new({
|
96
|
-
'api_id' => client.api_id,
|
97
|
-
'status_code' => '2',
|
98
|
-
'result_code' => '3',
|
99
|
-
'call_id' => '4',
|
100
|
-
'signature' => '5'}, client)
|
101
|
-
|
102
|
-
r.verified?.should be_false
|
103
|
-
end
|
104
|
-
|
105
|
-
it "returns false when the calculated signature is correct but the api_id does not match the client's'" do
|
106
|
-
api_id = '1c016050-498a-012e-91b1-005056a216ab'
|
107
|
-
status_code = '200'
|
108
|
-
result_code = '2000'
|
109
|
-
call_id = '1234'
|
110
|
-
|
111
|
-
# Used the generator here: http://hash.online-convert.com/sha1-generator
|
112
|
-
# ... with message: "1c016050-498a-012e-91b1-005056a216ab20020001234"
|
113
|
-
# ... and secret: "p5lxQ804MYtwZecFWNOT"
|
114
|
-
# ... to get: "9d1b9139d6c49720faa0b2b6207c95060e6695d4"
|
115
|
-
signature = "9d1b9139d6c49720faa0b2b6207c95060e6695d4"
|
116
|
-
|
117
|
-
client_credentials = valid_client_credentials
|
118
|
-
client_credentials[:api_id] = '1234'
|
119
|
-
different_client = Client.new(client_credentials)
|
120
|
-
r = Direct::Result.new({
|
121
|
-
'api_id' => api_id,
|
122
|
-
'status_code' => status_code,
|
123
|
-
'result_code' => result_code,
|
124
|
-
'call_id' => call_id,
|
125
|
-
'signature' => signature}, different_client)
|
126
|
-
|
127
|
-
r.verified?.should be_false
|
128
|
-
end
|
65
|
+
it "generates a new ResponseParameters instance given a hash of response params" do
|
66
|
+
direct.response_parameters({}).should be_a(Direct::ResponseParameters)
|
129
67
|
end
|
130
68
|
end
|
131
69
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargify2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Klett
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-20 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- README.md
|
213
213
|
- Rakefile
|
214
214
|
- VERSION
|
215
|
+
- chargify2.gemspec
|
215
216
|
- lib/chargify2.rb
|
216
217
|
- lib/chargify2/client.rb
|
217
218
|
- lib/chargify2/direct.rb
|
@@ -221,6 +222,7 @@ files:
|
|
221
222
|
- lib/chargify2/utils.rb
|
222
223
|
- spec/call_resource_spec.rb
|
223
224
|
- spec/client_spec.rb
|
225
|
+
- spec/direct_response_parameters_spec.rb
|
224
226
|
- spec/direct_secure_parameters_spec.rb
|
225
227
|
- spec/direct_spec.rb
|
226
228
|
- spec/spec_helper.rb
|
@@ -262,6 +264,7 @@ summary: Chargify API V2 Ruby Wrapper
|
|
262
264
|
test_files:
|
263
265
|
- spec/call_resource_spec.rb
|
264
266
|
- spec/client_spec.rb
|
267
|
+
- spec/direct_response_parameters_spec.rb
|
265
268
|
- spec/direct_secure_parameters_spec.rb
|
266
269
|
- spec/direct_spec.rb
|
267
270
|
- spec/spec_helper.rb
|