gillbus 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +10 -0
  5. data/Guardfile +29 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +140 -0
  8. data/Rakefile +9 -0
  9. data/gillbus.gemspec +31 -0
  10. data/lib/gillbus/base_request.rb +99 -0
  11. data/lib/gillbus/base_response.rb +43 -0
  12. data/lib/gillbus/buy_booking.rb +74 -0
  13. data/lib/gillbus/buy_tickets.rb +36 -0
  14. data/lib/gillbus/cancel_order.rb +55 -0
  15. data/lib/gillbus/drivers/faraday_response_file_logger.rb +19 -0
  16. data/lib/gillbus/find_order.rb +37 -0
  17. data/lib/gillbus/get_all_cities.rb +24 -0
  18. data/lib/gillbus/get_cities.rb +34 -0
  19. data/lib/gillbus/get_countries.rb +24 -0
  20. data/lib/gillbus/get_dates_new.rb +35 -0
  21. data/lib/gillbus/get_order_status.rb +28 -0
  22. data/lib/gillbus/get_order_ticket.rb +62 -0
  23. data/lib/gillbus/get_required_fields.rb +32 -0
  24. data/lib/gillbus/get_time_table.rb +33 -0
  25. data/lib/gillbus/get_trip_seats.rb +61 -0
  26. data/lib/gillbus/get_trips.rb +13 -0
  27. data/lib/gillbus/helpers/fields.rb +47 -0
  28. data/lib/gillbus/helpers/parser.rb +100 -0
  29. data/lib/gillbus/helpers/update_attrs.rb +15 -0
  30. data/lib/gillbus/lock_seats.rb +82 -0
  31. data/lib/gillbus/logout.rb +19 -0
  32. data/lib/gillbus/parse_error.rb +11 -0
  33. data/lib/gillbus/reserve_tickets.rb +13 -0
  34. data/lib/gillbus/search_trips.rb +96 -0
  35. data/lib/gillbus/session_login.rb +32 -0
  36. data/lib/gillbus/structs/commission.rb +54 -0
  37. data/lib/gillbus/structs/item.rb +14 -0
  38. data/lib/gillbus/structs/passenger_discount.rb +37 -0
  39. data/lib/gillbus/structs/point.rb +38 -0
  40. data/lib/gillbus/structs/return_cause.rb +23 -0
  41. data/lib/gillbus/structs/seat.rb +38 -0
  42. data/lib/gillbus/structs/segment.rb +161 -0
  43. data/lib/gillbus/structs/tariff.rb +59 -0
  44. data/lib/gillbus/structs/ticket.rb +285 -0
  45. data/lib/gillbus/structs/timetable_segment.rb +51 -0
  46. data/lib/gillbus/structs/timetable_trip.rb +77 -0
  47. data/lib/gillbus/structs/trip.rb +164 -0
  48. data/lib/gillbus/tickets_booking.rb +182 -0
  49. data/lib/gillbus/unlock_seats.rb +15 -0
  50. data/lib/gillbus/version.rb +3 -0
  51. data/lib/gillbus.rb +86 -0
  52. data/script/example_booking.rb +82 -0
  53. data/script/example_booking_with_segments.rb +90 -0
  54. data/script/example_canceling_booking.rb +67 -0
  55. data/script/example_canceling_reservation.rb +69 -0
  56. data/script/example_reservation.rb +88 -0
  57. data/test/buy_booking_test.rb +32 -0
  58. data/test/buy_tickets_test.rb +12 -0
  59. data/test/cancel_order_test.rb +12 -0
  60. data/test/error_test.rb +31 -0
  61. data/test/find_order_test.rb +24 -0
  62. data/test/get_cities_test.rb +12 -0
  63. data/test/get_countries_test.rb +12 -0
  64. data/test/get_dates_new_test.rb +12 -0
  65. data/test/get_order_ticket_test.rb +12 -0
  66. data/test/get_time_table_test.rb +21 -0
  67. data/test/get_trip_seats_test.rb +40 -0
  68. data/test/lock_seats_test.rb +70 -0
  69. data/test/reserve_tickets_test.rb +22 -0
  70. data/test/responses/buyBooking.xml +9 -0
  71. data/test/responses/buyTickets.xml +7 -0
  72. data/test/responses/cancelOrder.xml +8 -0
  73. data/test/responses/error.xml +1 -0
  74. data/test/responses/findOrder.xml +296 -0
  75. data/test/responses/getCities.xml +266 -0
  76. data/test/responses/getCountries.xml +90 -0
  77. data/test/responses/getOrderTicket.xml +3 -0
  78. data/test/responses/getTimeTable.xml +81 -0
  79. data/test/responses/getTripSeats-one-empty-segment.xml +562 -0
  80. data/test/responses/getTripSeats-segments.xml +1052 -0
  81. data/test/responses/getTripSeats.xml +492 -0
  82. data/test/responses/lockSeats.xml +23 -0
  83. data/test/responses/reserveTickets.xml +76 -0
  84. data/test/responses/searchTrips-empty.xml +3 -0
  85. data/test/responses/searchTrips-prod.xml +193 -0
  86. data/test/responses/searchTrips-segments-roundtrip.xml +15812 -0
  87. data/test/responses/searchTrips-segments.xml +808 -0
  88. data/test/responses/sessionLogin.xml +3 -0
  89. data/test/responses/ticketsBooking.xml +75 -0
  90. data/test/responses/very_empty.xml +1 -0
  91. data/test/search_trips_test.rb +71 -0
  92. data/test/session_login_test.rb +12 -0
  93. data/test/test_helper.rb +3 -0
  94. data/test/tickets_booking_test.rb +16 -0
  95. metadata +303 -0
@@ -0,0 +1,182 @@
1
+ class Gillbus
2
+ module TicketsBooking
3
+
4
+ Gillbus.register self, :tickets_booking
5
+
6
+ class Request < BaseRequest
7
+
8
+ def path; '/online2/ticketsBooking' end
9
+
10
+ # orderId
11
+ # Сгенерированный уникальный ИД заказа.
12
+ attr_accessor :order_id
13
+
14
+ # terminalNumber (не обязательный)
15
+ # Номер терминала, с которого выполняется команда.
16
+ attr_accessor :terminal_number
17
+
18
+ # applyDiscount (не обязательный)
19
+ # Если при поиске рейсов не были указаны скидочные данные но есть возможность их применить при оформлении отложенной продажи (параметр CAN_DISCOUNT = true при поиске рейсов), то для применения скидочных данных необходимо этот параметр установить в true. Если на оформляемый рейс действуют скидки, то стоимость тарифа может быть пересчитана по переданным данным в параметрах passenger(0 - N)studentTicket, passenger(0 - N)birthday, passenger(0 - N)ISIC. По умолчанию false (скидочные данные не применяются ).
20
+ attr_accessor :apply_discount
21
+
22
+ # paymentMethod (не обязательный)
23
+ # Способ оплаты заказа.
24
+ attr_accessor :payment_method
25
+
26
+ # 1 – наличный;
27
+ METHOD_CASH = 1
28
+ # 2 – кредитной карточкой;
29
+ METHOD_CARD = 2
30
+ # 3 – безналичный;
31
+ METHOD_NOCASH = 3
32
+ # 4 – сервисный;
33
+ METHOD_SERVICE = 4
34
+ # 5 – эквайринг.
35
+ METHOD_ACQUIRING = 5
36
+ # По умолчанию 3.
37
+
38
+ # phoneNumber (не обязательный)
39
+ # Номер телефона пассажира.
40
+ attr_accessor :phone_number
41
+
42
+ # mailAddress (не обязательный)
43
+ # Адрес электронной почты пассажира. Если указан, то на него будет отправлен маршрутный лист соответствующий форме утвержденной с перевозчиком.
44
+ attr_accessor :mail_address
45
+
46
+ # note (не обязательный)
47
+ # Примечания.
48
+ attr_accessor :note
49
+
50
+ # ticketLocale (не обязательный)
51
+ # Язык, на котором будут возвращены данные для печати билета. Если язык не передан или ошибочный, то будет установлен язык переданный при вызове команды входа в систему.
52
+ # rus – русский;
53
+ # ukr – украинский; lat – английский.
54
+ attr_accessor :ticket_locale
55
+
56
+ # список пассажиров
57
+ attr_accessor :passengers
58
+
59
+ # отправлять ли email с листом бронирования пользователю
60
+ attr_accessor :send_to
61
+
62
+ def params
63
+ pax = (passengers || []).map.with_index { |p, i| Passenger.new(p).params("passenger#{i}") }.reduce({}, :merge)
64
+ compact(
65
+ orderId: order_id,
66
+ terminalNumber: terminal_number,
67
+ applyDiscount: apply_discount,
68
+ paymentMethod: payment_method,
69
+ phoneNumber: phone_number,
70
+ mailAddress: mail_address,
71
+ note: note,
72
+ ticketLocale: translated_locale(ticket_locale),
73
+ sendTo: send_to,
74
+ **pax
75
+ )
76
+
77
+ end
78
+
79
+ # not a request, just a record for BookTickets
80
+ class Passenger < BaseRequest
81
+
82
+ # passenger0studentTicket... passengerNstudentTicket (не обязательный)
83
+ # Номер студенческого билета пассажира с порядковым номером 0... N.
84
+
85
+ # passenger0birthday... passengerNbirthday (обязательный для авиаперевозки)
86
+ # Дата рождения пассажира с порядковым номером 0...N.
87
+ attr_accessor :birthday
88
+
89
+ # passenger0ISIC...passengerNISIC (не обязательный)
90
+ # Номер ISIC пассажира с порядковым номером 0...N.
91
+ attr_accessor :isic
92
+
93
+ # passenger0firstName... passengerNfirstName (не обязательный)
94
+ # Имя пассажира с порядковым номером 0...N.
95
+ attr_accessor :first_name
96
+
97
+ # passenger0lastName... passengerNlastName (не обязательный)
98
+ # Фамилия пассажира с порядковым номером 0...N.
99
+ attr_accessor :last_name
100
+
101
+ # passenger0middleName... passengerNmiddleName (не обязательный)
102
+ # Отчество пассажира с порядковым номером 0...N.
103
+ attr_accessor :second_name
104
+
105
+ # passenger0tariffShortName... passengerNtariffShortName (не обязательный)
106
+ # Краткое обозначение тарифа, полученное при поиске рейсов в списке тарифов, по указанным passenger0studentTicket, passenger0birthday, passenger0ISIC.
107
+ attr_accessor :tariff_short_name
108
+
109
+ # passenger0tariffCost... passengerNtariffCost (не обязательный)
110
+ # Стоимость тарифа, полученное при поиске рейсов в списке тарифов, с кратким обозначением passenger0tariffShortName с порядковым номером 0...N.
111
+ attr_accessor :tariff_cost
112
+
113
+ # passenger0documentType... passengerNdocumentType (не обязательный)
114
+ # Тип удостоверения личности (для определения типа документа, номер которого передан в параметре passport).
115
+ # Возможные значения:
116
+ # :passport 1 - паспорт
117
+ # :military_card 2 - военный билет
118
+ # :foreign_document 3 - иностранный документ
119
+ # :foreign_passport 4 - заграничный паспорт
120
+ # :seaman_passport 6 - паспорт моряка
121
+ # :birth_certificate 7 - свидетельство о рождении
122
+ # :ussr_passport 8 - паспорт формы СССР
123
+ attr_accessor :document_type
124
+
125
+ # passenger0passport... passengerNpassport (обязательный для авиаперевозки)
126
+ # Паспортные данные пассажира с порядковым номером 0...N.
127
+ attr_accessor :passport
128
+
129
+ # passenger0passportExpireDate... passengerNpassportExpireDate (обязательный для авиаперевозки)
130
+ # Дата окончания действия паспорта пассажира с порядковым номером 0...N.
131
+ attr_accessor :passport_expire_date
132
+
133
+ # passenger0citizenship... passengerNcitizenship (обязательный для авиаперевозки)
134
+ # Гражданство пассажира с порядковым номером 0...N. 2-х буквенный код страны, пример, Украина – UA.
135
+ attr_accessor :citizenship
136
+
137
+ # passenger0gender... passengerNgender (обязательный для авиаперевозки)
138
+ # Пол пассажира с порядковым номером 0...N. M – мужской, F – женский.
139
+ attr_accessor :gender
140
+
141
+ # passenger0discountValue... passengerNdiscountValue (не обязательный)
142
+ # Величина скидки в валюте продажи для пассажира с порядковым номером 0…N.
143
+ attr_accessor :discount
144
+
145
+ def params(prefix="")
146
+ compact(
147
+ birthday: date(birthday),
148
+ ISIC: isic,
149
+ firstName: first_name,
150
+ lastName: last_name,
151
+ middleName: second_name,
152
+ tariffShortName: tariff_short_name,
153
+ tariffCost: tariff_cost,
154
+ documentType: document_type_to_int(document_type),
155
+ passport: passport,
156
+ passportExpireDate: passport_expire_date,
157
+ citizenship: citizenship,
158
+ gender: gender,
159
+ discountValue: discount.to_f.to_s,
160
+ ).map {|k, v| [:"#{prefix}#{k}", v] }.to_h
161
+ end
162
+
163
+ def document_type_to_int(value)
164
+ {
165
+ passport: 1,
166
+ military_card: 2,
167
+ foreign_document: 3,
168
+ foreign_passport: 4,
169
+ seaman_passport: 6,
170
+ birth_certificate: 7,
171
+ ussr_passport: 8,
172
+ }[value.try(:to_sym)]
173
+ end
174
+ end
175
+ end
176
+
177
+ class Response < BaseResponse
178
+ field :tickets, [Ticket], key: 'TICKET'
179
+ end
180
+
181
+ end
182
+ end
@@ -0,0 +1,15 @@
1
+ class Gillbus
2
+ module UnlockSeats
3
+
4
+ Gillbus.register self, :unlock_seats
5
+
6
+ class Request < BaseRequest
7
+ def path; '/online2/unlockSeats' end
8
+ end
9
+
10
+ # TODO: is it empty?
11
+ class Response < BaseResponse
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class Gillbus
2
+ VERSION = "0.11.0"
3
+ end
data/lib/gillbus.rb ADDED
@@ -0,0 +1,86 @@
1
+ require "gillbus/version"
2
+ require "faraday"
3
+
4
+ class Gillbus
5
+
6
+ # driver: e.g. Faraday.new(url: 'http://demo.gillbus.com')
7
+ def initialize(driver:, session_id: nil)
8
+ @driver = driver
9
+ @session_id = session_id
10
+ end
11
+
12
+ # Faraday instance
13
+ attr_reader :driver
14
+ # JSESSIONID сессии API gillbus
15
+ attr_accessor :session_id
16
+
17
+ def login(password:, locale: nil)
18
+ response = session_login password: password, locale: locale
19
+ self
20
+ end
21
+
22
+ def self.register klass, method_name
23
+ define_method method_name do |*args|
24
+ request_class = klass::Request
25
+ response_class = klass::Response
26
+ request = request_class.new(*args)
27
+ headers = {'Cookie' => "JSESSIONID=#{session_id}"} if session_id
28
+ http_response = driver.post( request.path, request.params, headers )
29
+ result = response_class.parse_string(http_response.body.force_encoding('utf-8'))
30
+ if cookie_string = http_response.headers["Set-Cookie"]
31
+ returned_session_id = CGI::Cookie.parse(cookie_string)['JSESSIONID'].first
32
+ self.session_id = returned_session_id
33
+ end
34
+ result.session_id = session_id
35
+ result
36
+ end
37
+ end
38
+
39
+ require 'monetize'
40
+ require 'gillbus/helpers/fields'
41
+ require 'gillbus/helpers/update_attrs'
42
+ require 'gillbus/helpers/parser'
43
+
44
+ require 'gillbus/structs/point'
45
+ require 'gillbus/structs/tariff'
46
+ require 'gillbus/structs/segment'
47
+ require 'gillbus/structs/timetable_segment'
48
+ require 'gillbus/structs/trip'
49
+ require 'gillbus/structs/timetable_trip'
50
+
51
+ require 'gillbus/structs/commission'
52
+ require 'gillbus/structs/return_cause'
53
+ require 'gillbus/structs/ticket'
54
+
55
+ require 'gillbus/structs/seat'
56
+ require 'gillbus/structs/item'
57
+
58
+ require 'gillbus/parse_error'
59
+ require 'gillbus/base_request'
60
+ require 'gillbus/base_response'
61
+
62
+ require 'gillbus/structs/passenger_discount'
63
+
64
+ require 'gillbus/session_login'
65
+ require 'gillbus/get_countries'
66
+ require 'gillbus/get_cities'
67
+ require 'gillbus/get_all_cities'
68
+ require 'gillbus/get_time_table'
69
+ require 'gillbus/get_dates_new'
70
+ require 'gillbus/search_trips'
71
+ require 'gillbus/get_trips'
72
+ require 'gillbus/get_trip_seats'
73
+ require 'gillbus/get_required_fields'
74
+ require 'gillbus/lock_seats'
75
+ require 'gillbus/unlock_seats'
76
+ require 'gillbus/tickets_booking'
77
+ require 'gillbus/reserve_tickets'
78
+ require 'gillbus/buy_booking'
79
+ require 'gillbus/buy_tickets'
80
+ require 'gillbus/cancel_order'
81
+ require 'gillbus/get_order_ticket'
82
+ require 'gillbus/find_order'
83
+ require 'gillbus/get_order_status'
84
+ require 'gillbus/logout'
85
+
86
+ end
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus'
5
+ require 'pry'
6
+ require 'logger'
7
+ require 'securerandom'
8
+
9
+ GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
10
+ GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"
11
+
12
+ driver = Faraday.new(url: GILLBUS_SERVER) { |c|
13
+ c.response :logger, Logger.new(STDOUT), bodies: true
14
+ c.request :url_encoded
15
+ c.adapter Faraday.default_adapter
16
+ }
17
+
18
+ g = Gillbus.new(driver: driver).login(
19
+ password: GILLBUS_PASSWORD,
20
+ locale: :ru
21
+ )
22
+
23
+ # getCities
24
+
25
+ cities = g.get_cities.cities
26
+
27
+ kiiv_id = cities.find {|c| c.name == "Киев" }.id
28
+ lviv_id = cities.find {|c| c.name == "Львов" }.id
29
+
30
+
31
+ # searchTrips
32
+
33
+ tomorrow = Date.today + 1
34
+ trips = g.search_trips(
35
+ start_city_id: kiiv_id,
36
+ end_city_id: lviv_id,
37
+ start_date_search: tomorrow,
38
+ ticket_count: 2,
39
+ passengers: [
40
+ { birthday: Date.new(1983,4,19) },
41
+ { birthday: Date.new(2007,10,15) },
42
+ ]
43
+ ).trips
44
+
45
+ trip_id = trips.first.id
46
+
47
+ # lockSeats
48
+
49
+ tl = g.lock_seats(trip_id: trip_id).time_limit
50
+
51
+ # ticketsBooking
52
+ order_id = SecureRandom.uuid
53
+
54
+ puts "making order: #{order_id}"
55
+ passengers = [
56
+ { first_name: 'Иван', last_name: 'Иванов', passport: "123" },
57
+ { first_name: 'Петр', last_name: 'Петров', passport: "123" }
58
+ ]
59
+
60
+ tb = g.tickets_booking(
61
+ order_id: order_id,
62
+ mail_address: 'invanov@mail.ru',
63
+ note: 'test',
64
+ passengers: passengers
65
+ )
66
+
67
+ # relogging again
68
+
69
+ g = Gillbus.new(driver: driver).login(password: GILLBUS_PASSWORD, locale: :ru)
70
+
71
+ # buyTickets
72
+ puts "confirmation: " + g.buy_tickets(order_id: order_id).ticket.confirmation.inspect
73
+
74
+ # getOrderTicket
75
+ ot = g.get_order_ticket order_id: order_id, base64: true
76
+
77
+ filename = order_id + ".pdf"
78
+ puts "saving " + filename
79
+ File.open filename, 'wb' do |f|
80
+ f << ot.ticket
81
+ end
82
+
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus'
5
+ require 'pry'
6
+ require 'logger'
7
+ require 'securerandom'
8
+
9
+ GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
10
+ GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"
11
+
12
+ driver = Faraday.new(url: GILLBUS_SERVER) { |c|
13
+ c.response :logger, Logger.new(STDOUT), bodies: true
14
+ c.request :url_encoded
15
+ c.adapter Faraday.default_adapter
16
+ }
17
+
18
+ g = Gillbus.new(driver: driver).login(
19
+ password: GILLBUS_PASSWORD,
20
+ locale: :ru
21
+ )
22
+
23
+ # getCities
24
+
25
+ cities = g.get_cities.cities
26
+
27
+ kiiv_id = cities.find {|c| c.name == "Киев" }.id
28
+ praga_id = cities.find {|c| c.name == "Прага" }.id
29
+
30
+
31
+ # searchTrips
32
+
33
+ tomorrow = Date.today + 1
34
+ trips = g.search_trips(
35
+ start_city_id: kiiv_id,
36
+ end_city_id: praga_id,
37
+ start_date_search: tomorrow,
38
+ ticket_count: 2,
39
+ selected_modes: [ :bus, :connections ],
40
+ ],
41
+ ).trips
42
+
43
+ trip_id = trips.find { |trip| trip.segments.present? }.id
44
+
45
+ # getTripSeats
46
+
47
+ seat_map = g.get_trip_seats(trip_id: trip_id)
48
+ selected_seat_ids = seat_map.segments.map do |k, v|
49
+ [k, v.select(&:free?).sample(2).map(&:id)]
50
+ end.to_h
51
+
52
+ # lockSeats
53
+
54
+ tl = g.lock_seats(
55
+ trip_id: trip_id,
56
+ segments_seat_ids: selected_seat_ids,
57
+ ).time_limit
58
+
59
+ # ticketsBooking
60
+ order_id = SecureRandom.uuid
61
+
62
+ puts "making order: #{order_id}"
63
+ passengers = [
64
+ { first_name: 'Иван', last_name: 'Иванов', passport: "123" },
65
+ { first_name: 'Петр', last_name: 'Петров', passport: "123" }
66
+ ]
67
+
68
+ tb = g.tickets_booking(
69
+ order_id: order_id,
70
+ mail_address: 'ivan@mail.ru',
71
+ note: 'test',
72
+ passengers: passengers
73
+ )
74
+
75
+ # relogging again
76
+
77
+ g = Gillbus.new(driver: driver).login(password: GILLBUS_PASSWORD, locale: :ru)
78
+
79
+ # buyTickets
80
+ puts "confirmation: " + g.buy_tickets(order_id: order_id).ticket.confirmation.inspect
81
+
82
+ # getOrderTicket
83
+ ot = g.get_order_ticket order_id: order_id, base64: true
84
+
85
+ filename = order_id + ".pdf"
86
+ puts "saving " + filename
87
+ File.open filename, 'wb' do |f|
88
+ f << ot.ticket
89
+ end
90
+
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus'
5
+ require 'pry'
6
+ require 'logger'
7
+ require 'securerandom'
8
+
9
+ GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
10
+ GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"
11
+
12
+ driver = Faraday.new(url: GILLBUS_SERVER) { |c|
13
+ c.response :logger, Logger.new(STDOUT), bodies: true
14
+ c.request :url_encoded
15
+ c.adapter Faraday.default_adapter
16
+ }
17
+
18
+ g = Gillbus.new(driver: driver).login(
19
+ password: GILLBUS_PASSWORD,
20
+ locale: :ru
21
+ )
22
+
23
+ # getCities
24
+
25
+ cities = g.get_cities.cities
26
+
27
+ kiiv_id = cities.find {|c| c.name == "Киев" }.id
28
+ lviv_id = cities.find {|c| c.name == "Львов" }.id
29
+
30
+
31
+ # searchTrips
32
+
33
+ tomorrow = Date.today + 1
34
+ trips = g.search_trips(
35
+ start_city_id: kiiv_id,
36
+ end_city_id: lviv_id,
37
+ start_date_search: tomorrow,
38
+ ticket_count: 2
39
+ ).trips
40
+
41
+ trip_id = trips.first.id
42
+
43
+ # lockSeats
44
+
45
+ tl = g.lock_seats(trip_id: trip_id).time_limit
46
+
47
+ # ticketsBooking
48
+ order_id = SecureRandom.uuid
49
+
50
+ puts "making order: #{order_id}"
51
+ passengers = [
52
+ { first_name: 'Иван', last_name: 'Иванов' },
53
+ { first_name: 'Петр', last_name: 'Петров' }
54
+ ]
55
+
56
+ tb = g.tickets_booking(
57
+ order_id: order_id,
58
+ mail_address: 'ivan@mail.ru',
59
+ note: 'test',
60
+ passengers: passengers
61
+ )
62
+
63
+ # отмена отложенной продажи
64
+ order_number = tb.tickets.first.order_number
65
+ canceling = g.cancel_order(order_number: order_number, cancel_reason: 'no_reason')
66
+ puts "canceling: " + canceling.inspect
67
+ puts "success? " + canceling.order_cancel.confirmation.inspect
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus'
5
+ require 'pry'
6
+ require 'securerandom'
7
+
8
+ GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
9
+ GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"
10
+
11
+ require 'logger'
12
+
13
+ driver = Faraday.new(url: GILLBUS_SERVER) { |c|
14
+ c.response :logger, Logger.new(STDOUT), bodies: true
15
+ c.request :url_encoded
16
+ c.adapter Faraday.default_adapter
17
+ }
18
+
19
+ g = Gillbus.new(driver: driver).login(
20
+ password: GILLBUS_PASSWORD,
21
+ locale: :ru
22
+ )
23
+
24
+ # getCities
25
+
26
+ cities = g.get_cities.cities
27
+
28
+ kiiv_id = cities.find {|c| c.name == "Киев" }.id
29
+ odessa_id = cities.find {|c| c.name == "Львов" }.id
30
+
31
+
32
+ # searchTrips
33
+
34
+ search_date = Date.today + 7
35
+ trips = g.search_trips(
36
+ start_city_id: kiiv_id,
37
+ end_city_id: odessa_id,
38
+ start_date_search: search_date,
39
+ ticket_count: 2,
40
+ selected_modes: 1,
41
+ ).trips
42
+
43
+ trip_id = trips.find { |trip| trip.reservation_enabled == true }.id
44
+
45
+ # lockSeats
46
+
47
+ tl = g.lock_seats(trip_id: trip_id).time_limit
48
+
49
+ # ticketsBooking
50
+ order_id = SecureRandom.uuid
51
+
52
+ puts "making order: #{order_id}"
53
+ passengers = [
54
+ { first_name: 'Иван', last_name: 'Иванов' },
55
+ { first_name: 'Петр', last_name: 'Петров' }
56
+ ]
57
+
58
+ rt = g.reserve_tickets(
59
+ order_id: order_id,
60
+ mail_address: 'ivan@mail.ru',
61
+ note: 'test',
62
+ passengers: passengers
63
+ )
64
+
65
+ # отмена брони
66
+ order_number = rt.tickets.first.order_number
67
+ canceling = g.cancel_order(order_number: order_number, cancel_reason: 'no_reason')
68
+ puts "canceling: " + canceling.inspect
69
+ puts "success? " + canceling.order_cancel.confirmation.inspect
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus'
5
+ require 'pry'
6
+ require 'securerandom'
7
+
8
+ GILLBUS_SERVER = "http://mdc.demo.gillbus.com"
9
+ GILLBUS_PASSWORD = "3DVG/x1AOk+xwNlAEXytMCxZMsb73r39DOg97k8b8c4YaMrlOar071diefS0IyZT"
10
+
11
+ require 'logger'
12
+
13
+ driver = Faraday.new(url: GILLBUS_SERVER) { |c|
14
+ c.response :logger, Logger.new(STDOUT), bodies: true
15
+ c.request :url_encoded
16
+ c.adapter Faraday.default_adapter
17
+ }
18
+
19
+ g = Gillbus.new(driver: driver).login(
20
+ password: GILLBUS_PASSWORD,
21
+ locale: :ru
22
+ )
23
+
24
+ # getCities
25
+
26
+ cities = g.get_cities.cities
27
+
28
+ kiiv_id = cities.find {|c| c.name == "Киев" }.id
29
+ lviv_id = cities.find {|c| c.name == "Львов" }.id
30
+
31
+
32
+ # searchTrips
33
+
34
+ search_date = Date.today + 7
35
+ trips = g.search_trips(
36
+ start_city_id: kiiv_id,
37
+ end_city_id: lviv_id,
38
+ start_date_search: search_date,
39
+ ticket_count: 2,
40
+ selected_modes: 1,
41
+ ).trips
42
+
43
+ trip_id = trips.find { |trip| trip.reservation_enabled == true }.id
44
+
45
+ # lockSeats
46
+
47
+ tl = g.lock_seats(
48
+ trip_id: trip_id,
49
+ ).time_limit
50
+
51
+ # ticketsBooking
52
+ order_id = SecureRandom.uuid
53
+
54
+ puts "making order: #{order_id}"
55
+ passengers = [
56
+ { first_name: 'Иван', last_name: 'Иванов' },
57
+ { first_name: 'Петр', last_name: 'Петров' }
58
+ ]
59
+
60
+ rt = g.reserve_tickets(
61
+ order_id: order_id,
62
+ mail_address: 'ivan@mail.ru',
63
+ note: 'test',
64
+ passengers: passengers
65
+ )
66
+ ticket_numbers = rt.tickets.map(&:ticket_number)
67
+
68
+ # relogging again
69
+
70
+ g = Gillbus.new(driver: driver).login(password: GILLBUS_PASSWORD, locale: :ru)
71
+
72
+ # buyBooking
73
+ response = g.buy_booking(
74
+ ticket_count: 2,
75
+ ticket_numbers: ticket_numbers,
76
+ order_ids: [order_id, order_id]
77
+ )
78
+ p "confirmation: " + response.ticket.confirmation.inspect
79
+ p "ticket_numbers: " + response.ticket.position_numbers.inspect
80
+
81
+ # getOrderTicket
82
+ ot = g.get_order_ticket order_id: order_id, base64: true
83
+
84
+ filename = order_id + ".pdf"
85
+ puts "saving " + filename
86
+ File.open filename, 'wb' do |f|
87
+ f << ot.ticket
88
+ end