gillbus 0.16.7 → 0.16.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +88 -0
- data/Rakefile +3 -3
- data/gillbus.gemspec +16 -15
- data/lib/gillbus.rb +10 -9
- data/lib/gillbus/base_request.rb +17 -19
- data/lib/gillbus/base_response.rb +11 -13
- data/lib/gillbus/buy_booking.rb +1 -9
- data/lib/gillbus/buy_tickets.rb +1 -8
- data/lib/gillbus/cancel_order.rb +0 -10
- data/lib/gillbus/drivers/faraday_response_file_logger.rb +1 -3
- data/lib/gillbus/find_order.rb +0 -5
- data/lib/gillbus/get_all_cities.rb +0 -2
- data/lib/gillbus/get_bus_image.rb +0 -3
- data/lib/gillbus/get_cities.rb +0 -4
- data/lib/gillbus/get_countries.rb +0 -4
- data/lib/gillbus/get_dates_new.rb +0 -4
- data/lib/gillbus/get_order_status.rb +1 -6
- data/lib/gillbus/get_order_ticket.rb +4 -7
- data/lib/gillbus/get_time_table.rb +0 -4
- data/lib/gillbus/get_trip_seats.rb +8 -11
- data/lib/gillbus/get_trip_segments.rb +0 -2
- data/lib/gillbus/get_trips.rb +0 -2
- data/lib/gillbus/helpers/fields.rb +5 -7
- data/lib/gillbus/helpers/parser.rb +10 -13
- data/lib/gillbus/helpers/update_attrs.rb +2 -4
- data/lib/gillbus/lock_seats.rb +7 -10
- data/lib/gillbus/logout.rb +0 -6
- data/lib/gillbus/parse_error.rb +3 -1
- data/lib/gillbus/reserve_tickets.rb +0 -2
- data/lib/gillbus/return_position.rb +0 -1
- data/lib/gillbus/search_trips.rb +5 -6
- data/lib/gillbus/session_login.rb +0 -6
- data/lib/gillbus/structs/commission.rb +4 -4
- data/lib/gillbus/structs/item.rb +0 -2
- data/lib/gillbus/structs/passenger_discount.rb +2 -3
- data/lib/gillbus/structs/point.rb +0 -1
- data/lib/gillbus/structs/return_cause.rb +0 -2
- data/lib/gillbus/structs/seat.rb +0 -2
- data/lib/gillbus/structs/segment.rb +5 -6
- data/lib/gillbus/structs/tariff.rb +1 -2
- data/lib/gillbus/structs/tariff/return_cause.rb +3 -3
- data/lib/gillbus/structs/ticket.rb +0 -2
- data/lib/gillbus/structs/timetable_trip.rb +4 -4
- data/lib/gillbus/structs/trip.rb +5 -6
- data/lib/gillbus/structs/trip_options.rb +0 -1
- data/lib/gillbus/structs/trip_service.rb +0 -2
- data/lib/gillbus/tickets_booking.rb +17 -13
- data/lib/gillbus/unlock_seats.rb +0 -2
- data/lib/gillbus/version.rb +1 -1
- data/script/example_booking.rb +16 -18
- data/script/example_booking_with_segments.rb +0 -1
- data/script/example_canceling_booking.rb +12 -13
- data/script/example_canceling_reservation.rb +11 -12
- data/script/example_reservation.rb +14 -15
- data/test/all_commissions_test.rb +1 -2
- data/test/buy_booking_test.rb +14 -13
- data/test/buy_tickets_test.rb +1 -2
- data/test/cancel_order_test.rb +1 -2
- data/test/error_test.rb +1 -3
- data/test/find_order_test.rb +3 -4
- data/test/get_bus_image_test.rb +0 -1
- data/test/get_cities_test.rb +1 -2
- data/test/get_countries_test.rb +1 -2
- data/test/get_dates_new_test.rb +0 -1
- data/test/get_order_ticket_test.rb +1 -2
- data/test/get_time_table_test.rb +0 -1
- data/test/get_trip_seats_test.rb +3 -4
- data/test/get_trip_segments_test.rb +5 -6
- data/test/lock_seats_test.rb +43 -33
- data/test/reserve_tickets_test.rb +10 -3
- data/test/return_position_test.rb +8 -5
- data/test/search_trips_test.rb +15 -19
- data/test/session_login_test.rb +0 -1
- data/test/tickets_booking_test.rb +2 -3
- metadata +24 -9
@@ -1,15 +1,13 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module UpdateAttrs
|
3
|
-
|
4
|
-
def initialize(attrs={})
|
3
|
+
def initialize(attrs = {})
|
5
4
|
update_attrs attrs if attrs
|
6
5
|
end
|
7
6
|
|
8
|
-
def update_attrs(attrs={})
|
7
|
+
def update_attrs(attrs = {})
|
9
8
|
attrs.each do |k, v|
|
10
9
|
public_send "#{k}=", v
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
end
|
data/lib/gillbus/lock_seats.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module LockSeats
|
3
|
-
|
4
3
|
Gillbus.register self, :lock_seats
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/lockSeats' end
|
9
7
|
|
10
8
|
# tripId
|
@@ -12,11 +10,13 @@ class Gillbus
|
|
12
10
|
attr_accessor :trip_id
|
13
11
|
|
14
12
|
# carriageId (не обязательный)
|
15
|
-
# ИД вагона, для которого нужно получить карту мест.
|
13
|
+
# ИД вагона, для которого нужно получить карту мест.
|
14
|
+
# По- умолчанию первый попавшийся. Только для железнодорожных рейсов.
|
16
15
|
attr_accessor :carriage_id
|
17
16
|
|
18
17
|
# backCarriageId (не обязательный)
|
19
|
-
# ИД вагона обратного рейса, для которого нужно получить карту мест.
|
18
|
+
# ИД вагона обратного рейса, для которого нужно получить карту мест.
|
19
|
+
# По-умолчанию первый попавшийся. Только для железнодорожных рейсов.
|
20
20
|
attr_accessor :back_carriage_id
|
21
21
|
|
22
22
|
# segment0carriageId...segmentNcarriageId (не обязательный)
|
@@ -36,10 +36,10 @@ class Gillbus
|
|
36
36
|
attr_accessor :segments_seat_ids
|
37
37
|
|
38
38
|
def params
|
39
|
-
seats = Array(seat_ids).map.with_index {|id, n| [:"seatId#{n}", id] }.to_h
|
40
|
-
back_seats = Array(back_seat_ids).map.with_index {|id, n| [:"backSeatId#{n}", id] }.to_h
|
39
|
+
seats = Array(seat_ids).map.with_index { |id, n| [:"seatId#{n}", id] }.to_h
|
40
|
+
back_seats = Array(back_seat_ids).map.with_index { |id, n| [:"backSeatId#{n}", id] }.to_h
|
41
41
|
segments_seats = Hash(segments_seat_ids).map do |segment, seat_ids|
|
42
|
-
Array(seat_ids).map.with_index {|id, n| [:"segment#{segment}seatId#{n}", id] }.to_h
|
42
|
+
Array(seat_ids).map.with_index { |id, n| [:"segment#{segment}seatId#{n}", id] }.to_h
|
43
43
|
end.reduce(&:merge).to_h
|
44
44
|
|
45
45
|
compact(
|
@@ -54,7 +54,6 @@ class Gillbus
|
|
54
54
|
end
|
55
55
|
|
56
56
|
class Response < BaseResponse
|
57
|
-
|
58
57
|
# seat lock, time limit, in seconds
|
59
58
|
field :time_limit, :milliseconds
|
60
59
|
# [{Symbol => Boolean}] необходимые для ввода типы документов?
|
@@ -75,8 +74,6 @@ class Gillbus
|
|
75
74
|
result
|
76
75
|
end
|
77
76
|
end
|
78
|
-
|
79
77
|
end
|
80
|
-
|
81
78
|
end
|
82
79
|
end
|
data/lib/gillbus/logout.rb
CHANGED
data/lib/gillbus/parse_error.rb
CHANGED
data/lib/gillbus/search_trips.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module SearchTrips
|
3
|
-
|
4
3
|
Gillbus.register self, :search_trips
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/searchTrips' end
|
9
7
|
|
10
8
|
# selectedModes (не обязательный)
|
@@ -13,11 +11,14 @@ class Gillbus
|
|
13
11
|
attr_accessor :selected_modes
|
14
12
|
|
15
13
|
# connectionIds (не обязательный)
|
16
|
-
# Список предполагаемых идентификаторов пересадочных пунктов, разделенных “;”.
|
14
|
+
# Список предполагаемых идентификаторов пересадочных пунктов, разделенных “;”.
|
15
|
+
# Используется если выбран вид транспорта 8, 9.
|
17
16
|
attr_accessor :connection_ids
|
18
17
|
|
19
18
|
# tripFullSale (не обязательный)
|
20
|
-
# Признак определяющий количество возвращаемых рейсов.
|
19
|
+
# Признак определяющий количество возвращаемых рейсов.
|
20
|
+
# Если true, то возвращаются заказные и регулярные рейсы.
|
21
|
+
# Если false, то возвращаются только регулярные рейсы.
|
21
22
|
attr_accessor :trip_full_sale
|
22
23
|
|
23
24
|
# fullSearch (не обязательный)
|
@@ -123,13 +124,11 @@ class Gillbus
|
|
123
124
|
PassengerDiscount.wrap(p).params("passenger#{i}")
|
124
125
|
end.reduce({}, :merge)
|
125
126
|
end
|
126
|
-
|
127
127
|
end
|
128
128
|
|
129
129
|
class Response < BaseResponse
|
130
130
|
field :completed, :bool
|
131
131
|
field :trips, [Trip], key: 'TRIP'
|
132
132
|
end
|
133
|
-
|
134
133
|
end
|
135
134
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module SessionLogin
|
3
|
-
|
4
3
|
Gillbus.register self, :session_login
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def initialize(password:, locale: nil)
|
9
7
|
super
|
10
8
|
end
|
@@ -19,14 +17,10 @@ class Gillbus
|
|
19
17
|
def params
|
20
18
|
compact(locale: translated_locale(locale))
|
21
19
|
end
|
22
|
-
|
23
20
|
end
|
24
21
|
|
25
22
|
class Response < BaseResponse
|
26
|
-
|
27
23
|
field :logged, :bool
|
28
|
-
|
29
24
|
end
|
30
|
-
|
31
25
|
end
|
32
26
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# FIXME it's possible I got currency for some fields wrong.
|
1
|
+
# FIXME: it's possible I got currency for some fields wrong.
|
2
2
|
class Gillbus
|
3
3
|
class Commission
|
4
|
-
|
5
4
|
extend Fields
|
6
5
|
include UpdateAttrs
|
7
6
|
|
@@ -14,7 +13,9 @@ class Gillbus
|
|
14
13
|
# Collecting description
|
15
14
|
field :description
|
16
15
|
|
17
|
-
# type of commission according to tariff
|
16
|
+
# type of commission according to tariff
|
17
|
+
# (1 - inside tariff, 2 - outside of tariff, 3 - inside of tariff type II)
|
18
|
+
# NB: only in ALL_COMMISSIONS
|
18
19
|
field :in_out_type
|
19
20
|
|
20
21
|
# Value of collecting in sale currency
|
@@ -59,6 +60,5 @@ class Gillbus
|
|
59
60
|
Monetize.parse(val, doc['CURRENCY'])
|
60
61
|
end
|
61
62
|
end
|
62
|
-
|
63
63
|
end
|
64
64
|
end
|
data/lib/gillbus/structs/item.rb
CHANGED
@@ -2,7 +2,6 @@ class Gillbus
|
|
2
2
|
# not a request, neither a response part
|
3
3
|
# just a params record for SearchTrips
|
4
4
|
class PassengerDiscount < BaseRequest
|
5
|
-
|
6
5
|
def self.wrap(passenger_or_params)
|
7
6
|
return passenger_or_params if passenger_or_params.is_a? self
|
8
7
|
new(passenger_or_params)
|
@@ -31,14 +30,14 @@ class Gillbus
|
|
31
30
|
# с предоставлением места, если такой имеется.
|
32
31
|
attr_accessor :with_seat
|
33
32
|
|
34
|
-
def params(prefix=
|
33
|
+
def params(prefix = '')
|
35
34
|
compact(
|
36
35
|
birthday: date(birthday),
|
37
36
|
studentTicket: student_ticket,
|
38
37
|
studentYear: student_year,
|
39
38
|
ISIC: isic,
|
40
39
|
withSeat: bool(with_seat),
|
41
|
-
).map {|k, v| [:"#{prefix}#{k}", v] }.to_h
|
40
|
+
).map { |k, v| [:"#{prefix}#{k}", v] }.to_h
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
data/lib/gillbus/structs/seat.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class Gillbus
|
2
2
|
class Segment
|
3
|
-
|
4
3
|
extend Fields
|
5
4
|
include UpdateAttrs
|
6
5
|
|
@@ -137,11 +136,11 @@ class Gillbus
|
|
137
136
|
# => "643"
|
138
137
|
field :currency_code
|
139
138
|
|
140
|
-
field :tariffs, [:tariff], key:
|
139
|
+
field :tariffs, [:tariff], key: 'TARIFF'
|
141
140
|
|
142
|
-
field :points, [Point], key:
|
141
|
+
field :points, [Point], key: 'POINT'
|
143
142
|
|
144
|
-
field :segments, [Segment], key:
|
143
|
+
field :segments, [Segment], key: 'SEGMENT'
|
145
144
|
|
146
145
|
field :options, TripOptions, key: 'OPTIONS'
|
147
146
|
|
@@ -164,11 +163,11 @@ class Gillbus
|
|
164
163
|
# to hold unserialized data
|
165
164
|
attr_accessor :data
|
166
165
|
|
167
|
-
|
166
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
167
|
+
def self.parse(doc, instance: nil, parent: nil, options: {})
|
168
168
|
instance = super
|
169
169
|
instance.data = doc
|
170
170
|
instance
|
171
171
|
end
|
172
|
-
|
173
172
|
end
|
174
173
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class Gillbus
|
2
2
|
class Tariff
|
3
|
-
|
4
3
|
extend Fields
|
5
4
|
include UpdateAttrs
|
6
5
|
|
@@ -58,7 +57,7 @@ class Gillbus
|
|
58
57
|
|
59
58
|
def string_with_possible_attributes(val)
|
60
59
|
[val].flatten.map do |value|
|
61
|
-
if value.
|
60
|
+
if value.is_a? Hash
|
62
61
|
value['__content__']
|
63
62
|
else
|
64
63
|
value
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Gillbus
|
2
2
|
class Tariff
|
3
3
|
class ReturnCause
|
4
|
-
|
5
4
|
extend Fields
|
6
5
|
include UpdateAttrs
|
7
6
|
|
@@ -9,9 +8,10 @@ class Gillbus
|
|
9
8
|
|
10
9
|
field :cause, :string
|
11
10
|
|
12
|
-
|
11
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
12
|
+
def self.parse(doc, instance: nil, parent: nil, options: {})
|
13
13
|
instance = super
|
14
|
-
if doc.
|
14
|
+
if doc.is_a? Hash
|
15
15
|
instance.cause = doc['__content__']
|
16
16
|
instance.lossless = doc['lossless'] == 'true'
|
17
17
|
else
|
@@ -42,11 +42,11 @@ class Gillbus
|
|
42
42
|
# => "1"
|
43
43
|
field :trip_mode, :int
|
44
44
|
|
45
|
-
field :segments, [TimetableSegment], key:
|
45
|
+
field :segments, [TimetableSegment], key: 'SEGMENT'
|
46
46
|
|
47
|
-
field :days_of_week, :days_of_week, key:
|
47
|
+
field :days_of_week, :days_of_week, key: 'DAY_OR_DATE'
|
48
48
|
|
49
|
-
field :dates, :dates, key:
|
49
|
+
field :dates, :dates, key: 'DAY_OR_DATE'
|
50
50
|
|
51
51
|
parser do
|
52
52
|
DAYS_INTO_WEEK = {
|
@@ -57,7 +57,7 @@ class Gillbus
|
|
57
57
|
5 => :thursday,
|
58
58
|
6 => :friday,
|
59
59
|
7 => :saturday,
|
60
|
-
}
|
60
|
+
}.freeze
|
61
61
|
|
62
62
|
def days_of_week(value)
|
63
63
|
return unless instance.frequency == 3
|
data/lib/gillbus/structs/trip.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class Gillbus
|
2
2
|
class Trip
|
3
|
-
|
4
3
|
extend Fields
|
5
4
|
include UpdateAttrs
|
6
5
|
|
@@ -151,11 +150,11 @@ class Gillbus
|
|
151
150
|
# => "643"
|
152
151
|
field :currency_code
|
153
152
|
|
154
|
-
field :tariffs, [:tariff], key:
|
153
|
+
field :tariffs, [:tariff], key: 'TARIFF'
|
155
154
|
|
156
|
-
field :points, [Point], key:
|
155
|
+
field :points, [Point], key: 'POINT'
|
157
156
|
|
158
|
-
field :segments, [Segment], key:
|
157
|
+
field :segments, [Segment], key: 'SEGMENT'
|
159
158
|
|
160
159
|
field :options, TripOptions, key: 'OPTIONS'
|
161
160
|
|
@@ -178,11 +177,11 @@ class Gillbus
|
|
178
177
|
# to hold unserialized data
|
179
178
|
attr_accessor :data
|
180
179
|
|
181
|
-
|
180
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
181
|
+
def self.parse(doc, instance: nil, parent: nil, options: {})
|
182
182
|
instance = super
|
183
183
|
instance.data = doc
|
184
184
|
instance
|
185
185
|
end
|
186
|
-
|
187
186
|
end
|
188
187
|
end
|