Class: Gbif::Request

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpt, args, verbose, options) ⇒ Request

Returns a new instance of Request.



20
21
22
23
24
25
# File 'lib/gbifrb/request.rb', line 20

def initialize(endpt, args, verbose, options)
  self.endpt = endpt
  self.args = args
  self.verbose = verbose
  self.options = (options or {}).merge({params_encoder: Faraday::FlatParamsEncoder})
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



16
17
18
# File 'lib/gbifrb/request.rb', line 16

def args
  @args
end

#endptObject

Returns the value of attribute endpt.



15
16
17
# File 'lib/gbifrb/request.rb', line 15

def endpt
  @endpt
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/gbifrb/request.rb', line 18

def options
  @options
end

#verboseObject

Returns the value of attribute verbose.



17
18
19
# File 'lib/gbifrb/request.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#performObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gbifrb/request.rb', line 27

def perform
  if verbose
    conn = Faraday.new(:url => Gbif.base_url, :request => self.options || []) do |f|
      f.response :logger
      f.response :raise_error
      f.adapter  Faraday.default_adapter
    end
  else
    conn = Faraday.new(:url => Gbif.base_url, :request => self.options || []) do |f|
      f.response :raise_error
      f.adapter  Faraday.default_adapter
    end
  end

  conn.headers[:user_agent] = make_ua
  conn.headers["X-USER-AGENT"] = make_ua

  res = conn.get self.endpt, self.args
  return MultiJson.load(res.body)
end