chargify2 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -15,4 +15,5 @@ group :development do
15
15
  gem "webmock"
16
16
  gem "vcr"
17
17
  gem "capybara"
18
+ gem "ruby-debug19", :platforms => [:ruby_19]
18
19
  end
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  addressable (2.2.5)
5
+ archive-tar-minitar (0.5.2)
5
6
  capybara (0.4.1.2)
6
7
  celerity (>= 0.7.9)
7
8
  culerity (>= 0.2.4)
@@ -14,6 +15,7 @@ GEM
14
15
  celerity (0.8.9)
15
16
  childprocess (0.1.8)
16
17
  ffi (~> 1.0.6)
18
+ columnize (0.3.4)
17
19
  crack (0.1.8)
18
20
  culerity (0.2.15)
19
21
  diff-lcs (1.1.2)
@@ -29,6 +31,8 @@ GEM
29
31
  git (>= 1.2.5)
30
32
  rake
31
33
  json_pure (1.5.1)
34
+ linecache19 (0.5.12)
35
+ ruby_core_source (>= 0.1.4)
32
36
  mime-types (1.16)
33
37
  nokogiri (1.4.4)
34
38
  rack (1.2.2)
@@ -44,6 +48,16 @@ GEM
44
48
  rspec-expectations (2.3.0)
45
49
  diff-lcs (~> 1.1.2)
46
50
  rspec-mocks (2.3.0)
51
+ ruby-debug-base19 (0.11.25)
52
+ columnize (>= 0.3.1)
53
+ linecache19 (>= 0.5.11)
54
+ ruby_core_source (>= 0.1.4)
55
+ ruby-debug19 (0.11.6)
56
+ columnize (>= 0.3.1)
57
+ linecache19 (>= 0.5.11)
58
+ ruby-debug-base19 (>= 0.11.19)
59
+ ruby_core_source (0.1.5)
60
+ archive-tar-minitar (>= 0.5.2)
47
61
  rubyzip (0.9.4)
48
62
  selenium-webdriver (0.1.4)
49
63
  childprocess (>= 0.1.7)
@@ -71,6 +85,7 @@ DEPENDENCIES
71
85
  jeweler (~> 1.5.2)
72
86
  rcov
73
87
  rspec (~> 2.3.0)
88
+ ruby-debug19
74
89
  vcr
75
90
  webmock
76
91
  yard (~> 0.6.0)
data/chargify2.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chargify2}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
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-10-19}
11
+ s.authors = ["Michael Klett", "Shay Frendt"]
12
+ s.date = %q{2011-10-28}
13
13
  s.description = %q{}
14
14
  s.email = %q{michael@webadvocate.com}
15
15
  s.extra_rdoc_files = [
@@ -1,12 +1,12 @@
1
1
  module Chargify2
2
2
  class Direct
3
3
  attr_reader :client
4
-
4
+
5
5
  def initialize(client)
6
6
  @client = client
7
7
  validate_client
8
8
  end
9
-
9
+
10
10
  def secure_parameters(params = {})
11
11
  SecureParameters.new(params, client)
12
12
  end
@@ -18,9 +18,9 @@ module Chargify2
18
18
  def self.signature(message, secret)
19
19
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), secret, message)
20
20
  end
21
-
21
+
22
22
  private
23
-
23
+
24
24
  def validate_client
25
25
  unless client.is_a?(Client)
26
26
  raise ArgumentError.new("Direct.new requires a Client as an argument")
@@ -35,20 +35,20 @@ module Chargify2
35
35
  attr_reader :nonce
36
36
  attr_reader :data
37
37
  attr_reader :secret
38
-
38
+
39
39
  def initialize(hash, client)
40
40
  args = hash.symbolize_keys
41
-
41
+
42
42
  @api_id = client.api_id
43
43
  @secret = client.api_secret
44
44
 
45
45
  @timestamp = args[:timestamp]
46
46
  @nonce = args[:nonce]
47
47
  @data = args[:data]
48
-
48
+
49
49
  validate_args
50
50
  end
51
-
51
+
52
52
  def to_form_inputs
53
53
  output = []
54
54
  output << %{<input type="hidden" name="secure[api_id]" value="#{h(api_id)}"/>}
@@ -59,42 +59,42 @@ module Chargify2
59
59
  output.join("\n")
60
60
  end
61
61
 
62
- %w(timestamp nonce data).each do |method|
62
+ %w(timestamp nonce data api_id secret).each do |method|
63
63
  define_method("#{method}?") do
64
64
  value = self.send(method)
65
- value && value.to_s.strip.length > 0
65
+ value && !(value.is_a?(Hash) ? value : value.to_s.strip).empty?
66
66
  end
67
67
  end
68
-
68
+
69
69
  def encoded_data
70
70
  hash = data? ? data : {}
71
71
  uri = Addressable::URI.new
72
72
  uri.query_values = hash
73
73
  uri.query
74
74
  end
75
-
75
+
76
76
  def signature
77
77
  message = "#{api_id}#{timestamp}#{nonce}#{encoded_data}"
78
78
  Direct.signature(message, secret)
79
79
  end
80
-
80
+
81
81
  private
82
-
82
+
83
83
  def h(s)
84
84
  ERB::Util.html_escape(s)
85
85
  end
86
-
86
+
87
87
  def validate_args
88
88
  if data && !data.is_a?(Hash)
89
89
  raise ArgumentError.new("The 'data' must be provided as a Hash (you passed a #{data.class})")
90
90
  end
91
-
92
- unless api_id && secret && api_id.to_s.length > 0 && secret.to_s.length > 0
91
+
92
+ unless api_id? && secret?
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
98
  # There is no need to instantiate a ResponseParameters instance directly. Use Direct#response_parameters instead.
99
99
  class ResponseParameters
100
100
  attr_reader :api_id
@@ -105,10 +105,10 @@ module Chargify2
105
105
  attr_reader :call_id
106
106
  attr_reader :secret
107
107
  attr_reader :signature
108
-
108
+
109
109
  def initialize(params, client)
110
110
  args = params.symbolize_keys
111
-
111
+
112
112
  @api_id = client.api_id
113
113
  @secret = client.api_secret
114
114
 
@@ -118,21 +118,21 @@ module Chargify2
118
118
  @result_code = args[:result_code]
119
119
  @call_id = args[:call_id]
120
120
  @signature = args[:signature]
121
-
121
+
122
122
  validate_args
123
123
  end
124
-
124
+
125
125
  def verified?
126
126
  message = "#{api_id}#{timestamp}#{nonce}#{status_code}#{result_code}#{call_id}"
127
127
  Direct.signature(message, secret) == signature
128
128
  end
129
-
129
+
130
130
  def success?
131
131
  status_code.to_s == '200'
132
132
  end
133
-
133
+
134
134
  private
135
-
135
+
136
136
  def validate_args
137
137
  unless api_id && secret && api_id.to_s.length > 0 && secret.to_s.length > 0
138
138
  raise ArgumentError.new("ResponseParameters require connection to a Client - was one given?")
@@ -140,4 +140,4 @@ module Chargify2
140
140
  end
141
141
  end
142
142
  end
143
- end
143
+ end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  module Chargify2
4
4
  describe Direct::ResponseParameters do
5
5
  let(:client) { Client.new(valid_client_credentials) }
6
-
6
+
7
7
  it "raises an argument error if it could not get an api_id and secret from the passed client" do
8
8
  lambda {
9
9
  Direct::SecureParameters.new({}, OpenCascade.new)
10
10
  }.should raise_error(ArgumentError)
11
11
  end
12
-
12
+
13
13
  describe "#verified?" do
14
14
  before(:each) do
15
15
  @api_id = valid_client_credentials[:api_id]
@@ -18,7 +18,7 @@ module Chargify2
18
18
  @status_code = '200'
19
19
  @result_code = '2000'
20
20
  @call_id = 'blah'
21
-
21
+
22
22
  # Used the generator here: http://hash.online-convert.com/sha1-generator
23
23
  # ... with message: "1c016050-498a-012e-91b1-005056a216ab13032453261c016050-498a-012e-91b1-005056a216ab2002000blah"
24
24
  # ... and secret: "p5lxQ804MYtwZecFWNOT"
@@ -36,10 +36,10 @@ module Chargify2
36
36
  'call_id' => @call_id,
37
37
  'signature' => @signature
38
38
  }, client)
39
-
39
+
40
40
  rp.verified?.should be_true
41
41
  end
42
-
42
+
43
43
  it "returns false when the calculated signature of the result params is different from the received signature" do
44
44
  rp = Direct::ResponseParameters.new({
45
45
  'api_id' => @api_id,
@@ -50,10 +50,10 @@ module Chargify2
50
50
  'call_id' => @call_id,
51
51
  'signature' => 'foo'
52
52
  }, client)
53
-
53
+
54
54
  rp.verified?.should be_false
55
55
  end
56
-
56
+
57
57
  it "returns false when the calculated signature is correct but the api_id does not match the client's" do
58
58
  other_client_credentials = valid_client_credentials.merge(:api_id => '1')
59
59
  other_client = Client.new(other_client_credentials)
@@ -67,9 +67,9 @@ module Chargify2
67
67
  'call_id' => @call_id,
68
68
  'signature' => @signature
69
69
  }, other_client)
70
-
70
+
71
71
  rp.verified?.should be_false
72
72
  end
73
73
  end
74
74
  end
75
- end
75
+ end
@@ -3,30 +3,30 @@ require 'spec_helper'
3
3
  module Chargify2
4
4
  describe Direct::SecureParameters do
5
5
  let(:client) { Client.new(valid_client_credentials) }
6
-
6
+
7
7
  it "raises an argument error if data is provided but it is not in hash format" do
8
8
  lambda {
9
9
  Direct::SecureParameters.new({'data' => 'string'}, client)
10
10
  }.should raise_error(ArgumentError)
11
11
  end
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
15
  Direct::SecureParameters.new({}, OpenCascade.new)
16
16
  }.should raise_error(ArgumentError)
17
17
  end
18
-
18
+
19
19
  describe "#timestamp?" do
20
20
  it "returns true when a timestamp is provided via a string hash key" do
21
21
  sp = Direct::SecureParameters.new({'timestamp' => '1234'}, client)
22
22
  sp.timestamp?.should be_true
23
23
  end
24
-
24
+
25
25
  it "returns true when a timestamp is provided via a symbol hash key" do
26
26
  sp = Direct::SecureParameters.new({:timestamp => '1234'}, client)
27
27
  sp.timestamp?.should be_true
28
28
  end
29
-
29
+
30
30
  it "returns false when a timestamp key/value is not provided" do
31
31
  sp = Direct::SecureParameters.new({}, client)
32
32
  sp.timestamp?.should be_false
@@ -48,12 +48,12 @@ module Chargify2
48
48
  sp = Direct::SecureParameters.new({'nonce' => '1234'}, client)
49
49
  sp.nonce?.should be_true
50
50
  end
51
-
51
+
52
52
  it "returns true when a nonce is provided via a symbol hash key" do
53
53
  sp = Direct::SecureParameters.new({:nonce => '1234'}, client)
54
54
  sp.nonce?.should be_true
55
55
  end
56
-
56
+
57
57
  it "returns false when a nonce key/value is not provided" do
58
58
  sp = Direct::SecureParameters.new({}, client)
59
59
  sp.nonce?.should be_false
@@ -75,12 +75,12 @@ module Chargify2
75
75
  sp = Direct::SecureParameters.new({'data' => {'foo' => 'bar'}}, client)
76
76
  sp.data?.should be_true
77
77
  end
78
-
78
+
79
79
  it "returns true when data is provided via a symbol hash key" do
80
80
  sp = Direct::SecureParameters.new({:data => {'foo' => 'bar'}}, client)
81
81
  sp.data?.should be_true
82
82
  end
83
-
83
+
84
84
  it "returns false when a data key/value is not provided" do
85
85
  sp = Direct::SecureParameters.new({}, client)
86
86
  sp.data?.should be_false
@@ -96,24 +96,24 @@ module Chargify2
96
96
  sp.data?.should be_false
97
97
  end
98
98
  end
99
-
99
+
100
100
  describe "#encoded_data" do
101
101
  it "turns the data hash in to query string format" do
102
102
  sp = Direct::SecureParameters.new({'data' => {'one' => 'two', 'three' => 'four'}}, client)
103
103
  sp.encoded_data.should == "one=two&three=four"
104
104
  end
105
-
105
+
106
106
  it "turns a nested data hash in to nested query string format" do
107
107
  sp = Direct::SecureParameters.new({'data' => {'one' => {'two' => {'three' => 'four'}}, 'foo' => 'bar'}}, client)
108
108
  sp.encoded_data.should == "foo=bar&one[two][three]=four"
109
109
  end
110
-
110
+
111
111
  it "performs percent encoding on unsafe characters" do
112
112
  sp = Direct::SecureParameters.new({'data' => {'redirect_uri' => 'http://www.example.com', 'sentence' => 'Michael was here!'}}, client)
113
113
  sp.encoded_data.should == "redirect_uri=http%3A%2F%2Fwww.example.com&sentence=Michael%20was%20here%21"
114
114
  end
115
115
  end
116
-
116
+
117
117
  describe "#to_form_inputs" do
118
118
  context "with no timestamp, nonce, nor data" do
119
119
  it "outputs 2 hidden form inputs - one for the api_id and one for the signature" do
@@ -125,7 +125,7 @@ module Chargify2
125
125
  form.should have_selector("input[type='hidden'][name='secure[signature]'][value='#{sp.signature}']", :count => 1)
126
126
  end
127
127
  end
128
-
128
+
129
129
  context "with a timestamp" do
130
130
  it "outputs 3 hidden form inputs - one each for the api_id, timestamp, and signature" do
131
131
  sp = Direct::SecureParameters.new({'timestamp' => '1234'}, client)
@@ -183,7 +183,7 @@ module Chargify2
183
183
  nonce = '5678'
184
184
  data = {'one' => 'two', 'three' => {'four' => "http://www.example.com"}}
185
185
  sp = Direct::SecureParameters.new({'timestamp' => timestamp, 'nonce' => nonce, 'data' => data}, client)
186
-
186
+
187
187
  # Used the generator here: http://hash.online-convert.com/sha1-generator
188
188
  # ... with message: "1c016050-498a-012e-91b1-005056a216ab12345678one=two&three[four]=http%3A%2F%2Fwww.example.com"
189
189
  # ... and secret: "p5lxQ804MYtwZecFWNOT"
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
13
  RSpec.configure do |config|
14
14
  config.include SpecHelperMethods
15
15
  config.extend VCR::RSpec::Macros
16
+ config.filter_run :focused => true
17
+ config.run_all_when_everything_filtered = true
18
+ config.alias_example_to :fit, :focused => true
19
+ config.alias_example_to :xit, :disabled => true
20
+ config.color_enabled = true
16
21
  end
17
22
 
18
23
  VCR.config do |c|
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Klett
9
+ - Shay Frendt
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2011-10-19 00:00:00.000000000 -04:00
13
+ date: 2011-10-28 00:00:00.000000000 -04:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: httparty
17
- requirement: &2153775320 !ruby/object:Gem::Requirement
18
+ requirement: &2153786560 !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ! '>='
@@ -22,10 +23,10 @@ dependencies:
22
23
  version: '0'
23
24
  type: :runtime
24
25
  prerelease: false
25
- version_requirements: *2153775320
26
+ version_requirements: *2153786560
26
27
  - !ruby/object:Gem::Dependency
27
28
  name: addressable
28
- requirement: &2153774820 !ruby/object:Gem::Requirement
29
+ requirement: &2153786080 !ruby/object:Gem::Requirement
29
30
  none: false
30
31
  requirements:
31
32
  - - ! '>='
@@ -33,10 +34,10 @@ dependencies:
33
34
  version: '0'
34
35
  type: :runtime
35
36
  prerelease: false
36
- version_requirements: *2153774820
37
+ version_requirements: *2153786080
37
38
  - !ruby/object:Gem::Dependency
38
39
  name: hashie
39
- requirement: &2153774320 !ruby/object:Gem::Requirement
40
+ requirement: &2153785600 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ! '>='
@@ -44,10 +45,10 @@ dependencies:
44
45
  version: '0'
45
46
  type: :runtime
46
47
  prerelease: false
47
- version_requirements: *2153774320
48
+ version_requirements: *2153785600
48
49
  - !ruby/object:Gem::Dependency
49
50
  name: hashery
50
- requirement: &2153773820 !ruby/object:Gem::Requirement
51
+ requirement: &2153785120 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
53
54
  - - ! '>='
@@ -55,10 +56,10 @@ dependencies:
55
56
  version: '0'
56
57
  type: :runtime
57
58
  prerelease: false
58
- version_requirements: *2153773820
59
+ version_requirements: *2153785120
59
60
  - !ruby/object:Gem::Dependency
60
61
  name: rspec
61
- requirement: &2153773320 !ruby/object:Gem::Requirement
62
+ requirement: &2153784640 !ruby/object:Gem::Requirement
62
63
  none: false
63
64
  requirements:
64
65
  - - ~>
@@ -66,10 +67,10 @@ dependencies:
66
67
  version: 2.3.0
67
68
  type: :development
68
69
  prerelease: false
69
- version_requirements: *2153773320
70
+ version_requirements: *2153784640
70
71
  - !ruby/object:Gem::Dependency
71
72
  name: yard
72
- requirement: &2153772780 !ruby/object:Gem::Requirement
73
+ requirement: &2153784160 !ruby/object:Gem::Requirement
73
74
  none: false
74
75
  requirements:
75
76
  - - ~>
@@ -77,10 +78,10 @@ dependencies:
77
78
  version: 0.6.0
78
79
  type: :development
79
80
  prerelease: false
80
- version_requirements: *2153772780
81
+ version_requirements: *2153784160
81
82
  - !ruby/object:Gem::Dependency
82
83
  name: bundler
83
- requirement: &2153772240 !ruby/object:Gem::Requirement
84
+ requirement: &2153783680 !ruby/object:Gem::Requirement
84
85
  none: false
85
86
  requirements:
86
87
  - - ~>
@@ -88,10 +89,10 @@ dependencies:
88
89
  version: 1.0.0
89
90
  type: :development
90
91
  prerelease: false
91
- version_requirements: *2153772240
92
+ version_requirements: *2153783680
92
93
  - !ruby/object:Gem::Dependency
93
94
  name: jeweler
94
- requirement: &2153771720 !ruby/object:Gem::Requirement
95
+ requirement: &2153799580 !ruby/object:Gem::Requirement
95
96
  none: false
96
97
  requirements:
97
98
  - - ~>
@@ -99,10 +100,10 @@ dependencies:
99
100
  version: 1.5.2
100
101
  type: :development
101
102
  prerelease: false
102
- version_requirements: *2153771720
103
+ version_requirements: *2153799580
103
104
  - !ruby/object:Gem::Dependency
104
105
  name: rcov
105
- requirement: &2153771200 !ruby/object:Gem::Requirement
106
+ requirement: &2153799100 !ruby/object:Gem::Requirement
106
107
  none: false
107
108
  requirements:
108
109
  - - ! '>='
@@ -110,10 +111,10 @@ dependencies:
110
111
  version: '0'
111
112
  type: :development
112
113
  prerelease: false
113
- version_requirements: *2153771200
114
+ version_requirements: *2153799100
114
115
  - !ruby/object:Gem::Dependency
115
116
  name: webmock
116
- requirement: &2153770660 !ruby/object:Gem::Requirement
117
+ requirement: &2153798620 !ruby/object:Gem::Requirement
117
118
  none: false
118
119
  requirements:
119
120
  - - ! '>='
@@ -121,10 +122,10 @@ dependencies:
121
122
  version: '0'
122
123
  type: :development
123
124
  prerelease: false
124
- version_requirements: *2153770660
125
+ version_requirements: *2153798620
125
126
  - !ruby/object:Gem::Dependency
126
127
  name: vcr
127
- requirement: &2153770140 !ruby/object:Gem::Requirement
128
+ requirement: &2153798140 !ruby/object:Gem::Requirement
128
129
  none: false
129
130
  requirements:
130
131
  - - ! '>='
@@ -132,10 +133,10 @@ dependencies:
132
133
  version: '0'
133
134
  type: :development
134
135
  prerelease: false
135
- version_requirements: *2153770140
136
+ version_requirements: *2153798140
136
137
  - !ruby/object:Gem::Dependency
137
138
  name: capybara
138
- requirement: &2153769600 !ruby/object:Gem::Requirement
139
+ requirement: &2153797660 !ruby/object:Gem::Requirement
139
140
  none: false
140
141
  requirements:
141
142
  - - ! '>='
@@ -143,7 +144,7 @@ dependencies:
143
144
  version: '0'
144
145
  type: :development
145
146
  prerelease: false
146
- version_requirements: *2153769600
147
+ version_requirements: *2153797660
147
148
  description: ''
148
149
  email: michael@webadvocate.com
149
150
  executables: []
@@ -190,9 +191,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
191
  - - ! '>='
191
192
  - !ruby/object:Gem::Version
192
193
  version: '0'
193
- segments:
194
- - 0
195
- hash: 1643346488157857297
196
194
  required_rubygems_version: !ruby/object:Gem::Requirement
197
195
  none: false
198
196
  requirements: