Class: Traitify::Response
- Inherits:
-
Object
- Object
- Traitify::Response
- Defined in:
- lib/traitify/response.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(request) ⇒ Response
constructor
A new instance of Response.
- #page ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(request) ⇒ Response
Returns a new instance of Response.
7 8 9 |
# File 'lib/traitify/response.rb', line 7 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/traitify/response.rb', line 5 def request @request end |
Instance Method Details
#data ⇒ Object
11 12 13 |
# File 'lib/traitify/response.rb', line 11 def data @data ||= Traitify::Data.new(request.body) end |
#page ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/traitify/response.rb', line 15 def page @page ||= begin page = {} if request.env.response_headers["link"] links = request.env.response_headers["link"].split(",") if prev_link = links.find{ |link| link.include?("rel=\"prev\"") } prev_link = prev_link.split(/>|</)[1] page[:previous] = { url: prev_link, params: CGI.parse(prev_link.split("?")[1..-1].join("?")) } end if next_link = links.find{ |link| link.include?("rel=\"next\"") } next_link = next_link.split(/>|</)[1] page[:next] = { url: next_link, params: CGI.parse(next_link.split("?")[1..-1].join("?")) } end end Traitify::Data.new page end end |
#total ⇒ Object
42 43 44 |
# File 'lib/traitify/response.rb', line 42 def total @total ||= request.env.response_headers["x-total-count"] end |