Class: Serrano::Request
- Inherits:
-
Object
- Object
- Serrano::Request
- Includes:
- Helpers
- Defined in:
- lib/serrano/request.rb,
lib/serrano/filterhandler.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#agency ⇒ Object
Returns the value of attribute agency.
-
#endpt ⇒ Object
Returns the value of attribute endpt.
-
#facet ⇒ Object
Returns the value of attribute facet.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#id ⇒ Object
Returns the value of attribute id.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#options ⇒ Object
Returns the value of attribute options.
-
#order ⇒ Object
Returns the value of attribute order.
-
#query ⇒ Object
Returns the value of attribute query.
-
#sample ⇒ Object
Returns the value of attribute sample.
-
#select ⇒ Object
Returns the value of attribute select.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#works ⇒ Object
Returns the value of attribute works.
Instance Method Summary collapse
-
#initialize(endpt, id, query, filter, offset, limit, sample, sort, order, facet, select, works, agency, options, verbose) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Methods included from Helpers
#filter_handler, #rename_keys, #stringify
Constructor Details
#initialize(endpt, id, query, filter, offset, limit, sample, sort, order, facet, select, works, agency, options, verbose) ⇒ Request
Returns a new instance of Request.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/serrano/request.rb', line 32 def initialize(endpt, id, query, filter, offset, limit, sample, sort, order, facet, select, works, agency, , verbose) self.endpt = endpt self.id = id self.query = query self.filter = filter self.offset = offset self.limit = limit self.sample = sample self.sort = sort self.order = order self.facet = facet self.select = select self.works = works self.agency = agency self. = self.verbose = verbose end |
Instance Attribute Details
#agency ⇒ Object
Returns the value of attribute agency.
28 29 30 |
# File 'lib/serrano/request.rb', line 28 def agency @agency end |
#endpt ⇒ Object
Returns the value of attribute endpt.
16 17 18 |
# File 'lib/serrano/request.rb', line 16 def endpt @endpt end |
#facet ⇒ Object
Returns the value of attribute facet.
25 26 27 |
# File 'lib/serrano/request.rb', line 25 def facet @facet end |
#filter ⇒ Object
Returns the value of attribute filter.
19 20 21 |
# File 'lib/serrano/request.rb', line 19 def filter @filter end |
#id ⇒ Object
Returns the value of attribute id.
17 18 19 |
# File 'lib/serrano/request.rb', line 17 def id @id end |
#limit ⇒ Object
Returns the value of attribute limit.
21 22 23 |
# File 'lib/serrano/request.rb', line 21 def limit @limit end |
#offset ⇒ Object
Returns the value of attribute offset.
20 21 22 |
# File 'lib/serrano/request.rb', line 20 def offset @offset end |
#options ⇒ Object
Returns the value of attribute options.
29 30 31 |
# File 'lib/serrano/request.rb', line 29 def @options end |
#order ⇒ Object
Returns the value of attribute order.
24 25 26 |
# File 'lib/serrano/request.rb', line 24 def order @order end |
#query ⇒ Object
Returns the value of attribute query.
18 19 20 |
# File 'lib/serrano/request.rb', line 18 def query @query end |
#sample ⇒ Object
Returns the value of attribute sample.
22 23 24 |
# File 'lib/serrano/request.rb', line 22 def sample @sample end |
#select ⇒ Object
Returns the value of attribute select.
26 27 28 |
# File 'lib/serrano/request.rb', line 26 def select @select end |
#sort ⇒ Object
Returns the value of attribute sort.
23 24 25 |
# File 'lib/serrano/request.rb', line 23 def sort @sort end |
#verbose ⇒ Object
Returns the value of attribute verbose.
30 31 32 |
# File 'lib/serrano/request.rb', line 30 def verbose @verbose end |
#works ⇒ Object
Returns the value of attribute works.
27 28 29 |
# File 'lib/serrano/request.rb', line 27 def works @works end |
Instance Method Details
#perform ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/serrano/request.rb', line 53 def perform filt = filter_handler(filter) self.select = select&.instance_of?(Array) ? select.join(",") : select args = {query: query, filter: filt, offset: offset, rows: limit, sample: sample, sort: sort, order: order, facet: facet, select: select} opts = args.delete_if { |_k, v| v.nil? } conn = if verbose Faraday.new(url: Serrano.base_url, request: || {}) do |f| f.response :logger f.use Faraday::SerranoErrors::Middleware end else Faraday.new(url: Serrano.base_url, request: || {}) do |f| f.use Faraday::SerranoErrors::Middleware end end conn.headers[:user_agent] = make_ua conn.headers["X-USER-AGENT"] = make_ua if id.nil? res = conn.get endpt, opts MultiJson.load(res.body) else self.id = Array(id) # url encoding self.id = id.map { |x| ERB::Util.url_encode(x) } coll = [] id.each do |x| endpt = if works self.endpt + "/" + x.to_s + "/works" elsif agency self.endpt + "/" + x.to_s + "/agency" else self.endpt + "/" + x.to_s end res = conn.get endpt, opts coll << MultiJson.load(res.body) end coll end end |