Class: SpreeCmCommissioner::Integrations::Larryta::Resources::Base
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::Larryta::Resources::Base
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/resources/base.rb
Direct Known Subclasses
Booking, BookingSession, BookingTransaction, Direction, Passenger, Schedule, Seat, SeatAvailability, SeatLayout
Class Method Summary collapse
-
.from_api_response(data) ⇒ Object, Array
Parse API response data into resource objects Handles both single and collection responses.
Instance Method Summary collapse
-
#to_h ⇒ Object
Default to_h method - override in subclasses for custom serialization.
Class Method Details
.from_api_response(data) ⇒ Object, Array
Parse API response data into resource objects Handles both single and collection responses
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/base.rb', line 8 def self.from_api_response(data) return [] unless data.is_a?(Hash) if data['data'].is_a?(Array) data['data'].map { |item| new((item, data)) } elsif data['data'].is_a?(Hash) new((data['data'], data)) else new(data) end end |
Instance Method Details
#to_h ⇒ Object
Default to_h method - override in subclasses for custom serialization
32 33 34 35 36 37 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/base.rb', line 32 def to_h instance_variables.each_with_object({}) do |var, hash| key = var.to_s.delete('@').to_sym hash[key] = instance_variable_get(var) end end |