frenchy 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frenchy.rb +1 -1
- data/lib/frenchy/client.rb +17 -2
- data/lib/frenchy/instrumentation.rb +1 -1
- data/lib/frenchy/resource.rb +15 -3
- 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: 37216ca75dbf240d76ca4f7db7eb02984459d5a3
|
4
|
+
data.tar.gz: b8f71d9be3b8853664ba84dd000427c13ef05c14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0b31d927cbe19c18554dc98f076bd5ac32cef99fc69b145f90141b7e969a88ea3d16fd8ca576f5675b193b941a5788fbdd428bee856ba768bd93fb5e37c704
|
7
|
+
data.tar.gz: a802d114e6ee44ed790a7322fbde501348815ccfbbaee6c1f7d26f85f1ba1d801878fff619ab7056d565010ff901dfebe5d8b217c3883d20e18051443b5e395b
|
data/lib/frenchy.rb
CHANGED
@@ -25,6 +25,6 @@ module Frenchy
|
|
25
25
|
raise(Frenchy::ConfigurationError, "No services have been configured")
|
26
26
|
end
|
27
27
|
|
28
|
-
@services[name.to_sym] || raise(Frenchy::ConfigurationError, "No service
|
28
|
+
@services[name.to_sym] || raise(Frenchy::ConfigurationError, "No service '#{name}' registered")
|
29
29
|
end
|
30
30
|
end
|
data/lib/frenchy/client.rb
CHANGED
@@ -31,6 +31,7 @@ module Frenchy
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Issue a non-retryable request with the given path and query parameters
|
34
|
+
def patch(path, params); perform(:patch, path, params); end
|
34
35
|
def post(path, params); perform(:post, path, params); end
|
35
36
|
def put(path, params); perform(:put, path, params); end
|
36
37
|
def delete(path, params); perform(:delete, path, params); end
|
@@ -46,14 +47,28 @@ module Frenchy
|
|
46
47
|
params: params
|
47
48
|
}
|
48
49
|
|
50
|
+
headers = {
|
51
|
+
"User-Agent" => "Frenchy/#{Frenchy::VERSION}",
|
52
|
+
"Accept" => "application/json",
|
53
|
+
}
|
54
|
+
|
55
|
+
body = nil
|
56
|
+
|
57
|
+
case method
|
58
|
+
when :patch, :post, :put
|
59
|
+
headers["Content-Type"] = "application/json"
|
60
|
+
body = JSON.generate(params)
|
61
|
+
params = nil
|
62
|
+
end
|
63
|
+
|
49
64
|
response = begin
|
50
|
-
HTTP.accept(:json).send(method, url, params: params).response
|
65
|
+
HTTP.accept(:json).send(method, url, headers: headers, params: params, body: body).response
|
51
66
|
rescue => exception
|
52
67
|
raise Frenchy::ServerError, {request: request, error: exception}
|
53
68
|
end
|
54
69
|
|
55
70
|
case response.code
|
56
|
-
when 200
|
71
|
+
when 200, 400
|
57
72
|
begin
|
58
73
|
JSON.parse(response.body)
|
59
74
|
rescue => e
|
@@ -13,7 +13,7 @@ module Frenchy
|
|
13
13
|
Thread.current[:frenchy_runtime] += event.duration
|
14
14
|
if logger.debug?
|
15
15
|
name = "%s (%.2fms)" % [event.payload[:service].capitalize, event.duration]
|
16
|
-
output = " #{color(name, YELLOW, true)}
|
16
|
+
output = " #{color(name, YELLOW, true)} #{event.payload[:method].to_s.upcase} #{event.payload[:path]}"
|
17
17
|
if event.payload[:params].any?
|
18
18
|
output += "?"
|
19
19
|
output += event.payload[:params].map {|k,v| "#{k}=#{v}" }.join("&")
|
data/lib/frenchy/resource.rb
CHANGED
@@ -24,13 +24,27 @@ module Frenchy
|
|
24
24
|
find_with_endpoint([:many, :default], {ids: ids.join(",")}.merge(params))
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
# Call with a specific endpoint and params
|
28
28
|
def find_with_endpoint(endpoints, params={})
|
29
29
|
name, endpoint = resolve_endpoints(endpoints)
|
30
30
|
method = (endpoint[:method] || :get).to_sym
|
31
31
|
options = {model: self.name.underscore, endpoint: name.to_s}
|
32
|
+
|
32
33
|
response = Frenchy::Request.new(@service, method, endpoint[:path], params, options).value
|
34
|
+
digest_response(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Call with arbitrary method and path
|
38
|
+
def find_with_path(method, path, params={})
|
39
|
+
options = {model: self.name.underscore, endpoint: "path"}
|
40
|
+
response = Frenchy::Request.new(@service, method.to_sym, path, params, options).value
|
41
|
+
digest_response(response)
|
42
|
+
end
|
33
43
|
|
44
|
+
private
|
45
|
+
|
46
|
+
# Converts a response into model data
|
47
|
+
def digest_response(response)
|
34
48
|
if response.is_a?(Array)
|
35
49
|
Frenchy::Collection.new(Array(response).map {|v| from_hash(v) })
|
36
50
|
else
|
@@ -38,8 +52,6 @@ module Frenchy
|
|
38
52
|
end
|
39
53
|
end
|
40
54
|
|
41
|
-
private
|
42
|
-
|
43
55
|
# Choose the first available endpoint
|
44
56
|
def resolve_endpoints(endpoints)
|
45
57
|
Array(endpoints).map(&:to_sym).each do |sym|
|
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.7
|
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-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|