midwife-client 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ module Midwife
19
19
  private
20
20
 
21
21
  def request(path, attributes)
22
- uri = URI.join(@endpoint, 'api', path)
22
+ uri = join_uri(@endpoint, "api", path)
23
23
 
24
24
  request = Net::HTTP::Post.new(uri.path)
25
25
  request["content-type"] = "application/json"
@@ -43,6 +43,19 @@ module Midwife
43
43
  raise RequestError.new(response)
44
44
  end
45
45
  end
46
+
47
+ # Apparently joining URIs in ruby isn't as intuitive as one would
48
+ # think. This method helps makes things a little more sane for
49
+ # our use case.
50
+ def join_uri(base_uri, *paths)
51
+ base_uri = URI.parse(base_uri) unless base_uri.is_a?(URI)
52
+ base_path = base_uri.path
53
+ base_uri = base_uri.to_s
54
+ new_path = File.join(base_path, paths)
55
+
56
+ URI.join(base_uri, new_path)
57
+ end
58
+
46
59
  end
47
60
 
48
61
  class Client
@@ -1,5 +1,5 @@
1
1
  module Midwife
2
2
  class Client
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -12,8 +12,8 @@ describe Midwife::Client do
12
12
  describe '#unsubscribe' do
13
13
  context 'when the recipient exists' do
14
14
  before do
15
- stub_request(:post, "http://localhost:3000/unsubscribe").
16
- with(:body => "{\"list_id\":42,\"email\":\"exists@email.com\"}").
15
+ stub_request(:post, "http://localhost:3000/api/unsubscribe").
16
+ with(:body => { :list_id => 42, :email => 'exists@email.com' }).
17
17
  to_return(:body => file_fixture('unsubscribe/recipient_exists.json'))
18
18
  end
19
19
 
@@ -26,8 +26,8 @@ describe Midwife::Client do
26
26
 
27
27
  context 'when the recipient does not exist' do
28
28
  before do
29
- stub_request(:post, "http://localhost:3000/unsubscribe").
30
- with(:body => "{\"list_id\":42,\"email\":\"doesnotexist@email.com\"}").
29
+ stub_request(:post, "http://localhost:3000/api/unsubscribe").
30
+ with(:body => { :list_id => 42, :email => 'doesnotexist@email.com' }).
31
31
  to_return(:status => 404, :body => file_fixture('unsubscribe/recipient_does_not_exist.json'))
32
32
  end
33
33
 
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: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
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-06-13 00:00:00 -04:00
18
+ date: 2011-06-14 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency