Class: Lighthouse::Facilities::V1::Response
- Inherits:
-
Common::Base
- Object
- Common::Base
- Lighthouse::Facilities::V1::Response
- Defined in:
- lib/lighthouse/facilities/v1/response.rb
Instance Attribute Summary
Attributes inherited from Common::Base
Instance Method Summary collapse
- #facilities ⇒ Object
- #facility ⇒ Object
-
#initialize(body, status) ⇒ Response
constructor
A new instance of Response.
Methods inherited from Common::Base
#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes
Constructor Details
#initialize(body, status) ⇒ Response
Returns a new instance of Response.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lighthouse/facilities/v1/response.rb', line 19 def initialize(body, status) super() self.body = body self.status = status parsed_body = JSON.parse(body) self.data = parsed_body['data'] || [] self. = parsed_body['meta'] self.links = parsed_body['links'] if self.current_page = ['pagination']['currentPage'] self.per_page = ['pagination']['perPage'] self.total_entries = ['pagination']['totalEntries'] end end |
Instance Method Details
#facilities ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lighthouse/facilities/v1/response.rb', line 34 def facilities facilities = data.each_with_index.map do |facility, index| facility['attributes'] = facility['attributes'].transform_keys(&:underscore) fac = Lighthouse::Facilities::Facility.new(facility) fac.distance = ['distances'][index]['distance'] if ['distances'].present? fac end WillPaginate::Collection.create(current_page, per_page) do |pager| pager.replace(facilities) pager.total_entries = total_entries end end |
#facility ⇒ Object
48 49 50 |
# File 'lib/lighthouse/facilities/v1/response.rb', line 48 def facility Lighthouse::Facilities::Facility.new(data) end |