Class: Lagotto::Request

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, path, ids, type, source, publisher, order, per_page, page, key, options, verbose) ⇒ Request

Returns a new instance of Request.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lagotto-rb/request.rb', line 23

def initialize(url, path, ids, type, source,
  publisher, order, per_page, page, key,
  options, verbose)

  self.url = url
  self.path = path
  self.ids = ids
  self.type = type
  self.source = source
  self.publisher = publisher
  self.order = order
  self.per_page = per_page
  self.page = page
  self.key = key
  self.options = options
  self.verbose = verbose
end

Instance Attribute Details

#idsObject

Returns the value of attribute ids.



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

def ids
  @ids
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

#keyObject

Returns the value of attribute key.



19
20
21
# File 'lib/lagotto-rb/request.rb', line 19

def key
  @key
end

#optionsObject

Returns the value of attribute options.



20
21
22
# File 'lib/lagotto-rb/request.rb', line 20

def options
  @options
end

#orderObject

Returns the value of attribute order.



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

def order
  @order
end

#pageObject

Returns the value of attribute page.



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

def page
  @page
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#per_pageObject

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#publisherObject

Returns the value of attribute publisher.



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

def publisher
  @publisher
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#verboseObject

Returns the value of attribute verbose.



21
22
23
# File 'lib/lagotto-rb/request.rb', line 21

def verbose
  @verbose
end

Instance Method Details

#performObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lagotto-rb/request.rb', line 41

def perform
  args = { ids: self.ids, type: self.type,
          source: self.source, publisher: self.publisher,
          order: self.order, per_page: self.per_page,
          page: self.page, api_key: self.key }
  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