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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c24e75a394d31f69936e9a3822a2a839232d171d
4
- data.tar.gz: 2e1c151cf0a63632fce3d4a3b333cfdbf6fff2c6
3
+ metadata.gz: 140d94b1fc16018b2810e3abc6a1fd9bc5bf7393
4
+ data.tar.gz: b9a87718c0a4e543115763efebb8daf51acbe8aa
5
5
  SHA512:
6
- metadata.gz: 2732ce3dad4378648cec1f3e3152958c47452a6e2ea32fb01b73e1e14e4a62ad498dc2d40b737110434e936fc54203789c877c3ae5a4606448612b66a4272a3a
7
- data.tar.gz: b24023751a614b3dc092ceba07b09b3c236e98f24ded2b941953eb7dd71ad4ee7bfe01d0c9b589bac5a13afd5dbe66b50f27c363b175ce900fb5b816237b9eca
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
- raw_value =
22
- if key.is_a?(Regexp)
23
- doc.select { |k| k =~ key }
24
- elsif root
25
- doc[root] && doc[root][key]
21
+ value =
22
+ if type == :datetime_combined
23
+ datetime_combined(key)
26
24
  else
27
- doc[key]
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
- tz = @options[:timezone] || 'Europe/Kiev'
94
- ActiveSupport::TimeZone[tz].parse(val)
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
- def start_at
150
- timezone = data['START_TIMEZONE'] || 'Europe/Kiev'
151
- datetime_string = "#{data['START_DATE']} #{data['START_TIME']}"
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
  {
@@ -160,11 +160,9 @@ class Gillbus
160
160
 
161
161
  field :bus_photos, [BusPhoto], key: 'BUS_PHOTO'
162
162
 
163
- def start_at
164
- timezone = data['START_TIMEZONE'] || 'Europe/Kiev'
165
- datetime_string = "#{data['START_DATE']} #{data['START_TIME']}"
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)
@@ -1,3 +1,3 @@
1
1
  class Gillbus
2
- VERSION = '0.17.3'.freeze
2
+ VERSION = '0.17.4'.freeze
3
3
  end
@@ -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(File.read('test/responses/reserveTickets.xml'))
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 = Gillbus::ReserveTickets::Response.parse_string(
23
- File.read('test/responses/reserveTickets.xml'),
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>Одесса</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>
@@ -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
- assert_equal 'Europe/Kiev', response.trips.first.start_timezone
188
- assert_equal 'Europe/Kiev', response.trips.first.end_timezone
189
- assert_equal true, response.trips.first.fake_time_in_road
190
- assert_equal 2, response.trips.first.segments.size
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.3
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-05 00:00:00.000000000 Z
12
+ date: 2018-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport