Class: Vessel::Response
- Inherits:
-
Object
- Object
- Vessel::Response
- Extended by:
- Forwardable
- Defined in:
- lib/vessel/response.rb
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#handler ⇒ Object
(also: #callback)
readonly
Returns the value of attribute handler.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#rejected ⇒ Object
Returns the value of attribute rejected.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #absolute_url(relative, encode: true) ⇒ Object
- #body ⇒ Object
- #close ⇒ Object
- #headers ⇒ Object
-
#initialize(handler:, url: nil, data: nil, page: nil, attempt: 1) ⇒ Response
constructor
A new instance of Response.
- #join_url(head, tail) ⇒ Object
- #raw ⇒ Object
- #size ⇒ Object
- #status ⇒ Object
- #stub? ⇒ Boolean
- #sync_body(seconds = 2) ⇒ Object
- #url_decode(uri) ⇒ Object (also: #uri_decode)
- #url_encode(uri) ⇒ Object (also: #uri_encode)
Constructor Details
#initialize(handler:, url: nil, data: nil, page: nil, attempt: 1) ⇒ Response
Returns a new instance of Response.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vessel/response.rb', line 16 def initialize(handler:, url: nil, data: nil, page: nil, attempt: 1) @url = Addressable::URI.parse(url) if url @data = data @handler = handler @attempt = attempt @driven_page = page @page = @driven_page&.page @rejected = false @cookies = @driven_page&.&.map do |c| { name: c.name, value: c.value, domain: c.domain, path: c.path, httponly: c.httponly?, secure: c.secure?, expires: c.expires } end end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def attempt @attempt end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def @cookies end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def data @data end |
#handler ⇒ Object (readonly) Also known as: callback
Returns the value of attribute handler.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def handler @handler end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def page @page end |
#rejected ⇒ Object
Returns the value of attribute rejected.
11 12 13 |
# File 'lib/vessel/response.rb', line 11 def rejected @rejected end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/vessel/response.rb', line 12 def url @url end |
Instance Method Details
#==(other) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/vessel/response.rb', line 91 def ==(other) url == other.url && data == other.data && handler == other.handler && page == other.page && attempt == other.attempt && == other. end |
#absolute_url(relative, encode: true) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/vessel/response.rb', line 34 def absolute_url(relative, encode: true) if encode relative = url_decode(relative) relative = url_encode(relative) end join_url(url.to_s, relative) end |
#body ⇒ Object
56 57 58 |
# File 'lib/vessel/response.rb', line 56 def body @body ||= Nokogiri::HTML(raw) end |
#close ⇒ Object
70 71 72 73 |
# File 'lib/vessel/response.rb', line 70 def close @driven_page&.close @driven_page = @page = nil end |
#headers ⇒ Object
83 84 85 |
# File 'lib/vessel/response.rb', line 83 def headers @driven_page&.headers end |
#join_url(head, tail) ⇒ Object
42 43 44 |
# File 'lib/vessel/response.rb', line 42 def join_url(head, tail) Addressable::URI.join(head, tail).to_s end |
#raw ⇒ Object
60 61 62 |
# File 'lib/vessel/response.rb', line 60 def raw @raw ||= @driven_page&.body end |
#size ⇒ Object
87 88 89 |
# File 'lib/vessel/response.rb', line 87 def size @driven_page&.size end |
#status ⇒ Object
79 80 81 |
# File 'lib/vessel/response.rb', line 79 def status @driven_page&.status end |
#stub? ⇒ Boolean
75 76 77 |
# File 'lib/vessel/response.rb', line 75 def stub? !url end |
#sync_body(seconds = 2) ⇒ Object
64 65 66 67 68 |
# File 'lib/vessel/response.rb', line 64 def sync_body(seconds = 2) sleep(seconds) @raw = @body = nil body end |
#url_decode(uri) ⇒ Object Also known as: uri_decode
51 52 53 |
# File 'lib/vessel/response.rb', line 51 def url_decode(uri) Addressable::URI.unencode(uri) end |
#url_encode(uri) ⇒ Object Also known as: uri_encode
46 47 48 |
# File 'lib/vessel/response.rb', line 46 def url_encode(uri) Addressable::URI.encode(uri) end |