responsys-api 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c58dabbbc30ada0598409ef51e03261727c7e9f
4
- data.tar.gz: 99998f69378d08f201ef7f2237f5ba539ba7f835
3
+ metadata.gz: 84547cf31f537da62287c2dcb67e45d3ca767323
4
+ data.tar.gz: 465b7023b7b30abf01d29392b76699d2666927d2
5
5
  SHA512:
6
- metadata.gz: ed4209c6e94719176a85d2a509473a324a73663ccc2ab98b947802a98c38bcbd990da8eafcca56a7efeae46a4cb6e7325171f43ee16212f64827d31528088f8b
7
- data.tar.gz: 6f1c45aede0988f1d8bbe4961eb70dedbc3d062f7be0d8bff92177fc07b862f155de88a3a5b4be2672711162e497c173c3cd34a9e39667f16792bfd7331362b2
6
+ metadata.gz: 063b69c6e94269e0bd9b91cc2c3898ad8d5f94b531424b893c0a3f5adbbb953c5ee016b01379acecdb61bc1c9ad71875177eb2d4d6f5dbddb834870e238cecf2
7
+ data.tar.gz: d21ec3c1160d93e4197eb1867bd7ad54ab52f8ab999acace83c1bf236b2f869c65b7e9c74b3fc5416b959aefe50e943c5cd66526e093093029301a5c3886633a
@@ -64,13 +64,13 @@ module Responsys
64
64
 
65
65
  def self.format_response_with_errors(error)
66
66
  error_response = { status: "failure" }
67
-
68
- if error.to_hash[:fault].has_key?(:detail) and !error.to_hash[:fault][:detail].nil?
69
- key = error.to_hash[:fault][:detail].keys[0]
70
- error_response[:error] = { http_status_code: error.http.code, code: error.to_hash[:fault][:detail][key][:exception_code], message: error.to_hash[:fault][:detail][key][:exception_message] }
71
- error_response[:error][:trace] = error.to_hash[:fault][:detail][:source] if error.to_hash[:fault][:detail].has_key?(:source)
72
- else
73
- error_response[:error] = { http_status_code: error.http.code, code: error.to_hash[:fault][:faultcode], message: error.to_hash[:fault][:faultstring] }
67
+ case error
68
+ when Savon::SOAPFault
69
+ error_response.merge!(format_soap_fault(error))
70
+ when Savon::HTTPError
71
+ error_response.merge!(format_http_error(error))
72
+ else
73
+ raise error
74
74
  end
75
75
 
76
76
  error_response
@@ -87,5 +87,30 @@ module Responsys
87
87
  I18n.t(key, scope: :responsys_api, locale: :en, default: "Responsys - Unknown message '#{key}'")
88
88
  end
89
89
  end
90
+
91
+ class << self
92
+ private
93
+ def format_soap_fault(error)
94
+ error_response = {}
95
+ if error.to_hash[:fault].has_key?(:detail) and !error.to_hash[:fault][:detail].nil?
96
+ key = error.to_hash[:fault][:detail].keys[0]
97
+ error_response[:error] = { http_status_code: error.http.code, code: error.to_hash[:fault][:detail][key][:exception_code], message: error.to_hash[:fault][:detail][key][:exception_message] }
98
+ error_response[:error][:trace] = error.to_hash[:fault][:detail][:source] if error.to_hash[:fault][:detail][:source]
99
+ else
100
+ error_response[:error] = { http_status_code: error.http.code, code: error.to_hash[:fault][:faultcode], message: error.to_hash[:fault][:faultstring] }
101
+ end
102
+ error_response
103
+ end
104
+
105
+ def format_http_error(error)
106
+ {
107
+ error: {
108
+ http_status_code: error.to_hash[:code],
109
+ message: error.to_hash[:body],
110
+ }
111
+ }
112
+ end
113
+ end
114
+
90
115
  end
91
116
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "responsys-api"
7
- spec.version = "0.2.6"
7
+ spec.version = "0.2.7"
8
8
  spec.authors = ["Dan DeMeyere", "Florian Lorrain", "Morgan Griggs", "Mike Rocco"]
9
9
  spec.email = ["dan@thredup.com", "florian.lorrain@thredup.com", "morgan@thredup.com", "michael.rocco@thredup.com"]
10
10
  spec.description = "A gem to integrate with the Responsys SOAP API"
@@ -0,0 +1,8 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2
+ <soap:Body>
3
+ <soap:Fault>
4
+ <faultcode>soap:Server</faultcode>
5
+ <faultstring>Fault occurred while processing.</faultstring>
6
+ </soap:Fault>
7
+ </soap:Body>
8
+ </soap:Envelope>
@@ -35,6 +35,40 @@ describe Responsys::Helper do
35
35
  expect(Responsys::Helper.get_message(message_key))
36
36
  .to eq("Responsys - Unknown message 'member.record_not_found'")
37
37
  end
38
+ end
39
+
40
+ describe '#format_response_with_error' do
41
+ let(:nori) { Nori.new(:strip_namespaces => true, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }) }
42
+
43
+ it 'will format a Savon::SOAPFault response' do
44
+ fault_body = File.read File.expand_path "../fixtures/soap_fault.xml", __FILE__
45
+ http_response = HTTPI::Response.new 500, {}, fault_body
46
+ soap_fault = Savon::SOAPFault.new http_response, nori
47
+
48
+ result = Responsys::Helper.format_response_with_errors(soap_fault)
49
+ expect(result[:status]).to eq "failure"
50
+ expect(result[:error][:http_status_code]).to eq 500
51
+ expect(result[:error][:code]).to eq "soap:Server"
52
+ expect(result[:error][:message]).to eq "Fault occurred while processing."
53
+ end
54
+
55
+ it 'will format a Savon::HTTPError' do
56
+ http_response = HTTPI::Response.new 503, {}, "Service unavailable"
57
+ http_error = Savon::HTTPError.new(http_response)
58
+ result = Responsys::Helper.format_response_with_errors(http_error)
59
+
60
+ expect(result[:status]).to eq "failure"
61
+ expect(result[:error][:http_status_code]).to eq 503
62
+ expect(result[:error][:message]).to eq "Service unavailable"
63
+ end
64
+
65
+ it 'will re-raise a unformattable Savon error' do
66
+ unformattable_error = Savon::InvalidResponseError.new
67
+ expect{
68
+ Responsys::Helper.format_response_with_errors(unformattable_error)
69
+ }.to raise_error(Savon::InvalidResponseError)
70
+ end
38
71
 
39
72
  end
73
+
40
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responsys-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan DeMeyere
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-19 00:00:00.000000000 Z
14
+ date: 2016-09-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rubyntlm
@@ -274,6 +274,7 @@ files:
274
274
  - spec/api/table_spec.rb
275
275
  - spec/api_credentials.sample.yml
276
276
  - spec/configuration_spec.rb
277
+ - spec/fixtures/soap_fault.xml
277
278
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_custom_event_1.yml
278
279
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_custom_event_2.yml
279
280
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_message_1.yml
@@ -339,6 +340,7 @@ test_files:
339
340
  - spec/api/table_spec.rb
340
341
  - spec/api_credentials.sample.yml
341
342
  - spec/configuration_spec.rb
343
+ - spec/fixtures/soap_fault.xml
342
344
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_custom_event_1.yml
343
345
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_custom_event_2.yml
344
346
  - spec/fixtures/vcr_cassettes/api/campaign/trigger_message_1.yml