frenchy 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df9f2034c5a6e3f43cbb2f187798d0213412c111
4
- data.tar.gz: 0c4efe7e2493f909924b44e0ecb3ba52f82746ac
3
+ metadata.gz: 16af458377a1de408890760f4ac784abaad0a414
4
+ data.tar.gz: 84de7abdc7e201642c2521b3ec7add47869572a6
5
5
  SHA512:
6
- metadata.gz: 09c1d18e40914e2b86c89aeea2075d5f901d049810e50a2b6bc89c5553841a0c3a4159825a7fc1e179243b4de4ea31c4ac748e4b3fec5c1e1612190be03fbf1b
7
- data.tar.gz: 34d4992484cb896ee4c345cd5b5cf3ae15d16d8eaa1cd8900f43f67645a47e1f2a3086d9743cde0ea4a10e16a06bd15b7c9d91e030b8a6615c77f478ee095bb0
6
+ metadata.gz: f347685ae4c325a22ff0a7b76b6c11dd51742549c9ad51d1d38dc6bf5a188af842d5b8919a0cb61c42239ca41a2a987462b6838f08922cd932c65cff53e30895
7
+ data.tar.gz: 350dde3459350edb714c2f579cd912f1dd835b97865908249ceb99bca97d2b2ff151f590b5b66c1836f59c80dff11fe8b7ca1a31fec740df5dfcefeb17df81d3
data/lib/frenchy.rb CHANGED
@@ -16,7 +16,7 @@ module Frenchy
16
16
  end
17
17
 
18
18
  def self.register_service(name, options={})
19
- @services[name.to_s] = Frenchy::Client.new(options)
19
+ @services[name.to_s] = Frenchy::Client.new(name, options)
20
20
  end
21
21
 
22
22
  def self.find_service(name)
@@ -3,16 +3,17 @@ require "json"
3
3
 
4
4
  module Frenchy
5
5
  class Client
6
- attr_accessor :host, :timeout, :retries
6
+ attr_accessor :name, :host, :timeout, :retries
7
7
 
8
8
  # Create a new client instance
9
- def initialize(options={})
9
+ def initialize(name, options={})
10
10
  options.stringify_keys!
11
11
 
12
- @host = options.delete("host") || "http://127.0.0.1:8080"
13
- @timeout = options.delete("timeout") || 30
14
- @retries = options.delete("retries") || 0
15
- @backoff_delay = options.delete("backoff_delay") || 1.0
12
+ @name = name.to_s
13
+ @host = options.fetch("host") { "http://127.0.0.1:8080" }
14
+ @timeout = options.fetch("timeout") { 30 }
15
+ @retries = options.fetch("retries") { 0 }
16
+ @backoff_delay = options.fetch("backoff_delay") { 1.0 }
16
17
  end
17
18
 
18
19
  # Issue a get request with the given path and query parameters. Get
@@ -90,7 +91,7 @@ module Frenchy
90
91
 
91
92
  # Perform the request
92
93
  begin
93
- resp = http.request(req)
94
+ resp = perform_request(http, req)
94
95
  rescue => ex
95
96
  raise Frenchy::ServerError.new(ex, reqinfo, nil)
96
97
  end
@@ -112,5 +113,9 @@ module Frenchy
112
113
  raise Frenchy::ServiceUnavailable.new(nil, reqinfo, resp)
113
114
  end
114
115
  end
116
+
117
+ def perform_request(http, req)
118
+ http.request(req)
119
+ end
115
120
  end
116
121
  end
@@ -1,3 +1,3 @@
1
1
  module Frenchy
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -3,21 +3,21 @@ require "spec_helper"
3
3
  describe Frenchy::Client do
4
4
  describe "#initialize" do
5
5
  it "uses expected defaults" do
6
- client = Frenchy::Client.new
6
+ client = Frenchy::Client.new("default")
7
7
  expect(client.host).to eql("http://127.0.0.1:8080")
8
8
  expect(client.timeout).to eql(30)
9
9
  expect(client.retries).to eql(0)
10
10
  end
11
11
 
12
12
  it "accepts an options hash" do
13
- client = Frenchy::Client.new({"host" => "http://127.0.0.1:1234", "timeout" => 15, "retries" => 3})
13
+ client = Frenchy::Client.new("default", {"host" => "http://127.0.0.1:1234", "timeout" => 15, "retries" => 3})
14
14
  expect(client.host).to eql("http://127.0.0.1:1234")
15
15
  expect(client.timeout).to eql(15)
16
16
  expect(client.retries).to eql(3)
17
17
  end
18
18
 
19
19
  it "accepts an options hash (symbols)" do
20
- client = Frenchy::Client.new(host: "http://127.0.0.1:1234", timeout: 15, retries: 3)
20
+ client = Frenchy::Client.new("default", host: "http://127.0.0.1:1234", timeout: 15, retries: 3)
21
21
  expect(client.host).to eql("http://127.0.0.1:1234")
22
22
  expect(client.timeout).to eql(15)
23
23
  expect(client.retries).to eql(3)
@@ -27,7 +27,7 @@ describe Frenchy::Client do
27
27
  ["patch", "post", "put", "delete"].each do |method|
28
28
  describe "##{method}" do
29
29
  it "returns a successful response containing the request json data" do
30
- client = Frenchy::Client.new("host" => "http://httpbin.org")
30
+ client = Frenchy::Client.new("httpbin", "host" => "http://httpbin.org")
31
31
  data = {"data" => "abcd", "number" => 1, "nested" => {"more" => "data"}}
32
32
  expect = JSON.generate(data)
33
33
  result = client.send(method, "/#{method}", data)
@@ -39,24 +39,24 @@ describe Frenchy::Client do
39
39
 
40
40
  describe "#perform" do
41
41
  it "returns a hash for successful json response" do
42
- client = Frenchy::Client.new("host" => "http://httpbin.org")
42
+ client = Frenchy::Client.new("httpbin", "host" => "http://httpbin.org")
43
43
  result = client.get("/ip", {})
44
44
  expect(result).to be_an_instance_of(Hash)
45
45
  expect(result.keys).to eql(["origin"])
46
46
  end
47
47
 
48
48
  it "raises an invalid response error for non-json response" do
49
- client = Frenchy::Client.new("host" => "http://httpbin.org")
49
+ client = Frenchy::Client.new("httpbin", "host" => "http://httpbin.org")
50
50
  expect{client.get("/html", {})}.to raise_error(Frenchy::InvalidResponse)
51
51
  end
52
52
 
53
53
  it "raises a not found error for 404 responses" do
54
- client = Frenchy::Client.new("host" => "http://httpbin.org")
54
+ client = Frenchy::Client.new("httpbin", "host" => "http://httpbin.org")
55
55
  expect{client.get("/status/404", {})}.to raise_error(Frenchy::NotFound)
56
56
  end
57
57
 
58
58
  it "raises a service unavailable error for 500+ responses" do
59
- client = Frenchy::Client.new("host" => "http://httpbin.org")
59
+ client = Frenchy::Client.new("httpbin", "host" => "http://httpbin.org")
60
60
  expect{client.get("/status/500", {})}.to raise_error(Frenchy::ServiceUnavailable)
61
61
  end
62
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frenchy
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
  - Jason Coene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json