frenchy 0.0.1 → 0.0.2

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: 8bfef8fd98c84c71e524f5162592c7a482871a87
4
- data.tar.gz: 1420a7aa007282159d99ec13dceeea34479ffbe1
3
+ metadata.gz: ad1db4590ae68aec65ae8a7ed857d142897c49c9
4
+ data.tar.gz: 989a36bdc75e33f16ed6c73ad1cc37382e336523
5
5
  SHA512:
6
- metadata.gz: 05eb4261adeb633381985e6c7e949fb6851d0247fc0c980f446c6bfea4ce34806811e579f1de66cc3f3c43f5c7df09a2446130e78c5ad72cfbbe6c1f3810209d
7
- data.tar.gz: 155a63ef8a914acef37dc832d446fb6db131f578527997c87c96367c9826803d692b7a8f5327d555cee8dd2d29cbb14c12575880a6c11124763b0a66a24ed259
6
+ metadata.gz: bf9d3d87f2bc87909b173223400525cda80eb502a3b5db753eb87f5429e30ad1f92856e39770dfd96ab970a7985c3095761aa067b43660d6500ffef0aa7fa6a7
7
+ data.tar.gz: aae4fbe9d4964a19f9e8ea65178f8ae7cab4ec13c759947a58ffa8dc280557f3bc2e7e28330c37f4cf5cd9bfbd261c7a21ec6eba4b905b9e0c630c96782720cd
@@ -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) || 30
13
- @retries = options.delete(:retires) || 5
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 = 1
18
+ try = 0
19
19
  error = nil
20
20
 
21
- while try < @retries
21
+ while try <= @retries
22
22
  begin
23
- return get_once(path, params)
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 get_once(path, params)
40
+ def perform(method, path, params)
36
41
  url = "#{@host}#{path}"
37
42
 
38
43
  response = begin
39
- HTTP.accept(:json).get(url, params: params).response
44
+ HTTP.accept(:json).send(method, url, params: params).response
40
45
  rescue
41
46
  raise Frenchy::ServerError
42
47
  end
@@ -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.get(@path, @params)
35
+ client.send(@method, @path, @params)
35
36
  end
36
37
  end
37
38
  end
@@ -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) })
@@ -1,3 +1,3 @@
1
1
  module Frenchy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.0.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel