spreedly 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.4
4
+ * Add ability to retrieve a transcript [hoenth]
5
+
3
6
  ## 2.0.3
4
7
  * Readme improvements
5
8
  * Smarter about timeouts - now only have long timeout for calls
data/README.md CHANGED
@@ -227,7 +227,7 @@ transaction.order_id # => '30-9904-31114'
227
227
  #### Retrieving the transcript for a transaction
228
228
 
229
229
  ``` ruby
230
- env.find_transaction_transcript(transaction_token)
230
+ env.find_transcript(transaction_token)
231
231
  ```
232
232
 
233
233
  #### Updating a credit card
@@ -29,6 +29,10 @@ module Spreedly
29
29
  Transaction.new_from(xml_doc)
30
30
  end
31
31
 
32
+ def find_transcript(transaction_token)
33
+ ssl_raw_get(find_transcript_url(transaction_token), headers)
34
+ end
35
+
32
36
  def find_gateway(token)
33
37
  xml_doc = ssl_get(find_gateway_url(token), headers)
34
38
  Gateway.new(xml_doc)
@@ -2,31 +2,37 @@ module Spreedly
2
2
 
3
3
  module SslRequester
4
4
 
5
- def ssl_get(endpoint, headers, talking_to_gateway = false)
6
- ssl_request(:get, endpoint, nil, headers, talking_to_gateway)
5
+ def ssl_get(endpoint, headers)
6
+ ssl_request(:get, endpoint, nil, headers)
7
7
  end
8
8
 
9
9
  def ssl_post(endpoint, body, headers, talking_to_gateway = false)
10
- ssl_request(:post, endpoint, body, headers, talking_to_gateway)
10
+ ssl_request(:post, endpoint, body, headers, talking_to_gateway: talking_to_gateway)
11
11
  end
12
12
 
13
- def ssl_put(endpoint, body, headers, talking_to_gateway = false)
14
- ssl_request(:put, endpoint, body, headers, talking_to_gateway)
13
+ def ssl_raw_get(endpoint, headers)
14
+ ssl_request(:get, endpoint, nil, headers, return_raw: true)
15
15
  end
16
16
 
17
- def ssl_options(endpoint, talking_to_gateway = false)
18
- ssl_request(:options, endpoint, nil, {}, talking_to_gateway)
17
+ def ssl_put(endpoint, body, headers)
18
+ ssl_request(:put, endpoint, body, headers)
19
+ end
20
+
21
+ def ssl_options(endpoint)
22
+ ssl_request(:options, endpoint, nil, {})
19
23
  end
20
24
 
21
25
  private
22
- def ssl_request(method, endpoint, body, headers, talking_to_gateway)
23
- how_long = talking_to_gateway ? 66 : 10
26
+ def ssl_request(method, endpoint, body, headers, options = {})
27
+ opts = { talking_to_gateway: false, return_raw: false }.merge(options)
28
+ how_long = opts[:talking_to_gateway] ? 66 : 10
29
+
24
30
  raw_response = Timeout::timeout(how_long) do
25
31
  raw_ssl_request(method, endpoint, body, headers)
26
32
  end
27
33
 
28
34
  show_raw_response(raw_response)
29
- handle_response(raw_response)
35
+ handle_response(raw_response, opts[:return_raw])
30
36
 
31
37
  rescue Timeout::Error => e
32
38
  raise Spreedly::TimeoutError.new
@@ -37,29 +43,31 @@ module Spreedly
37
43
  connection.request(method, body, headers)
38
44
  end
39
45
 
40
- def handle_response(response)
41
- xml_doc = Nokogiri::XML(response.body)
42
-
46
+ def handle_response(response, return_raw)
43
47
  case response.code.to_i
44
48
  when 200...300
45
- xml_doc
49
+ return_raw ? response.body : xml_doc(response)
46
50
  when 401
47
- raise AuthenticationError.new(xml_doc)
51
+ raise AuthenticationError.new(xml_doc(response))
48
52
  when 404
49
- raise NotFoundError.new(xml_doc)
53
+ raise NotFoundError.new(xml_doc(response))
50
54
  when 402
51
- raise PaymentRequiredError.new(xml_doc)
55
+ raise PaymentRequiredError.new(xml_doc(response))
52
56
  when 422
53
- if xml_doc.at_xpath('.//errors/error')
54
- raise TransactionCreationError.new(xml_doc)
57
+ if xml_doc(response).at_xpath('.//errors/error')
58
+ raise TransactionCreationError.new(xml_doc(response))
55
59
  else
56
- xml_doc
60
+ xml_doc(response)
57
61
  end
58
62
  else
59
63
  raise UnexpectedResponseError.new(response)
60
64
  end
61
65
  end
62
66
 
67
+ def xml_doc(response)
68
+ Nokogiri::XML(response.body)
69
+ end
70
+
63
71
  def show_raw_response(raw_response)
64
72
  return unless ENV['SHOW_RAW_RESPONSE'] == 'true'
65
73
  puts raw_response.inspect
data/lib/spreedly/urls.rb CHANGED
@@ -10,6 +10,10 @@ module Spreedly
10
10
  "#{base_url}/v1/transactions/#{token}.xml"
11
11
  end
12
12
 
13
+ def find_transcript_url(transaction_token)
14
+ "#{base_url}/v1/transactions/#{transaction_token}/transcript"
15
+ end
16
+
13
17
  def find_gateway_url(token)
14
18
  "#{base_url}/v1/gateways/#{token}.xml"
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Spreedly
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteFindTranscriptTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
7
+ end
8
+
9
+ def test_invalid_login
10
+ assert_invalid_login do |environment|
11
+ environment.find_transcript("SomeToken")
12
+ end
13
+ end
14
+
15
+ def test_transaction_not_found
16
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the transaction SomeUnknownToken.") do
17
+ @environment.find_transcript("SomeUnknownToken")
18
+ end
19
+ end
20
+
21
+ def test_successfully_find_transcript
22
+ gateway_token = @environment.add_gateway(:test).token
23
+ card_token = create_failed_card_on(@environment).token
24
+ transaction = @environment.purchase_on_gateway(gateway_token, card_token, 144)
25
+
26
+ found = @environment.find_transcript(transaction.token)
27
+ assert_kind_of(String, found)
28
+ end
29
+
30
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class FindTransactionTranscriptTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @environment = Spreedly::Environment.new("key", "secret")
7
+ end
8
+
9
+ def test_successful_find_transcript
10
+ t = find_using("Some Non XML String. Could be anything really.")
11
+ assert_equal "Some Non XML String. Could be anything really.", t
12
+ end
13
+
14
+ private
15
+ def find_using(response)
16
+ @environment.stubs(:raw_ssl_request).returns(StubResponse.succeeded(response))
17
+ @environment.find_transcript("IgnoredTokenSinceResponseIsStubbed")
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: spreedly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.3
5
+ version: 2.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Spreedly
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-20 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -165,6 +165,7 @@ files:
165
165
  - test/remote/remote_find_gateway_test.rb
166
166
  - test/remote/remote_find_payment_method_test.rb
167
167
  - test/remote/remote_find_transaction_test.rb
168
+ - test/remote/remote_find_transcript_test.rb
168
169
  - test/remote/remote_gateway_options_test.rb
169
170
  - test/remote/remote_list_gateways_test.rb
170
171
  - test/remote/remote_list_payment_methods_test.rb
@@ -186,6 +187,7 @@ files:
186
187
  - test/unit/find_gateway_test.rb
187
188
  - test/unit/find_payment_method_test.rb
188
189
  - test/unit/find_transaction_test.rb
190
+ - test/unit/find_transcript_test.rb
189
191
  - test/unit/gateway_options_test.rb
190
192
  - test/unit/list_gateways_test.rb
191
193
  - test/unit/list_payment_methods_test.rb
@@ -229,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
231
  - !ruby/object:Gem::Version
230
232
  segments:
231
233
  - 0
232
- hash: -2109504524353041148
234
+ hash: 4235559723397187348
233
235
  version: '0'
234
236
  none: false
235
237
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -238,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
240
  - !ruby/object:Gem::Version
239
241
  segments:
240
242
  - 0
241
- hash: -2109504524353041148
243
+ hash: 4235559723397187348
242
244
  version: '0'
243
245
  none: false
244
246
  requirements: []
@@ -261,6 +263,7 @@ test_files:
261
263
  - test/remote/remote_find_gateway_test.rb
262
264
  - test/remote/remote_find_payment_method_test.rb
263
265
  - test/remote/remote_find_transaction_test.rb
266
+ - test/remote/remote_find_transcript_test.rb
264
267
  - test/remote/remote_gateway_options_test.rb
265
268
  - test/remote/remote_list_gateways_test.rb
266
269
  - test/remote/remote_list_payment_methods_test.rb
@@ -282,6 +285,7 @@ test_files:
282
285
  - test/unit/find_gateway_test.rb
283
286
  - test/unit/find_payment_method_test.rb
284
287
  - test/unit/find_transaction_test.rb
288
+ - test/unit/find_transcript_test.rb
285
289
  - test/unit/gateway_options_test.rb
286
290
  - test/unit/list_gateways_test.rb
287
291
  - test/unit/list_payment_methods_test.rb