Class: SpreeCmCommissioner::Integrations::Larryta::ExternalClient::Client
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::Larryta::ExternalClient::Client
- Includes:
- AuditWrapper, Connection
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb
Constant Summary collapse
- BASE_PATH =
'gateway'.freeze
- RATE_LIMIT =
100
Instance Attribute Summary collapse
-
#integration ⇒ Object
readonly
Returns the value of attribute integration.
Instance Method Summary collapse
-
#confirm_booking!(session_token:, internal_order: nil) ⇒ Object
Confirm booking.
-
#create_passenger!(full_name:, phone:, country_code:, email: nil, internal_order: nil) ⇒ Object
Create passenger.
-
#get_available_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) ⇒ Object
Get available seats.
-
#get_bus_template!(schedule_id:) ⇒ Object
Get bus template (seat layout).
-
#get_directions! ⇒ Array<Hash>, Hash
Get all available directions.
-
#get_schedules!(direction_id:, depart_date:, depart_time: nil) ⇒ Array<Hash>, Hash
Get trip schedules.
-
#get_unavailable_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) ⇒ Object
Get unavailable seats.
-
#initialize(integration:) ⇒ Client
constructor
A new instance of Client.
-
#inventory_item_status!(session_token:, internal_order: nil) ⇒ Object
Check transaction status.
-
#select_seat!(direction_id:, depart_date:, depart_time:, seat_num:, ticket_type: 'k', internal_order: nil) ⇒ Object
Select/reserve a seat.
-
#unselect_seat!(session_token:, booking_code:, seat_num:, internal_order: nil) ⇒ Object
Release seat reservation.
-
#update_booking_info!(session_token:, customer_id:, payment_type:, payment_id:, remark: nil, internal_order: nil) ⇒ Object
Update booking info.
Methods included from AuditWrapper
Constructor Details
#initialize(integration:) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 11 def initialize(integration:) @integration = integration end |
Instance Attribute Details
#integration ⇒ Object (readonly)
Returns the value of attribute integration.
9 10 11 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 9 def integration @integration end |
Instance Method Details
#confirm_booking!(session_token:, internal_order: nil) ⇒ Object
Confirm booking
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 280 def confirm_booking!(session_token:, internal_order: nil) body = { session_token: session_token } endpoint = "#{BASE_PATH}/confirm_booking" with_audit( event_base: 'larryta.bookings.confirm', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::Booking) end end |
#create_passenger!(full_name:, phone:, country_code:, email: nil, internal_order: nil) ⇒ Object
Create passenger
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 235 def create_passenger!(full_name:, phone:, country_code:, email: nil, internal_order: nil) body = { full_name: full_name, phone: phone, email: email, user_id: integration.api_uid, country_code: country_code } endpoint = "#{BASE_PATH}/create_passenger" with_audit( event_base: 'larryta.passengers.create', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::Passenger) end end |
#get_available_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) ⇒ Object
Get available seats
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 149 def get_available_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) body = { direction_id: direction_id, depart_date: depart_date, depart_time: depart_time, user_id: integration.api_uid } endpoint = "#{BASE_PATH}/get_total_available_seat" with_audit( event_base: 'larryta.seats.get_available', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::SeatAvailability) end end |
#get_bus_template!(schedule_id:) ⇒ Object
Get bus template (seat layout)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 129 def get_bus_template!(schedule_id:) body = { schedule_id: schedule_id, user_id: integration.api_uid } endpoint = "#{BASE_PATH}/get_bus_template" with_audit( event_base: 'larryta.bus_template.get', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::SeatLayout) end end |
#get_directions! ⇒ Array<Hash>, Hash
Get all available directions
41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 41 def get_directions! # rubocop:disable Naming/AccessorMethodName endpoint = "#{BASE_PATH}/get_direction" with_audit( event_base: 'larryta.directions.get_all', request: { method: 'POST', endpoint: endpoint, body: {} }, auditable: integration ) do response = post(endpoint, {}) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::Direction) end end |
#get_schedules!(direction_id:, depart_date:, depart_time: nil) ⇒ Array<Hash>, Hash
Get trip schedules
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 105 def get_schedules!(direction_id:, depart_date:, depart_time: nil) body = { direction_id: direction_id, depart_date: depart_date, enable_price: 1, user_id: integration.api_uid } body[:depart_time] = depart_time if depart_time.present? endpoint = "#{BASE_PATH}/get_schedules" with_audit( event_base: 'larryta.schedules.get', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::Schedule) end end |
#get_unavailable_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) ⇒ Object
Get unavailable seats
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 169 def get_unavailable_seats!(direction_id:, depart_date:, depart_time:, internal_order: nil) body = { direction_id: direction_id, depart_date: depart_date, depart_time: depart_time, user_id: integration.api_uid } endpoint = "#{BASE_PATH}/get_total_unavailable_seat" with_audit( event_base: 'larryta.seats.get_unavailable', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::SeatAvailability) end end |
#inventory_item_status!(session_token:, internal_order: nil) ⇒ Object
Check transaction status
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 297 def inventory_item_status!(session_token:, internal_order: nil) body = { session_token: session_token } endpoint = "#{BASE_PATH}/check_transaction" with_audit( event_base: 'larryta.transactions.check', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::BookingTransaction) end end |
#select_seat!(direction_id:, depart_date:, depart_time:, seat_num:, ticket_type: 'k', internal_order: nil) ⇒ Object
Select/reserve a seat
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 191 def select_seat!(direction_id:, depart_date:, depart_time:, seat_num:, ticket_type: 'k', internal_order: nil) # rubocop:disable Metrics/ParameterLists body = { direction_id: direction_id, depart_date: depart_date, depart_time: depart_time, seat_num: seat_num, ticket_type: ticket_type, channel: 'api', user_id: integration.api_uid } endpoint = "#{BASE_PATH}/select_seat" with_audit( event_base: 'larryta.seats.select', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::BookingSession) end end |
#unselect_seat!(session_token:, booking_code:, seat_num:, internal_order: nil) ⇒ Object
Release seat reservation
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 214 def unselect_seat!(session_token:, booking_code:, seat_num:, internal_order: nil) body = { session_token: session_token, booking_code: booking_code, seat_num: seat_num } endpoint = "#{BASE_PATH}/unselect_seat" with_audit( event_base: 'larryta.seats.unselect', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response) end end |
#update_booking_info!(session_token:, customer_id:, payment_type:, payment_id:, remark: nil, internal_order: nil) ⇒ Object
Update booking info
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/external_client/client.rb', line 258 def update_booking_info!(session_token:, customer_id:, payment_type:, payment_id:, remark: nil, internal_order: nil) # rubocop:disable Metrics/ParameterLists body = { session_token: session_token, customer_id: customer_id, payment_type: payment_type, payment_id: payment_id, remark: remark, user_id: integration.api_uid } endpoint = "#{BASE_PATH}/update_info" with_audit( event_base: 'larryta.bookings.update_info', request: { method: 'POST', endpoint: endpoint, body: body }, auditable: internal_order || integration ) do response = post(endpoint, body) handle_response(response, SpreeCmCommissioner::Integrations::Larryta::Resources::BookingSession) end end |