Sha256: 1658842c625e5f43f4a31f8580114dc32867b67bfc8c95030a1f8b18282ef75f

Contents?: true

Size: 1.94 KB

Versions: 31

Compression:

Stored size: 1.94 KB

Contents

#!/usr/bin/env ruby
lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'gillbus'
require 'pry'
require 'securerandom'

GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"

require 'logger'

driver = Faraday.new(url: GILLBUS_SERVER) { |c|
  c.response :logger, Logger.new(STDOUT), bodies: true
  c.request :url_encoded
  c.adapter Faraday.default_adapter
}

g = Gillbus.new(driver: driver).login(
  password: GILLBUS_PASSWORD,
  locale: :ru
)

# getCities

cities = g.get_cities.cities

kiiv_id = cities.find {|c| c.name == "Киев" }.id
lviv_id = cities.find {|c| c.name == "Львов" }.id


# searchTrips

search_date = Date.today + 7
trips = g.search_trips(
  start_city_id: kiiv_id,
  end_city_id: lviv_id,
  start_date_search: search_date,
  ticket_count: 2,
  selected_modes: 1,
).trips

trip_id = trips.find { |trip| trip.reservation_enabled == true }.id

# lockSeats

tl = g.lock_seats(
  trip_id: trip_id,
).time_limit

# ticketsBooking
order_id = SecureRandom.uuid

puts "making order: #{order_id}"
passengers = [
  { first_name: 'Иван', last_name: 'Иванов' },
  { first_name: 'Петр', last_name: 'Петров' }
]

rt = g.reserve_tickets(
  order_id: order_id,
  mail_address: 'ivan@mail.ru',
  note: 'test',
  passengers: passengers
)
ticket_numbers = rt.tickets.map(&:ticket_number)

# relogging again

g = Gillbus.new(driver: driver).login(password: GILLBUS_PASSWORD, locale: :ru)

# buyBooking
response = g.buy_booking(
  ticket_count: 2,
  ticket_numbers: ticket_numbers,
  order_ids: [order_id, order_id]
)
p "confirmation: " + response.ticket.confirmation.inspect
p "ticket_numbers: " + response.ticket.position_numbers.inspect

# getOrderTicket
ot = g.get_order_ticket order_id: order_id, base64: true

filename = order_id + ".pdf"
puts "saving " + filename
File.open filename, 'wb' do |f|
  f << ot.ticket
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
gillbus-0.16.7 script/example_reservation.rb
gillbus-0.16.6 script/example_reservation.rb
gillbus-0.16.5 script/example_reservation.rb
gillbus-0.16.4 script/example_reservation.rb
gillbus-0.16.3 script/example_reservation.rb
gillbus-0.16.2 script/example_reservation.rb
gillbus-0.16.1 script/example_reservation.rb
gillbus-0.15.7 script/example_reservation.rb
gillbus-0.15.6 script/example_reservation.rb
gillbus-0.15.5 script/example_reservation.rb
gillbus-0.15.4 script/example_reservation.rb
gillbus-0.15.3 script/example_reservation.rb
gillbus-0.15.2 script/example_reservation.rb
gillbus-0.15.1 script/example_reservation.rb
gillbus-0.15.0 script/example_reservation.rb
gillbus-0.14.12 script/example_reservation.rb
gillbus-0.14.11 script/example_reservation.rb
gillbus-0.14.10 script/example_reservation.rb
gillbus-0.14.9 script/example_reservation.rb
gillbus-0.14.8 script/example_reservation.rb