midwife-client 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/midwife/client/version.rb +1 -1
- data/lib/midwife/client.rb +7 -2
- data/midwife-client.gemspec +1 -0
- data/spec/client_spec.rb +3 -1
- data/spec/fixtures/unsubscribe/recipient_does_not_exist.json +1 -0
- data/spec/fixtures/unsubscribe/recipient_exists.json +1 -0
- data/spec/integration_spec.rb +42 -0
- data/{spec_helper.rb → spec/spec_helper.rb} +0 -0
- metadata +27 -4
data/lib/midwife/client.rb
CHANGED
@@ -13,11 +13,13 @@ module Midwife
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
class NotFoundError < RequestError; end
|
17
|
+
|
16
18
|
module Request
|
17
19
|
private
|
18
20
|
|
19
21
|
def request(path, attributes)
|
20
|
-
uri = URI.
|
22
|
+
uri = URI.join(@endpoint, path)
|
21
23
|
|
22
24
|
request = Net::HTTP::Post.new(uri.path)
|
23
25
|
request["content-type"] = "application/json"
|
@@ -32,8 +34,11 @@ module Midwife
|
|
32
34
|
|
33
35
|
response = http.request(request)
|
34
36
|
|
35
|
-
|
37
|
+
case response.code
|
38
|
+
when /2../
|
36
39
|
JSON.parse(response.body)
|
40
|
+
when /404/
|
41
|
+
raise NotFoundError.new(response)
|
37
42
|
else
|
38
43
|
raise RequestError.new(response)
|
39
44
|
end
|
data/midwife-client.gemspec
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -141,11 +141,13 @@ describe Midwife::Client do
|
|
141
141
|
|
142
142
|
context 'when processing a non-success response' do
|
143
143
|
let(:client) { Midwife::Client.new }
|
144
|
+
let(:http) { double.as_null_object }
|
144
145
|
let(:response) { double(:code => '404', :body => 'error') }
|
145
146
|
|
146
147
|
|
147
148
|
before do
|
148
|
-
|
149
|
+
http.stub(:request).and_return(response)
|
150
|
+
Net::HTTP.stub(:new).and_return(http)
|
149
151
|
end
|
150
152
|
|
151
153
|
it 'raises an exception' do
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":false}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":true}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
describe Midwife::Client do
|
5
|
+
|
6
|
+
let(:client) { Midwife::Client.new }
|
7
|
+
|
8
|
+
def file_fixture(path)
|
9
|
+
File.read(File.join('spec/fixtures', path))
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#unsubscribe' do
|
13
|
+
context 'when the recipient exists' do
|
14
|
+
before do
|
15
|
+
stub_request(:post, "http://localhost:3000/unsubscribe").
|
16
|
+
with(:body => "{\"list_id\":42,\"email\":\"exists@email.com\"}").
|
17
|
+
to_return(:body => file_fixture('unsubscribe/recipient_exists.json'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the JSON from the response' do
|
21
|
+
response = client.unsubscribe(:list_id => 42, :email => 'exists@email.com')
|
22
|
+
|
23
|
+
response.should == { 'status' => true }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when the recipient does not exist' do
|
28
|
+
before do
|
29
|
+
stub_request(:post, "http://localhost:3000/unsubscribe").
|
30
|
+
with(:body => "{\"list_id\":42,\"email\":\"doesnotexist@email.com\"}").
|
31
|
+
to_return(:status => 404, :body => file_fixture('unsubscribe/recipient_does_not_exist.json'))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'raises a RecipientNotFound exception' do
|
35
|
+
expect {
|
36
|
+
client.unsubscribe(:list_id => 42, :email => 'doesnotexist@email.com')
|
37
|
+
}.to raise_error(Midwife::NotFoundError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwife-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Guterl
|
@@ -47,6 +47,22 @@ dependencies:
|
|
47
47
|
version: "2.5"
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: webmock
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 7
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 6
|
62
|
+
- 4
|
63
|
+
version: 1.6.4
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
50
66
|
description: A ruby wrapper for the Midwife HTTP API
|
51
67
|
email:
|
52
68
|
- mguterl@gmail.com
|
@@ -66,7 +82,10 @@ files:
|
|
66
82
|
- lib/midwife/client/version.rb
|
67
83
|
- midwife-client.gemspec
|
68
84
|
- spec/client_spec.rb
|
69
|
-
-
|
85
|
+
- spec/fixtures/unsubscribe/recipient_does_not_exist.json
|
86
|
+
- spec/fixtures/unsubscribe/recipient_exists.json
|
87
|
+
- spec/integration_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
70
89
|
has_rdoc: true
|
71
90
|
homepage: ""
|
72
91
|
licenses: []
|
@@ -103,3 +122,7 @@ specification_version: 3
|
|
103
122
|
summary: A ruby wrapper for the Midwife HTTP API
|
104
123
|
test_files:
|
105
124
|
- spec/client_spec.rb
|
125
|
+
- spec/fixtures/unsubscribe/recipient_does_not_exist.json
|
126
|
+
- spec/fixtures/unsubscribe/recipient_exists.json
|
127
|
+
- spec/integration_spec.rb
|
128
|
+
- spec/spec_helper.rb
|