frenchy 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/frenchy/client.rb +13 -8
- data/lib/frenchy/request.rb +4 -3
- data/lib/frenchy/resource.rb +2 -1
- data/lib/frenchy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad1db4590ae68aec65ae8a7ed857d142897c49c9
|
4
|
+
data.tar.gz: 989a36bdc75e33f16ed6c73ad1cc37382e336523
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf9d3d87f2bc87909b173223400525cda80eb502a3b5db753eb87f5429e30ad1f92856e39770dfd96ab970a7985c3095761aa067b43660d6500ffef0aa7fa6a7
|
7
|
+
data.tar.gz: aae4fbe9d4964a19f9e8ea65178f8ae7cab4ec13c759947a58ffa8dc280557f3bc2e7e28330c37f4cf5cd9bfbd261c7a21ec6eba4b905b9e0c630c96782720cd
|
data/lib/frenchy/client.rb
CHANGED
@@ -9,18 +9,18 @@ module Frenchy
|
|
9
9
|
options.symbolize_keys!
|
10
10
|
|
11
11
|
@host = options.delete(:host) || "http://127.0.0.1:8080"
|
12
|
-
@timeout = options.delete(:timeout) ||
|
13
|
-
@retries = options.delete(:
|
12
|
+
@timeout = options.delete(:timeout) || 60
|
13
|
+
@retries = options.delete(:retries) || 0
|
14
14
|
end
|
15
15
|
|
16
|
-
# Issue a request with the given path and query parameters
|
16
|
+
# Issue a get request with the given path and query parameters
|
17
17
|
def get(path, params)
|
18
|
-
try =
|
18
|
+
try = 0
|
19
19
|
error = nil
|
20
20
|
|
21
|
-
while try
|
21
|
+
while try <= @retries
|
22
22
|
begin
|
23
|
-
return
|
23
|
+
return perform(:get, path, params)
|
24
24
|
rescue Frenchy::ServerError, Frenchy::InvalidResponse => error
|
25
25
|
sleep (0.35 * (try*try))
|
26
26
|
try += 1
|
@@ -30,13 +30,18 @@ module Frenchy
|
|
30
30
|
raise error
|
31
31
|
end
|
32
32
|
|
33
|
+
# Issue a non-retryable request with the given path and query parameters
|
34
|
+
def post(path, params); perform(:post, path, params); end
|
35
|
+
def put(path, params); perform(:put, path, params); end
|
36
|
+
def delete(path, params); perform(:delete, path, params); end
|
37
|
+
|
33
38
|
private
|
34
39
|
|
35
|
-
def
|
40
|
+
def perform(method, path, params)
|
36
41
|
url = "#{@host}#{path}"
|
37
42
|
|
38
43
|
response = begin
|
39
|
-
HTTP.accept(:json).
|
44
|
+
HTTP.accept(:json).send(method, url, params: params).response
|
40
45
|
rescue
|
41
46
|
raise Frenchy::ServerError
|
42
47
|
end
|
data/lib/frenchy/request.rb
CHANGED
@@ -5,7 +5,7 @@ require "active_support/notifications"
|
|
5
5
|
module Frenchy
|
6
6
|
class Request
|
7
7
|
# Create a new request with given parameters
|
8
|
-
def initialize(service, path, params={}, options={})
|
8
|
+
def initialize(service, method, path, params={}, options={})
|
9
9
|
params.stringify_keys!
|
10
10
|
|
11
11
|
path = path.dup
|
@@ -22,6 +22,7 @@ module Frenchy
|
|
22
22
|
end
|
23
23
|
|
24
24
|
@service = service
|
25
|
+
@method = method
|
25
26
|
@path = path
|
26
27
|
@params = params
|
27
28
|
@options = options
|
@@ -29,9 +30,9 @@ module Frenchy
|
|
29
30
|
|
30
31
|
# Issue the request and return the value
|
31
32
|
def value
|
32
|
-
ActiveSupport::Notifications.instrument("request.frenchy", {service: @service, path: @path, params: @params}.merge(@options)) do
|
33
|
+
ActiveSupport::Notifications.instrument("request.frenchy", {service: @service, method: @method, path: @path, params: @params}.merge(@options)) do
|
33
34
|
client = Frenchy.find_service(@service)
|
34
|
-
client.
|
35
|
+
client.send(@method, @path, @params)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
data/lib/frenchy/resource.rb
CHANGED
@@ -27,8 +27,9 @@ module Frenchy
|
|
27
27
|
# Find with a specific endpoint and params
|
28
28
|
def find_with_endpoint(endpoints, params={})
|
29
29
|
name, endpoint = resolve_endpoints(endpoints)
|
30
|
+
method = (endpoint[:method] || :get).to_sym
|
30
31
|
options = {model: self.name.underscore, endpoint: name.to_s}
|
31
|
-
response = Frenchy::Request.new(@service, endpoint[:path], params, options).value
|
32
|
+
response = Frenchy::Request.new(@service, method, endpoint[:path], params, options).value
|
32
33
|
|
33
34
|
if response.is_a?(Array)
|
34
35
|
Frenchy::Collection.new(Array(response).map {|v| from_hash(v) })
|
data/lib/frenchy/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|