midwife-client 0.0.2 → 0.0.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.
- data/lib/midwife/client/version.rb +1 -1
- data/lib/midwife/client.rb +13 -2
- data/spec/client_spec.rb +11 -1
- metadata +4 -4
data/lib/midwife/client.rb
CHANGED
@@ -16,7 +16,14 @@ module Midwife
|
|
16
16
|
|
17
17
|
def request(path, attributes)
|
18
18
|
uri = URI.parse(@endpoint + path)
|
19
|
-
|
19
|
+
|
20
|
+
request = Net::HTTP::Post.new(uri.path)
|
21
|
+
request["content-type"] = "application/json"
|
22
|
+
request.body = attributes.to_json
|
23
|
+
|
24
|
+
response = Net::HTTP.start(uri.host, uri.port) { |http|
|
25
|
+
http.request(request)
|
26
|
+
}
|
20
27
|
|
21
28
|
if response.code =~ /2../
|
22
29
|
JSON.parse(response.body)
|
@@ -30,7 +37,7 @@ module Midwife
|
|
30
37
|
|
31
38
|
include Request
|
32
39
|
|
33
|
-
def initialize(endpoint = 'http://localhost:3000')
|
40
|
+
def initialize(endpoint = 'http://localhost:3000/')
|
34
41
|
@endpoint = endpoint
|
35
42
|
end
|
36
43
|
|
@@ -62,5 +69,9 @@ module Midwife
|
|
62
69
|
request "/campaigns/#{campaign_id}/deliver", attributes
|
63
70
|
end
|
64
71
|
|
72
|
+
def unsubscribe(attributes)
|
73
|
+
request "/unsubscribe", attributes
|
74
|
+
end
|
75
|
+
|
65
76
|
end
|
66
77
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -110,6 +110,16 @@ describe Midwife::Client do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
|
+
|
114
|
+
describe '#unsubscribe' do
|
115
|
+
it 'unsubscribes the recipient' do
|
116
|
+
client.unsubscribe(:email => 'foo@bar.com', :list_id => 42)
|
117
|
+
|
118
|
+
last_request.path.should == "/unsubscribe"
|
119
|
+
last_request.method.should == :post
|
120
|
+
last_request.params.should == { :email => 'foo@bar.com', :list_id => 42 }
|
121
|
+
end
|
122
|
+
end
|
113
123
|
end
|
114
124
|
|
115
125
|
context 'when processing a non-success response' do
|
@@ -118,7 +128,7 @@ describe Midwife::Client do
|
|
118
128
|
|
119
129
|
|
120
130
|
before do
|
121
|
-
Net::HTTP.stub(:
|
131
|
+
Net::HTTP.stub(:start).and_return(response)
|
122
132
|
end
|
123
133
|
|
124
134
|
it 'raises an exception' do
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Guterl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-20 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|