Class: Frenchy::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new request with given parameters



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

def initialize(service, method, path, params={}, extras={})
  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::Error, "The required parameter '#{k}' was not specified."
    end

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

  @service = service
  @method = method
  @path = path
  @params = params
  @extras = extras
end

Instance Attribute Details

#extrasObject

Returns the value of attribute extras.



8
9
10
# File 'lib/frenchy/request.rb', line 8

def extras
  @extras
end

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/frenchy/request.rb', line 8

def method
  @method
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/frenchy/request.rb', line 8

def params
  @params
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/frenchy/request.rb', line 8

def path
  @path
end

#serviceObject

Returns the value of attribute service.



8
9
10
# File 'lib/frenchy/request.rb', line 8

def service
  @service
end

Instance Method Details

#valueObject

Issue the request and return the value



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

def value
  Frenchy.find_service(@service).send(@method, @path, @params)
end

#value_without_instrumentationObject

Issue the request and return the value



39
40
41
# File 'lib/frenchy/request.rb', line 39

def value
  Frenchy.find_service(@service).send(@method, @path, @params)
end