streamsend 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/streamsend/api/exception.rb +14 -0
- data/lib/streamsend/api/subscriber.rb +2 -0
- data/spec/lib/streamsend/api/subscriber_spec.rb +52 -18
- data/streamsend.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e41691af38b21804f3ae360a1ba2dec326e7090
|
4
|
+
data.tar.gz: 2f7a0ac3bd573ac8b6ff95e36c746dcc01b23aef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 "
|
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
|
-
|
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
|
184
|
-
|
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
|
-
|
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 "#
|
318
|
+
describe "#destroy" do
|
285
319
|
let( :subscriber ){
|
286
320
|
StreamSend::Api::Subscriber.new({"id"=> 2, "audience_id" => 1})
|
287
321
|
}
|
data/streamsend.gemspec
CHANGED