streamsend 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 570a759259227d544ce683da82e01e9de3fcf02f
4
- data.tar.gz: 3fab2452d29f3e1cb9246958482860a5610d9cf7
3
+ metadata.gz: 5e41691af38b21804f3ae360a1ba2dec326e7090
4
+ data.tar.gz: 2f7a0ac3bd573ac8b6ff95e36c746dcc01b23aef
5
5
  SHA512:
6
- metadata.gz: 731dd7a05dc12b5cf17b923b3dba981703ff96838cf94abe44d7306270a89d5aa270e65e2ea2d5655f89f063c93951445e433e568494a8fc36555173cae46f2f
7
- data.tar.gz: ff1ece90306b86ff2ebe904309f0782a4c0f0ea81fef98fbeb9bd8397a51eeaf3a84d0df40b76cc80c6cb495c918c7d26569d504a6d27a27659489cd3518770d
6
+ metadata.gz: 365a2fb216e108448b924e9c16578bcc266f0c4894132fd4deda97a82718fe996bf8e2e8338cd4b4c62bce3de31d578e1f0d5788220921722fb7fe6bb8405b49
7
+ data.tar.gz: d665fd2f40151ec996cacb85af23daaaba5689d98b7b615e02c80169c91df3ce380a01821d8809f3e2cb463e33f835f38c406f1f3680a9987fe5f6de3d299631
@@ -6,6 +6,20 @@ module StreamSend
6
6
  class ApiException < Exception
7
7
  end
8
8
 
9
+ class SemanticException < ApiException
10
+ def initialize(other_errors)
11
+ @errors = [other_errors].flatten
12
+ end
13
+
14
+ def errors
15
+ @errors
16
+ end
17
+
18
+ def to_s
19
+ "#{self.class.name}: #{errors.join(',')}"
20
+ end
21
+ end
22
+
9
23
  class LockedError < ApiException
10
24
  end
11
25
 
@@ -53,6 +53,8 @@ module StreamSend
53
53
  unless subscriber_id.nil?
54
54
  subscriber_id.to_i
55
55
  end
56
+ when 422
57
+ raise StreamSend::Api::SemanticException.new(response["errors"]["error"])
56
58
  else
57
59
  raise StreamSend::Api::Exception.new("Could not create the subscriber. (#{response.code})")
58
60
  end
@@ -175,30 +175,64 @@ module StreamSend
175
175
  end
176
176
  end
177
177
 
178
- describe "with an existing subscriber using the given email address" do
178
+ describe "when receiving a semantic error" do
179
+ describe "with a single error" do
180
+ let( :error1 ){ "Email address has already been taken" }
181
+
182
+ before(:each) do
183
+ response_body = <<-XML
184
+ <errors>
185
+ <error>#{error1}</error>
186
+ </errors>
187
+ XML
188
+ stub_http_request(:post, /audiences\/2\/people.xml/).with(:person => {"email_address" => "foo@bar.com", "first_name" => "JoeBob"}).to_return(:status => 422, :body => response_body )
189
+ end
190
+
191
+ it "should raise an exception" do
192
+ expect do
193
+ subscriber_id = StreamSend::Api::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
194
+ end.to raise_error( StreamSend::Api::SemanticException )
195
+ end
196
+
197
+ it "should pass on the errors" do
198
+ captured_problem = nil
199
+ begin
200
+ subscriber_id = StreamSend::Api::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
201
+ rescue StreamSend::Api::SemanticException => problem
202
+ captured_problem = problem
203
+ end
204
+ expect(captured_problem.errors.count).to be(1)
205
+ expect(captured_problem.errors).to include(error1)
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "with multiple errors" do
211
+ let( :error1 ){ "bonjour" }
212
+ let( :error2 ){ "some other string you are unlikely to copy and paste" }
213
+
179
214
  before(:each) do
180
- stub_http_request(:post, /audiences\/2\/people.xml/).with(:person => {"email_address" => "foo@bar.com", "first_name" => "JoeBob"}).to_return(:body => "<error>Email address has already been taken<error>")
215
+ response_body = <<-XML
216
+ <errors>
217
+ <error>#{error1}</error>
218
+ <error>#{error2}</error>
219
+ </errors>
220
+ XML
221
+ stub_http_request(:post, /audiences\/2\/people.xml/).with(:person => {"email_address" => "foo@bar.com", "first_name" => "JoeBob"}).to_return(:status => 422, :body => response_body )
181
222
  end
182
223
 
183
- it "should raise an exception" do
184
- lambda {
224
+ it "should pass on the errors" do
225
+ captured_problem = nil
226
+ begin
185
227
  subscriber_id = StreamSend::Api::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
186
- }.should raise_error
228
+ rescue StreamSend::Api::SemanticException => problem
229
+ captured_problem = problem
230
+ end
231
+ expect(captured_problem.errors.count).to eq( 2 )
232
+ expect(captured_problem.errors).to include(error1, error2)
187
233
  end
188
234
  end
189
235
  end
190
-
191
- describe "with invalid subscriber parameters" do
192
- before(:each) do
193
- stub_http_request(:post, /audiences\/2\/people.xml/).with({"email_address" => "foo.com", "first_name" => "JoeBob"}).to_return(:body => "<error>Email address does not appear to be valid</error>")
194
- end
195
-
196
- it "should raise an exception" do
197
- lambda {
198
- subscriber_id = StreamSend::Api::Subscriber.create({"email_address" => "foo@bar.com", "first_name" => "JoeBob"})
199
- }.should raise_error
200
- end
201
- end
202
236
  end
203
237
 
204
238
  describe "#show" do
@@ -281,7 +315,7 @@ module StreamSend
281
315
  end
282
316
  end
283
317
 
284
- describe "#destory" do
318
+ describe "#destroy" do
285
319
  let( :subscriber ){
286
320
  StreamSend::Api::Subscriber.new({"id"=> 2, "audience_id" => 1})
287
321
  }
@@ -24,5 +24,5 @@ Gem::Specification.new do |gem|
24
24
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
25
  gem.name = "streamsend"
26
26
  gem.require_paths = ["lib"]
27
- gem.version = "0.2.2"
27
+ gem.version = "0.2.3"
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamsend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Albertson