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,6 +1,5 @@
|
|
1
1
|
class Gillbus
|
2
2
|
class FaradayResponseFileLogger < Faraday::Middleware
|
3
|
-
|
4
3
|
def initialize(app, dir = '.')
|
5
4
|
@dir = dir
|
6
5
|
super(app)
|
@@ -8,12 +7,11 @@ class Gillbus
|
|
8
7
|
|
9
8
|
def call(env)
|
10
9
|
path = env.url.path
|
11
|
-
@app.call(env).on_complete do |
|
10
|
+
@app.call(env).on_complete do |_environment|
|
12
11
|
sanitized_path = path.gsub(/[^A-Za-z0-9_-]+/, '_').gsub(/^_|_$/, '')
|
13
12
|
sanitized_path = '_' if sanitized_path == ''
|
14
13
|
File.write(@dir + '/' + sanitized_path, env.body) if env.body != ''
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
data/lib/gillbus/find_order.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module FindOrder
|
3
|
-
|
4
3
|
Gillbus.register self, :find_order
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/findOrder' end
|
9
7
|
|
10
8
|
# orderId
|
@@ -25,13 +23,10 @@ class Gillbus
|
|
25
23
|
locale: translated_locale(locale),
|
26
24
|
)
|
27
25
|
end
|
28
|
-
|
29
26
|
end
|
30
27
|
|
31
28
|
class Response < BaseResponse
|
32
29
|
field :tickets, [Ticket], key: 'TICKET'
|
33
30
|
end
|
34
|
-
|
35
31
|
end
|
36
|
-
|
37
32
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetBusImage
|
3
|
-
|
4
3
|
Gillbus.register self, :get_bus_image
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getBusImage' end
|
9
7
|
|
10
8
|
# busId
|
@@ -16,7 +14,6 @@ class Gillbus
|
|
16
14
|
busId: bus_id,
|
17
15
|
)
|
18
16
|
end
|
19
|
-
|
20
17
|
end
|
21
18
|
|
22
19
|
class Image
|
data/lib/gillbus/get_cities.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetCities
|
3
|
-
|
4
3
|
Gillbus.register self, :get_cities
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getCities' end
|
9
7
|
|
10
8
|
attr_accessor :start_city_id
|
@@ -14,7 +12,6 @@ class Gillbus
|
|
14
12
|
startCityId: start_city_id,
|
15
13
|
}
|
16
14
|
end
|
17
|
-
|
18
15
|
end
|
19
16
|
|
20
17
|
class City
|
@@ -29,6 +26,5 @@ class Gillbus
|
|
29
26
|
class Response < BaseResponse
|
30
27
|
field :cities, [City], key: 'CITY'
|
31
28
|
end
|
32
|
-
|
33
29
|
end
|
34
30
|
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetCountries
|
3
|
-
|
4
3
|
Gillbus.register self, :get_countries
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getCountries' end
|
9
|
-
|
10
7
|
end
|
11
8
|
|
12
9
|
class Country
|
@@ -19,6 +16,5 @@ class Gillbus
|
|
19
16
|
class Response < BaseResponse
|
20
17
|
field :countries, [Country], key: 'COUNTRY'
|
21
18
|
end
|
22
|
-
|
23
19
|
end
|
24
20
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetDatesNew
|
3
|
-
|
4
3
|
Gillbus.register self, :get_dates_new
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getDatesNew' end
|
9
7
|
|
10
8
|
attr_accessor :start_city_id
|
@@ -24,12 +22,10 @@ class Gillbus
|
|
24
22
|
selectedModes: modes(selected_modes),
|
25
23
|
)
|
26
24
|
end
|
27
|
-
|
28
25
|
end
|
29
26
|
|
30
27
|
class Response < BaseResponse
|
31
28
|
field :items, [Item], key: 'ITEM'
|
32
29
|
end
|
33
|
-
|
34
30
|
end
|
35
31
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetOrderStatus
|
3
|
-
|
4
3
|
Gillbus.register self, :get_order_status
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getOrderStatus' end
|
9
7
|
|
10
8
|
# orderNumber
|
@@ -13,16 +11,13 @@ class Gillbus
|
|
13
11
|
|
14
12
|
def params
|
15
13
|
compact(
|
16
|
-
orderNumber: order_number.is_a?(Array) ? order_number.join(
|
14
|
+
orderNumber: order_number.is_a?(Array) ? order_number.join(';') : order_number,
|
17
15
|
)
|
18
16
|
end
|
19
|
-
|
20
17
|
end
|
21
18
|
|
22
19
|
class Response < BaseResponse
|
23
20
|
field :tickets, [Ticket], key: 'TICKET'
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
|
-
|
28
23
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'base64'
|
2
2
|
class Gillbus
|
3
3
|
module GetOrderTicket
|
4
|
-
|
5
4
|
Gillbus.register self, :get_order_ticket
|
6
5
|
|
7
6
|
class Request < BaseRequest
|
8
|
-
|
9
7
|
def path; '/online2/getOrderTicket' end
|
10
8
|
|
11
9
|
# orderId
|
@@ -22,7 +20,9 @@ class Gillbus
|
|
22
20
|
attr_accessor :order_number
|
23
21
|
|
24
22
|
# base64 (не обязательный)
|
25
|
-
# Признак получения билета заказа в виде строки Base64.
|
23
|
+
# Признак получения билета заказа в виде строки Base64.
|
24
|
+
# true – билет заказа будет возвращен как строка Base64.
|
25
|
+
# По умолчанию false.
|
26
26
|
# Важно: надо передать true, парсер ответа ожидает этого.
|
27
27
|
# Иначе можно получить невалидный xml
|
28
28
|
attr_accessor :base64
|
@@ -41,13 +41,12 @@ class Gillbus
|
|
41
41
|
orderNumber: order_number,
|
42
42
|
base64: base64,
|
43
43
|
as: as,
|
44
|
-
locale: translated_locale(locale)
|
44
|
+
locale: translated_locale(locale),
|
45
45
|
)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
class Response < BaseResponse
|
50
|
-
|
51
50
|
field :ticket, :ticket
|
52
51
|
|
53
52
|
parser do
|
@@ -55,8 +54,6 @@ class Gillbus
|
|
55
54
|
Base64.decode64(val)
|
56
55
|
end
|
57
56
|
end
|
58
|
-
|
59
57
|
end
|
60
|
-
|
61
58
|
end
|
62
59
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetTimeTable
|
3
|
-
|
4
3
|
Gillbus.register self, :get_time_table
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getTimeTable' end
|
9
7
|
|
10
8
|
attr_accessor :locale
|
@@ -22,12 +20,10 @@ class Gillbus
|
|
22
20
|
endDateSearch: date(end_date_search),
|
23
21
|
)
|
24
22
|
end
|
25
|
-
|
26
23
|
end
|
27
24
|
|
28
25
|
class Response < BaseResponse
|
29
26
|
field :trips, [TimetableTrip], key: 'TRIP'
|
30
27
|
end
|
31
|
-
|
32
28
|
end
|
33
29
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
class Gillbus
|
2
2
|
module GetTripSeats
|
3
|
-
|
4
3
|
Gillbus.register self, :get_trip_seats
|
5
4
|
|
6
5
|
class Request < BaseRequest
|
7
|
-
|
8
6
|
def path; '/online2/getTripSeats' end
|
9
7
|
|
10
8
|
# tripId
|
@@ -12,11 +10,15 @@ class Gillbus
|
|
12
10
|
attr_accessor :trip_id
|
13
11
|
|
14
12
|
# carriageId (не обязательный)
|
15
|
-
# ИД вагона, для которого нужно получить карту мест.
|
13
|
+
# ИД вагона, для которого нужно получить карту мест.
|
14
|
+
# По- умолчанию первый попавшийся.
|
15
|
+
# Только для железнодорожных рейсов.
|
16
16
|
attr_accessor :carriage_id
|
17
17
|
|
18
18
|
# backCarriageId (не обязательный)
|
19
|
-
# ИД вагона обратного рейса, для которого нужно получить карту мест.
|
19
|
+
# ИД вагона обратного рейса, для которого нужно получить карту мест.
|
20
|
+
# По-умолчанию первый попавшийся.
|
21
|
+
# Только для железнодорожных рейсов.
|
20
22
|
attr_accessor :back_carriage_id
|
21
23
|
|
22
24
|
# segment0carriageId...segmentNcarriageId (не обязательный)
|
@@ -27,14 +29,12 @@ class Gillbus
|
|
27
29
|
compact(
|
28
30
|
tripId: trip_id,
|
29
31
|
carriageId: carriage_id,
|
30
|
-
backCarriageId: back_carriage_id
|
32
|
+
backCarriageId: back_carriage_id,
|
31
33
|
)
|
32
34
|
end
|
33
|
-
|
34
35
|
end
|
35
36
|
|
36
37
|
class Response < BaseResponse
|
37
|
-
|
38
38
|
SEGMENT_REGEX = /SEGMENT_(?<number>\d+)_SEAT/
|
39
39
|
|
40
40
|
field :seats, [Seat], key: 'SEAT'
|
@@ -47,15 +47,12 @@ class Gillbus
|
|
47
47
|
|
48
48
|
max_segment_number = val.keys.max.match(SEGMENT_REGEX)[:number].to_i
|
49
49
|
|
50
|
-
[*0..max_segment_number].
|
50
|
+
[*0..max_segment_number].each_with_object({}) do |segment, hash|
|
51
51
|
seats = val["SEGMENT_#{segment}_SEAT"].to_a
|
52
52
|
hash[segment] = seats.map { |seat| Seat.parse(seat) }.presence || []
|
53
|
-
hash
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
59
|
-
|
60
57
|
end
|
61
58
|
end
|
@@ -3,7 +3,6 @@ class Gillbus
|
|
3
3
|
# Возвращает список остановочных пунктов следования рейса
|
4
4
|
# Если список остановочных пунктов отсутствует, то ресурс не предоставляет возможности получения маршрута следования.
|
5
5
|
module GetTripSegments
|
6
|
-
|
7
6
|
Gillbus.register self, :get_trip_segments
|
8
7
|
|
9
8
|
class Request < BaseRequest
|
@@ -21,6 +20,5 @@ class Gillbus
|
|
21
20
|
class Response < BaseResponse
|
22
21
|
field :points, [Point], key: 'POINT'
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
end
|
data/lib/gillbus/get_trips.rb
CHANGED
@@ -13,7 +13,6 @@ class Gillbus
|
|
13
13
|
#
|
14
14
|
# MyClass.parse(hash)
|
15
15
|
module Fields
|
16
|
-
|
17
16
|
def parser_class
|
18
17
|
if defined? @parser_class
|
19
18
|
@parser_class || Gillbus::Parser
|
@@ -22,13 +21,14 @@ class Gillbus
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
def parse(doc, instance
|
24
|
+
def parse(doc, instance: new, parent: nil, options: {})
|
26
25
|
instance ||= new
|
27
26
|
parser_class.new(
|
28
27
|
doc: doc,
|
29
28
|
instance: instance,
|
30
29
|
fields: field_definitions,
|
31
|
-
parent: parent
|
30
|
+
parent: parent,
|
31
|
+
options: options,
|
32
32
|
).parse
|
33
33
|
instance
|
34
34
|
end
|
@@ -43,11 +43,9 @@ class Gillbus
|
|
43
43
|
@fields ||= []
|
44
44
|
end
|
45
45
|
|
46
|
-
def field(name, type
|
47
|
-
field_definitions << {name: name, key: key, type: type, root: root}
|
46
|
+
def field(name, type = :string, key: name.to_s.upcase, root: nil)
|
47
|
+
field_definitions << { name: name, key: key, type: type, root: root }
|
48
48
|
attr_accessor name
|
49
49
|
end
|
50
|
-
|
51
|
-
|
52
50
|
end
|
53
51
|
end
|
@@ -3,17 +3,17 @@ require 'active_support/time'
|
|
3
3
|
|
4
4
|
class Gillbus
|
5
5
|
class Parser
|
6
|
-
|
7
6
|
attr_accessor :doc
|
8
7
|
attr_accessor :instance
|
9
8
|
attr_accessor :fields
|
10
9
|
attr_accessor :parent
|
11
10
|
|
12
|
-
def initialize(instance:, doc:, fields:, parent:)
|
11
|
+
def initialize(instance:, doc:, fields:, parent:, options: {})
|
13
12
|
@instance = instance
|
14
13
|
@doc = doc
|
15
14
|
@fields = fields
|
16
15
|
@parent = parent
|
16
|
+
@options = options
|
17
17
|
end
|
18
18
|
|
19
19
|
def parse
|
@@ -32,12 +32,12 @@ class Gillbus
|
|
32
32
|
instance
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
private
|
36
36
|
|
37
37
|
def make_one_or_many(type, val)
|
38
38
|
# [:type]
|
39
39
|
if type.is_a? Array
|
40
|
-
array(val).map {|v| make_one type.first, v }
|
40
|
+
array(val).map { |v| make_one type.first, v }
|
41
41
|
# :type
|
42
42
|
else
|
43
43
|
make_one type, val
|
@@ -47,14 +47,12 @@ class Gillbus
|
|
47
47
|
def make_one(type, val)
|
48
48
|
return if val.nil?
|
49
49
|
if type.is_a? Class
|
50
|
-
type.parse(val, nil, instance)
|
50
|
+
type.parse(val, instance: nil, parent: instance, options: @options)
|
51
51
|
else
|
52
52
|
send type, val
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
private
|
57
|
-
|
58
56
|
# nil => []
|
59
57
|
# [] => []
|
60
58
|
# {} => [{}]
|
@@ -64,12 +62,12 @@ class Gillbus
|
|
64
62
|
end
|
65
63
|
|
66
64
|
def string(val)
|
67
|
-
return if val ==
|
65
|
+
return if val == 'null'
|
68
66
|
val
|
69
67
|
end
|
70
68
|
|
71
69
|
def bool(val)
|
72
|
-
val ==
|
70
|
+
val == 'true'
|
73
71
|
end
|
74
72
|
|
75
73
|
def yesno_bool(val)
|
@@ -84,21 +82,20 @@ class Gillbus
|
|
84
82
|
Date.strptime(val, '%d.%m.%Y')
|
85
83
|
end
|
86
84
|
|
85
|
+
# rubocop:disable Style/GuardClause, Style/IfUnlessModifier
|
87
86
|
def time(val)
|
88
87
|
if val =~ /^ ( \d\d:\d\d ) (?: :\d\d )? $/x
|
89
88
|
$1
|
90
|
-
else
|
91
|
-
nil
|
92
89
|
end
|
93
90
|
end
|
94
91
|
|
95
92
|
def datetime(val)
|
96
|
-
|
93
|
+
tz = @options[:timezone] || 'Europe/Kiev'
|
94
|
+
ActiveSupport::TimeZone[tz].parse(val)
|
97
95
|
end
|
98
96
|
|
99
97
|
def decimal(val)
|
100
98
|
BigDecimal.new(val)
|
101
99
|
end
|
102
|
-
|
103
100
|
end
|
104
101
|
end
|