Class: Frenchy::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/frenchy/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(service, method, path, params = {}, options = {}) ⇒ Request

Create a new request with given parameters



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/frenchy/request.rb', line 8

def initialize(service, method, path, params={}, options={})
  params.stringify_keys!

  path = path.dup
  path.scan(/(:[a-z0-9_+]+)/).flatten.uniq.each do |pat|
    k = pat.sub(":", "")
    begin
      v = params.fetch(pat.sub(":", "")).to_s
    rescue
      raise Frenchy::InvalidRequest, "The required parameter '#{k}' was not specified."
    end

    params.delete(k)
    path.sub!(pat, v)
  end

  @service = service
  @method = method
  @path = path
  @params = params
  @options = options
end

Instance Method Details

#valueObject

Issue the request and return the value



32
33
34
35
36
37
# File 'lib/frenchy/request.rb', line 32

def value
  ActiveSupport::Notifications.instrument("request.frenchy", {service: @service, method: @method, path: @path, params: @params}.merge(@options)) do
    client = Frenchy.find_service(@service)
    client.send(@method, @path, @params)
  end
end