gillbus 0.17.3 → 0.17.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gillbus/helpers/parser.rb +27 -9
- data/lib/gillbus/structs/segment.rb +3 -5
- data/lib/gillbus/structs/ticket.rb +4 -0
- data/lib/gillbus/structs/trip.rb +3 -5
- data/lib/gillbus/version.rb +1 -1
- data/test/reserve_tickets_test.rb +35 -6
- data/test/responses/reserveTickets.xml +2 -1
- data/test/responses/searchTrips-segments.xml +2 -0
- data/test/search_trips_test.rb +37 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 140d94b1fc16018b2810e3abc6a1fd9bc5bf7393
|
4
|
+
data.tar.gz: b9a87718c0a4e543115763efebb8daf51acbe8aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271db72a1c6aa69dd9954e6b7d2b64bbdfddc9c8e98bd1f9e3c4efc75e0d07cb872d4bd0e5f716e8f4aee0b5feee1f0ac93329343c2050e594217c9667d43977
|
7
|
+
data.tar.gz: 9488294ff67f001ab47e310ce363409d826850f9d02776a0df332921693696e18d5d1cc75cfd1d778c2a07cbe5f4edc594bac07012690ab73ed66ca12d25697d
|
@@ -18,15 +18,13 @@ class Gillbus
|
|
18
18
|
|
19
19
|
def parse
|
20
20
|
fields.each do |name:, key:, type:, root:|
|
21
|
-
|
22
|
-
if
|
23
|
-
|
24
|
-
elsif root
|
25
|
-
doc[root] && doc[root][key]
|
21
|
+
value =
|
22
|
+
if type == :datetime_combined
|
23
|
+
datetime_combined(key)
|
26
24
|
else
|
27
|
-
|
25
|
+
raw_value = fetch_value(key: key, root: root)
|
26
|
+
make_one_or_many(type, raw_value)
|
28
27
|
end
|
29
|
-
value = make_one_or_many(type, raw_value)
|
30
28
|
instance.send "#{name}=", value unless value.nil?
|
31
29
|
end
|
32
30
|
instance
|
@@ -34,6 +32,16 @@ class Gillbus
|
|
34
32
|
|
35
33
|
private
|
36
34
|
|
35
|
+
def fetch_value(key:, root:)
|
36
|
+
if key.is_a?(Regexp)
|
37
|
+
doc.select { |k| k =~ key }
|
38
|
+
elsif root
|
39
|
+
doc[root] && doc[root][key]
|
40
|
+
else
|
41
|
+
doc[key]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
def make_one_or_many(type, val)
|
38
46
|
# [:type]
|
39
47
|
if type.is_a? Array
|
@@ -90,8 +98,18 @@ class Gillbus
|
|
90
98
|
end
|
91
99
|
|
92
100
|
def datetime(val)
|
93
|
-
|
94
|
-
|
101
|
+
ActiveSupport::TimeZone[default_timezone].parse(val)
|
102
|
+
end
|
103
|
+
|
104
|
+
def datetime_combined(key)
|
105
|
+
date_string = doc["#{key}_DATE"]
|
106
|
+
time_string = doc["#{key}_TIME"]
|
107
|
+
timezone = doc["#{key}_TIMEZONE"].presence || default_timezone
|
108
|
+
ActiveSupport::TimeZone[timezone].parse("#{date_string} #{time_string}")
|
109
|
+
end
|
110
|
+
|
111
|
+
def default_timezone
|
112
|
+
@options[:timezone] || 'Europe/Kiev'
|
95
113
|
end
|
96
114
|
|
97
115
|
def decimal(val)
|
@@ -146,11 +146,9 @@ class Gillbus
|
|
146
146
|
|
147
147
|
field :bus_photos, [BusPhoto], key: 'BUS_PHOTO'
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
ActiveSupport::TimeZone[timezone].parse(datetime_string)
|
153
|
-
end
|
149
|
+
field :start_at, :datetime_combined, key: 'START'
|
150
|
+
|
151
|
+
field :end_at, :datetime_combined, key: 'END'
|
154
152
|
|
155
153
|
parser do
|
156
154
|
def money(val)
|
@@ -264,6 +264,10 @@ class Gillbus
|
|
264
264
|
# Ticket type: i.e. bus ticket, insurance, etc
|
265
265
|
field :service_type
|
266
266
|
|
267
|
+
field :start_at, :datetime_combined, key: 'START'
|
268
|
+
|
269
|
+
field :end_at, :datetime_combined, key: 'END'
|
270
|
+
|
267
271
|
parser do
|
268
272
|
def ticket_status(value)
|
269
273
|
{
|
data/lib/gillbus/structs/trip.rb
CHANGED
@@ -160,11 +160,9 @@ class Gillbus
|
|
160
160
|
|
161
161
|
field :bus_photos, [BusPhoto], key: 'BUS_PHOTO'
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
ActiveSupport::TimeZone[timezone].parse(datetime_string)
|
167
|
-
end
|
163
|
+
field :start_at, :datetime_combined, key: 'START'
|
164
|
+
|
165
|
+
field :end_at, :datetime_combined, key: 'END'
|
168
166
|
|
169
167
|
parser do
|
170
168
|
def money(val)
|
data/lib/gillbus/version.rb
CHANGED
@@ -2,8 +2,11 @@ require 'test_helper'
|
|
2
2
|
require 'pry'
|
3
3
|
|
4
4
|
class ReserveTicketsTest < Minitest::Test
|
5
|
-
def reserve_tickets
|
6
|
-
Gillbus::ReserveTickets::Response.parse_string(
|
5
|
+
def reserve_tickets(timezone: nil)
|
6
|
+
Gillbus::ReserveTickets::Response.parse_string(
|
7
|
+
File.read('test/responses/reserveTickets.xml'),
|
8
|
+
timezone: timezone,
|
9
|
+
)
|
7
10
|
end
|
8
11
|
|
9
12
|
def test_number
|
@@ -19,10 +22,8 @@ class ReserveTicketsTest < Minitest::Test
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def test_date_to_pay_with_timezone
|
22
|
-
tickets =
|
23
|
-
|
24
|
-
timezone: 'Europe/Moscow',
|
25
|
-
)
|
25
|
+
tickets = reserve_tickets(timezone: 'Europe/Moscow')
|
26
|
+
|
26
27
|
assert_equal(DateTime.new(2013, 5, 22, 20, 30, 0, '+4'), tickets.tickets.first.date_to_pay)
|
27
28
|
assert_equal('MSK', tickets.tickets.first.date_to_pay.zone)
|
28
29
|
end
|
@@ -31,4 +32,32 @@ class ReserveTicketsTest < Minitest::Test
|
|
31
32
|
xml = YAML.load(File.read('test/responses/reserveTickets.yml'))
|
32
33
|
Gillbus::ReserveTickets::Response.parse(xml) # should not raise error
|
33
34
|
end
|
35
|
+
|
36
|
+
def test_start_at_end_at_parsing
|
37
|
+
# default timezone - Europe/Kiev
|
38
|
+
response = reserve_tickets
|
39
|
+
ticket = response.tickets.first
|
40
|
+
|
41
|
+
# default timezone
|
42
|
+
expected_start_at = ActiveSupport::TimeZone['Europe/Kiev'].parse('20.02.2013 14:40')
|
43
|
+
# timezone from response
|
44
|
+
expected_end_at = ActiveSupport::TimeZone['Europe/Prague'].parse('21.02.2013 06:35')
|
45
|
+
|
46
|
+
assert_equal expected_start_at, ticket.start_at
|
47
|
+
assert_equal expected_end_at, ticket.end_at
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_start_at_end_at_parsing_with_default_timezone
|
51
|
+
# default timezone - Europe/Moscow
|
52
|
+
response = reserve_tickets(timezone: 'Europe/Moscow')
|
53
|
+
ticket = response.tickets.first
|
54
|
+
|
55
|
+
# default timezone
|
56
|
+
expected_start_at = ActiveSupport::TimeZone['Europe/Moscow'].parse('20.02.2013 14:40')
|
57
|
+
# timezone from response
|
58
|
+
expected_end_at = ActiveSupport::TimeZone['Europe/Prague'].parse('21.02.2013 06:35')
|
59
|
+
|
60
|
+
assert_equal expected_start_at, ticket.start_at
|
61
|
+
assert_equal expected_end_at, ticket.end_at
|
62
|
+
end
|
34
63
|
end
|
@@ -24,8 +24,9 @@
|
|
24
24
|
<START_CITY>Донецк</START_CITY>
|
25
25
|
<START_DATE>20.02.2013</START_DATE>
|
26
26
|
<START_TIME>14:40</START_TIME>
|
27
|
-
<END_CITY
|
27
|
+
<END_CITY>Прага</END_CITY>
|
28
28
|
<END_TIME>06:35</END_TIME>
|
29
|
+
<END_TIMEZONE>Europe/Prague</END_TIMEZONE>
|
29
30
|
<TYPE_TARIFF_NAME>Y</TYPE_TARIFF_NAME>
|
30
31
|
<TARIFF>75.0</TARIFF>
|
31
32
|
<TARIFF_VAT>15.0</TARIFF_VAT>
|
@@ -57,7 +57,9 @@
|
|
57
57
|
<START_DATE>26.06.2015</START_DATE>
|
58
58
|
<END_DATE>26.06.2015</END_DATE>
|
59
59
|
<START_TIME>08:30</START_TIME>
|
60
|
+
<START_TIMEZONE>Europe/Moscow</START_TIMEZONE>
|
60
61
|
<END_TIME>15:30</END_TIME>
|
62
|
+
<END_TIMEZONE>Europe/Kiev</END_TIMEZONE>
|
61
63
|
<BUS_MODEL>Neoplan(Free)</BUS_MODEL>
|
62
64
|
<BUS_CLASS/>
|
63
65
|
<TRIP_SEATS_MAP>true</TRIP_SEATS_MAP>
|
data/test/search_trips_test.rb
CHANGED
@@ -109,6 +109,16 @@ class SearchTripsResponseTest < Minitest::Test
|
|
109
109
|
assert_equal trip2_start_at, response.trips[1].start_at
|
110
110
|
end
|
111
111
|
|
112
|
+
def test_end_at_parsing
|
113
|
+
response = get_successful_search_trips
|
114
|
+
|
115
|
+
trip1_end_at = ActiveSupport::TimeZone['Europe/Moscow'].parse('24.08.2014 06:30')
|
116
|
+
trip2_end_at = ActiveSupport::TimeZone['Europe/Kiev'].parse('24.08.2014 08:40')
|
117
|
+
|
118
|
+
assert_equal trip1_end_at, response.trips[0].end_at
|
119
|
+
assert_equal trip2_end_at, response.trips[1].end_at
|
120
|
+
end
|
121
|
+
|
112
122
|
def test_options_parsing
|
113
123
|
response = get_successful_search_trips
|
114
124
|
options = response.trips.first.options
|
@@ -182,12 +192,35 @@ class SearchTripsResponseTest < Minitest::Test
|
|
182
192
|
|
183
193
|
def test_trips_with_segments
|
184
194
|
response = get_trips_with_segments
|
195
|
+
|
185
196
|
assert response.completed
|
186
197
|
assert_equal 2, response.trips.size
|
187
|
-
|
188
|
-
|
189
|
-
assert_equal
|
190
|
-
assert_equal
|
198
|
+
|
199
|
+
trip = response.trips.first
|
200
|
+
assert_equal 'Europe/Kiev', trip.start_timezone
|
201
|
+
assert_equal 'Europe/Kiev', trip.end_timezone
|
202
|
+
assert_equal true, trip.fake_time_in_road
|
203
|
+
assert_equal 2, trip.segments.size
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_trip_segments_parsing
|
207
|
+
response = get_trips_with_segments
|
208
|
+
assert response.completed
|
209
|
+
|
210
|
+
segments = response.trips.first.segments
|
211
|
+
assert_equal 2, segments.size
|
212
|
+
|
213
|
+
segment1_start_at = ActiveSupport::TimeZone['Europe/Moscow'].parse('26.06.2015 08:30')
|
214
|
+
segment1_end_at = ActiveSupport::TimeZone['Europe/Kiev'].parse('26.06.2015 15:30')
|
215
|
+
|
216
|
+
assert_equal segment1_start_at, segments[0].start_at
|
217
|
+
assert_equal segment1_end_at, segments[0].end_at
|
218
|
+
|
219
|
+
segment2_start_at = ActiveSupport::TimeZone['Europe/Kiev'].parse('26.06.2015 22:40')
|
220
|
+
segment2_end_at = ActiveSupport::TimeZone['Europe/Kiev'].parse('27.06.2015 16:00')
|
221
|
+
|
222
|
+
assert_equal segment2_start_at, segments[1].start_at
|
223
|
+
assert_equal segment2_end_at, segments[1].end_at
|
191
224
|
end
|
192
225
|
|
193
226
|
def test_trips_with_insurance
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gillbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey "codesnik" Trofimenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-03-
|
12
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|