Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::InventoryItemStatus

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_json_api, from_json_api_item, from_json_api_single

Constructor Details

#initialize(attributes = {}) ⇒ InventoryItemStatus

rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 30

def initialize(attributes = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  super(attributes)

  @raw_data = attributes
  @from_location = attributes['from_location'] || {}
  @to_location = attributes['to_location'] || {}
  @from_stop_time = attributes['from_stop_time'] || {}
  @to_stop_time = attributes['to_stop_time'] || {}
  @operator = attributes['operator'] || {}
  @reserved_seats = attributes['reserved_seats'] || {}
  @reservation_cart = attributes['reservation_cart'] || {}
  @stop_times = attributes['stop_times'] || []
  @seat_stops = attributes['seat_stops'] || []
  @user = attributes['user'] || {}
  @vehicle_type = attributes['vehicle_type'] || {}
end

Instance Attribute Details

#amountObject

Financials



19
20
21
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19

def amount
  @amount
end

#arrival_timeObject

Schedule



13
14
15
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13

def arrival_time
  @arrival_time
end

#contact_emailObject

Contact and participants



22
23
24
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22

def contact_email
  @contact_email
end

#contact_phoneObject

Contact and participants



22
23
24
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22

def contact_phone
  @contact_phone
end

#created_atObject

Returns the value of attribute created_at.



10
11
12
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10

def created_at
  @created_at
end

#departure_dateObject

Schedule



13
14
15
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13

def departure_date
  @departure_date
end

#departure_timeObject

Schedule



13
14
15
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13

def departure_time
  @departure_time
end

#discountObject

Financials



19
20
21
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19

def discount
  @discount
end

#fareObject

Financials



19
20
21
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19

def fare
  @fare
end

#from_locationObject

Locations and stops



9
10
11
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 9

def from_location
  @from_location
end

#from_stop_timeObject

Returns the value of attribute from_stop_time.



10
11
12
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10

def from_stop_time
  @from_stop_time
end

#idObject

Identity



6
7
8
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6

def id
  @id
end

#number_of_seatsObject

Seats and vehicle



16
17
18
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16

def number_of_seats
  @number_of_seats
end

#operatorObject

Contact and participants



22
23
24
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22

def operator
  @operator
end

Returns the value of attribute paid_at.



10
11
12
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10

def paid_at
  @paid_at
end

#raw_dataObject

Raw API response



28
29
30
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 28

def raw_data
  @raw_data
end

#reservation_cartObject

Contact and participants



22
23
24
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22

def reservation_cart
  @reservation_cart
end

#reservation_eticket_urlObject

URLs and timestamps



25
26
27
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 25

def reservation_eticket_url
  @reservation_eticket_url
end

#reservation_numberObject

Identity



6
7
8
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6

def reservation_number
  @reservation_number
end

#reservation_qr_code_urlObject

URLs and timestamps



25
26
27
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 25

def reservation_qr_code_url
  @reservation_qr_code_url
end

#reserved_seatsObject

Seats and vehicle



16
17
18
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16

def reserved_seats
  @reserved_seats
end

#seat_stopsObject

Seats and vehicle



16
17
18
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16

def seat_stops
  @seat_stops
end

#statusObject

Identity



6
7
8
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6

def status
  @status
end

#stop_timesObject

Returns the value of attribute stop_times.



10
11
12
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10

def stop_times
  @stop_times
end

#ticket_typeObject

Identity



6
7
8
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6

def ticket_type
  @ticket_type
end

#to_locationObject

Locations and stops



9
10
11
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 9

def to_location
  @to_location
end

#to_stop_timeObject

Returns the value of attribute to_stop_time.



10
11
12
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10

def to_stop_time
  @to_stop_time
end

#typeObject

Identity



6
7
8
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6

def type
  @type
end

#userObject

Contact and participants



22
23
24
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22

def user
  @user
end

#vehicle_typeObject

Seats and vehicle



16
17
18
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16

def vehicle_type
  @vehicle_type
end

Instance Method Details

#ageObject



70
71
72
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 70

def age
  first_seat&.dig('age')
end

#arrival_time_formattedObject



111
112
113
114
115
116
117
118
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 111

def arrival_time_formatted
  return nil unless arrival_time

  seconds = arrival_time.to_i
  hours = seconds / 3600
  minutes = (seconds % 3600) / 60
  format('%<hours>02d:%<minutes>02d', hours: hours, minutes: minutes)
end

#cart_idObject



98
99
100
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 98

def cart_id
  reservation_cart['id']
end

#confirmed?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 78

def confirmed?
  paid? || status == 'confirmed'
end

#departure_time_formattedObject



102
103
104
105
106
107
108
109
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 102

def departure_time_formatted
  return nil unless departure_time

  seconds = departure_time.to_i
  hours = seconds / 3600
  minutes = (seconds % 3600) / 60
  format('%<hours>02d:%<minutes>02d', hours: hours, minutes: minutes)
end

#destination_nameObject



86
87
88
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 86

def destination_name
  to_location['name']
end

#first_seatObject

Get first reserved seat details



48
49
50
51
52
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 48

def first_seat
  return nil if reserved_seats.empty?

  reserved_seats.values.flatten.first
end

#genderObject



66
67
68
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 66

def gender
  first_seat&.dig('gender')
end

#nationalityObject



62
63
64
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 62

def nationality
  first_seat&.dig('readable_nationality') || first_seat&.dig('nationality')
end

#operator_nameObject



90
91
92
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 90

def operator_name
  operator['name']
end

#origin_nameObject



82
83
84
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 82

def origin_name
  from_location['name']
end

#paid?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 74

def paid?
  status == 'paid'
end

#passenger_nameObject



54
55
56
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 54

def passenger_name
  first_seat&.dig('name')
end

#seat_labelObject



58
59
60
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 58

def seat_label
  first_seat&.dig('label')
end

#to_hObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 120

def to_h
  {
    id: id,
    reservation_number: reservation_number,
    status: status,
    passenger_name: passenger_name,
    seat_label: seat_label,
    origin: origin_name,
    destination: destination_name,
    departure_date: departure_date,
    departure_time: departure_time,
    arrival_time: arrival_time,
    fare: fare,
    amount: amount,
    contact_phone: contact_phone,
    contact_email: contact_email,
    operator: operator_name,
    vehicle_type: vehicle_type_name,
    nationality: nationality,
    gender: gender,
    age: age,
    qr_code_url: reservation_qr_code_url,
    eticket_url: reservation_eticket_url,
    paid_at: paid_at,
    created_at: created_at
  }
end

#vehicle_type_nameObject



94
95
96
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 94

def vehicle_type_name
  vehicle_type['name']
end