Class: LCBO::CrawlKit::Request
- Inherits:
-
Object
- Object
- LCBO::CrawlKit::Request
- Defined in:
- lib/lcbo/crawlkit/request.rb
Constant Summary collapse
- MAX_RETRIES =
8
Instance Attribute Summary collapse
-
#body_params ⇒ Object
Returns the value of attribute body_params.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#request_prototype ⇒ Object
readonly
Returns the value of attribute request_prototype.
Instance Method Summary collapse
- #config ⇒ Object
- #gettable? ⇒ Boolean
-
#initialize(request_prototype, query_p = {}, body_p = {}) ⇒ Request
constructor
A new instance of Request.
- #run ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(request_prototype, query_p = {}, body_p = {}) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 |
# File 'lib/lcbo/crawlkit/request.rb', line 9 def initialize(request_prototype, query_p = {}, body_p = {}) @request_prototype = request_prototype self.query_params = query_p self.body_params = body_p end |
Instance Attribute Details
#body_params ⇒ Object
Returns the value of attribute body_params.
7 8 9 |
# File 'lib/lcbo/crawlkit/request.rb', line 7 def body_params @body_params end |
#query_params ⇒ Object
Returns the value of attribute query_params.
7 8 9 |
# File 'lib/lcbo/crawlkit/request.rb', line 7 def query_params @query_params end |
#request_prototype ⇒ Object (readonly)
Returns the value of attribute request_prototype.
7 8 9 |
# File 'lib/lcbo/crawlkit/request.rb', line 7 def request_prototype @request_prototype end |
Instance Method Details
#config ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/lcbo/crawlkit/request.rb', line 27 def config opts = {} opts[:method] = request_prototype.http_method opts[:headers] = { 'User-Agent' => LCBO.user_agent } opts[:body] = body_params if (body_params && body_params.any?) && !gettable? opts end |
#gettable? ⇒ Boolean
23 24 25 |
# File 'lib/lcbo/crawlkit/request.rb', line 23 def gettable? [:head, :get].include?(request_prototype.http_method) end |
#run ⇒ Object
44 45 46 |
# File 'lib/lcbo/crawlkit/request.rb', line 44 def run _run end |
#uri ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/lcbo/crawlkit/request.rb', line 35 def uri @uri ||= begin template = request_prototype.uri_template.dup query_params.reduce(template) do |mem, (key, value)| mem.gsub("{#{key}}", value.to_s) end end end |