Class: Lagotto::BasicRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/lagotto-rb/req.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, path, key, options, verbose, addargs) ⇒ BasicRequest

Returns a new instance of BasicRequest.



16
17
18
19
20
21
22
23
24
# File 'lib/lagotto-rb/req.rb', line 16

def initialize(url, path, key, options, verbose, addargs)

  self.url = url
  self.path = path
  self.key = key
  self.options = options
  self.verbose = verbose
  self.addargs = addargs
end

Instance Attribute Details

#addargsObject

Returns the value of attribute addargs.



14
15
16
# File 'lib/lagotto-rb/req.rb', line 14

def addargs
  @addargs
end

#keyObject

Returns the value of attribute key.



11
12
13
# File 'lib/lagotto-rb/req.rb', line 11

def key
  @key
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/lagotto-rb/req.rb', line 12

def options
  @options
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/lagotto-rb/req.rb', line 10

def path
  @path
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/lagotto-rb/req.rb', line 9

def url
  @url
end

#verboseObject

Returns the value of attribute verbose.



13
14
15
# File 'lib/lagotto-rb/req.rb', line 13

def verbose
  @verbose
end

Instance Method Details

#performObject



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

def perform
  args = { api_key: self.key }
  args = args.merge(addargs)
  opts = args.delete_if { |k, v| v.nil? }

  if verbose
    conn = Faraday.new(:url => self.url, :request => options) do |f|
      f.response :logger
      f.headers['Accept'] = 'application/json'
      f.adapter  Faraday.default_adapter
    end
  else
    conn = Faraday.new(:url => self.url, :request => options) do |f|
      f.headers['Accept'] = 'application/json'
      f.adapter  Faraday.default_adapter
    end
  end

  res = conn.get self.path, opts

  return MultiJson.load(res.body)
end