gillbus 0.16.7 → 0.16.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +88 -0
  3. data/Rakefile +3 -3
  4. data/gillbus.gemspec +16 -15
  5. data/lib/gillbus.rb +10 -9
  6. data/lib/gillbus/base_request.rb +17 -19
  7. data/lib/gillbus/base_response.rb +11 -13
  8. data/lib/gillbus/buy_booking.rb +1 -9
  9. data/lib/gillbus/buy_tickets.rb +1 -8
  10. data/lib/gillbus/cancel_order.rb +0 -10
  11. data/lib/gillbus/drivers/faraday_response_file_logger.rb +1 -3
  12. data/lib/gillbus/find_order.rb +0 -5
  13. data/lib/gillbus/get_all_cities.rb +0 -2
  14. data/lib/gillbus/get_bus_image.rb +0 -3
  15. data/lib/gillbus/get_cities.rb +0 -4
  16. data/lib/gillbus/get_countries.rb +0 -4
  17. data/lib/gillbus/get_dates_new.rb +0 -4
  18. data/lib/gillbus/get_order_status.rb +1 -6
  19. data/lib/gillbus/get_order_ticket.rb +4 -7
  20. data/lib/gillbus/get_time_table.rb +0 -4
  21. data/lib/gillbus/get_trip_seats.rb +8 -11
  22. data/lib/gillbus/get_trip_segments.rb +0 -2
  23. data/lib/gillbus/get_trips.rb +0 -2
  24. data/lib/gillbus/helpers/fields.rb +5 -7
  25. data/lib/gillbus/helpers/parser.rb +10 -13
  26. data/lib/gillbus/helpers/update_attrs.rb +2 -4
  27. data/lib/gillbus/lock_seats.rb +7 -10
  28. data/lib/gillbus/logout.rb +0 -6
  29. data/lib/gillbus/parse_error.rb +3 -1
  30. data/lib/gillbus/reserve_tickets.rb +0 -2
  31. data/lib/gillbus/return_position.rb +0 -1
  32. data/lib/gillbus/search_trips.rb +5 -6
  33. data/lib/gillbus/session_login.rb +0 -6
  34. data/lib/gillbus/structs/commission.rb +4 -4
  35. data/lib/gillbus/structs/item.rb +0 -2
  36. data/lib/gillbus/structs/passenger_discount.rb +2 -3
  37. data/lib/gillbus/structs/point.rb +0 -1
  38. data/lib/gillbus/structs/return_cause.rb +0 -2
  39. data/lib/gillbus/structs/seat.rb +0 -2
  40. data/lib/gillbus/structs/segment.rb +5 -6
  41. data/lib/gillbus/structs/tariff.rb +1 -2
  42. data/lib/gillbus/structs/tariff/return_cause.rb +3 -3
  43. data/lib/gillbus/structs/ticket.rb +0 -2
  44. data/lib/gillbus/structs/timetable_trip.rb +4 -4
  45. data/lib/gillbus/structs/trip.rb +5 -6
  46. data/lib/gillbus/structs/trip_options.rb +0 -1
  47. data/lib/gillbus/structs/trip_service.rb +0 -2
  48. data/lib/gillbus/tickets_booking.rb +17 -13
  49. data/lib/gillbus/unlock_seats.rb +0 -2
  50. data/lib/gillbus/version.rb +1 -1
  51. data/script/example_booking.rb +16 -18
  52. data/script/example_booking_with_segments.rb +0 -1
  53. data/script/example_canceling_booking.rb +12 -13
  54. data/script/example_canceling_reservation.rb +11 -12
  55. data/script/example_reservation.rb +14 -15
  56. data/test/all_commissions_test.rb +1 -2
  57. data/test/buy_booking_test.rb +14 -13
  58. data/test/buy_tickets_test.rb +1 -2
  59. data/test/cancel_order_test.rb +1 -2
  60. data/test/error_test.rb +1 -3
  61. data/test/find_order_test.rb +3 -4
  62. data/test/get_bus_image_test.rb +0 -1
  63. data/test/get_cities_test.rb +1 -2
  64. data/test/get_countries_test.rb +1 -2
  65. data/test/get_dates_new_test.rb +0 -1
  66. data/test/get_order_ticket_test.rb +1 -2
  67. data/test/get_time_table_test.rb +0 -1
  68. data/test/get_trip_seats_test.rb +3 -4
  69. data/test/get_trip_segments_test.rb +5 -6
  70. data/test/lock_seats_test.rb +43 -33
  71. data/test/reserve_tickets_test.rb +10 -3
  72. data/test/return_position_test.rb +8 -5
  73. data/test/search_trips_test.rb +15 -19
  74. data/test/session_login_test.rb +0 -1
  75. data/test/tickets_booking_test.rb +2 -3
  76. metadata +24 -9
@@ -1,7 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class BuyBookingTest < Minitest::Test
4
-
5
4
  def response
6
5
  Gillbus::BuyBooking::Response.parse_string(File.read('test/responses/buyBooking.xml'))
7
6
  end
@@ -11,22 +10,24 @@ class BuyBookingTest < Minitest::Test
11
10
  request = Gillbus::BuyBooking::Request.new(
12
11
  payment_method: Gillbus::BuyBooking::Request::METHOD_NOCASH,
13
12
  ticket_count: 2,
14
- ticket_numbers: ["123456", "654321"],
15
- order_ids: ["53ec1fc6-e42a-42b2-b94f-1d5b47466526", "53ec1fc6-e42a-42b2-b94f-1d5b47466526"]
13
+ ticket_numbers: ['123456', '654321'],
14
+ order_ids: ['53ec1fc6-e42a-42b2-b94f-1d5b47466526', '53ec1fc6-e42a-42b2-b94f-1d5b47466526'],
15
+ )
16
+ assert_equal(
17
+ {
18
+ paymentMethod: 3,
19
+ ticketCount: 2,
20
+ ticketNumber0: '123456',
21
+ ticketNumber1: '654321',
22
+ orderId0: '53ec1fc6-e42a-42b2-b94f-1d5b47466526',
23
+ orderId1: '53ec1fc6-e42a-42b2-b94f-1d5b47466526',
24
+ },
25
+ request.params,
16
26
  )
17
- assert_equal({
18
- paymentMethod: 3,
19
- ticketCount: 2,
20
- ticketNumber0: "123456",
21
- ticketNumber1: "654321",
22
- orderId0: "53ec1fc6-e42a-42b2-b94f-1d5b47466526",
23
- orderId1: "53ec1fc6-e42a-42b2-b94f-1d5b47466526",
24
- }, request.params)
25
27
  end
26
28
 
27
29
  def test_response
28
30
  assert response.ticket.confirmation
29
31
  assert_equal [123456, 654321], response.ticket.position_numbers
30
32
  end
31
-
32
33
  end
@@ -1,7 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class BuyTicketsTest < Minitest::Test
4
-
5
4
  def buy_tickets
6
5
  Gillbus::BuyTickets::Response.parse_string(File.read('test/responses/buyTickets.xml'))
7
6
  end
@@ -1,7 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class CancelOrderTest < Minitest::Test
4
-
5
4
  def cancel_order
6
5
  Gillbus::CancelOrder::Response.parse_string(File.read('test/responses/cancelOrder.xml'))
7
6
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ErrorTest < Minitest::Test
4
-
5
4
  def error_response
6
5
  Gillbus::SessionLogin::Response.parse_string(File.read('test/responses/error.xml'))
7
6
  end
@@ -17,7 +16,7 @@ class ErrorTest < Minitest::Test
17
16
  def test_errorness
18
17
  assert error_response.error?
19
18
  assert_equal 4, error_response.error_code
20
- assert_equal "Session not created error!", error_response.error_message
19
+ assert_equal 'Session not created error!', error_response.error_message
21
20
  assert_equal "We'r fucked", error_response.external_error_message
22
21
  end
23
22
 
@@ -28,5 +27,4 @@ class ErrorTest < Minitest::Test
28
27
  def test_malformed_2_errorness
29
28
  assert malformed_response_2.error?
30
29
  end
31
-
32
30
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class FindOrderTest < Minitest::Test
4
-
5
4
  def find_order
6
5
  Gillbus::FindOrder::Response.parse_string(File.read('test/responses/findOrder.xml'))
7
6
  end
@@ -11,7 +10,7 @@ class FindOrderTest < Minitest::Test
11
10
  end
12
11
 
13
12
  def test_number
14
- assert_equal("14482", find_order.tickets.first.ticket_number)
13
+ assert_equal('14482', find_order.tickets.first.ticket_number)
15
14
  end
16
15
 
17
16
  def test_total
@@ -27,11 +26,11 @@ class FindOrderTest < Minitest::Test
27
26
  end
28
27
 
29
28
  def test_comission_vat_value
30
- assert_equal("18", find_order.tickets.last.commissions.first.vat_value)
29
+ assert_equal('18', find_order.tickets.last.commissions.first.vat_value)
31
30
  end
32
31
 
33
32
  def test_vat_value
34
- assert_equal("0", find_order.tickets.first.vat_value)
33
+ assert_equal('0', find_order.tickets.first.vat_value)
35
34
  end
36
35
 
37
36
  def test_comission_currency
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetBusImageTest < Minitest::Test
4
-
5
4
  def get_bus_image
6
5
  Gillbus::GetBusImage::Response.parse_string(File.read('test/responses/getBusImage.xml'))
7
6
  end
@@ -1,12 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetCitiesTest < Minitest::Test
4
-
5
4
  def get_cities
6
5
  Gillbus::GetCities::Response.parse_string(File.read('test/responses/getCities.xml'))
7
6
  end
8
7
 
9
8
  def test_cities
10
- assert_equal( 'Афины', get_cities.cities.first.name)
9
+ assert_equal('Афины', get_cities.cities.first.name)
11
10
  end
12
11
  end
@@ -1,12 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetCountriesTest < Minitest::Test
4
-
5
4
  def get_countries
6
5
  Gillbus::GetCountries::Response.parse_string(File.read('test/responses/getCountries.xml'))
7
6
  end
8
7
 
9
8
  def test_countries
10
- assert_equal( "Австрия", get_countries.countries.first.name)
9
+ assert_equal('Австрия', get_countries.countries.first.name)
11
10
  end
12
11
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetDatesNewTest < Minitest::Test
4
-
5
4
  def get_dates_new_empty
6
5
  Gillbus::GetDatesNew::Response.parse_string(File.read('test/responses/very_empty.xml'))
7
6
  end
@@ -1,12 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetOrderTicketTest < Minitest::Test
4
-
5
4
  def get_order_ticket
6
5
  Gillbus::GetOrderTicket::Response.parse_string(File.read('test/responses/getOrderTicket.xml'))
7
6
  end
8
7
 
9
8
  def test_ticket
10
- assert_equal( "base64 string", get_order_ticket.ticket)
9
+ assert_equal('base64 string', get_order_ticket.ticket)
11
10
  end
12
11
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetTimeTableTest < Minitest::Test
4
-
5
4
  def get_time_table
6
5
  Gillbus::GetTimeTable::Response.parse_string(File.read('test/responses/getTimeTable.xml'))
7
6
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetTripSeatsTest < Minitest::Test
4
-
5
4
  def get_trip_seats
6
5
  Gillbus::GetTripSeats::Response.parse_string(File.read('test/responses/getTripSeats.xml'))
7
6
  end
@@ -18,9 +17,9 @@ class GetTripSeatsTest < Minitest::Test
18
17
  seats = get_trip_seats.seats
19
18
  max_x = seats.map(&:x).max
20
19
  max_y = seats.map(&:y).max
21
- assert_equal( 70, seats.size )
22
- assert_equal( 4, max_y )
23
- assert_equal( 13, max_x )
20
+ assert_equal(70, seats.size)
21
+ assert_equal(4, max_y)
22
+ assert_equal(13, max_x)
24
23
  end
25
24
 
26
25
  def test_seats_with_segments
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetTripSegmentsTest < Minitest::Test
4
-
5
4
  def get_trip_segments
6
5
  Gillbus::GetTripSegments::Response.parse_string(File.read('test/responses/getTripSegments.xml'))
7
6
  end
@@ -9,10 +8,10 @@ class GetTripSegmentsTest < Minitest::Test
9
8
  def test_get_trip_segments
10
9
  points = get_trip_segments.points
11
10
 
12
- assert_equal( 13, points.size )
13
- assert_equal( 'Львов', points.first.geography_name )
14
- assert_equal( 'Ж/Д вокзал Львів', points.first.name )
15
- assert_equal( 'Щецин', points.last.geography_name )
16
- assert_equal( 'Автовокзал', points.last.name )
11
+ assert_equal(13, points.size)
12
+ assert_equal('Львов', points.first.geography_name)
13
+ assert_equal('Ж/Д вокзал Львів', points.first.name)
14
+ assert_equal('Щецин', points.last.geography_name)
15
+ assert_equal('Автовокзал', points.last.name)
17
16
  end
18
17
  end
@@ -3,55 +3,65 @@ require 'test_helper'
3
3
  class LockSeatsRequestTest < Minitest::Test
4
4
  def test_lock_params
5
5
  request = Gillbus::LockSeats::Request.new(
6
- trip_id: "2457369573939592570",
6
+ trip_id: '2457369573939592570',
7
+ )
8
+ assert_equal(
9
+ { tripId: '2457369573939592570' },
10
+ request.params,
7
11
  )
8
- assert_equal({
9
- tripId: "2457369573939592570",
10
- }, request.params)
11
12
  end
12
13
 
13
14
  def test_lock_params_with_seats
14
15
  request = Gillbus::LockSeats::Request.new(
15
- trip_id: "2457369573939592570",
16
- seat_ids: ["12", "13"],
16
+ trip_id: '2457369573939592570',
17
+ seat_ids: ['12', '13'],
18
+ )
19
+ assert_equal(
20
+ {
21
+ tripId: '2457369573939592570',
22
+ seatId0: '12',
23
+ seatId1: '13',
24
+ },
25
+ request.params,
17
26
  )
18
- assert_equal({
19
- tripId: "2457369573939592570",
20
- seatId0: "12",
21
- seatId1: "13",
22
- }, request.params)
23
27
  end
24
28
 
25
29
  def test_lock_params_with_back_seats
26
30
  request = Gillbus::LockSeats::Request.new(
27
- trip_id: "2457369573939592570",
28
- seat_ids: ["12", "13"],
29
- back_seat_ids: ["14", "15"],
31
+ trip_id: '2457369573939592570',
32
+ seat_ids: ['12', '13'],
33
+ back_seat_ids: ['14', '15'],
34
+ )
35
+ assert_equal(
36
+ {
37
+ tripId: '2457369573939592570',
38
+ seatId0: '12',
39
+ seatId1: '13',
40
+ backSeatId0: '14',
41
+ backSeatId1: '15',
42
+ },
43
+ request.params,
30
44
  )
31
- assert_equal({
32
- tripId: "2457369573939592570",
33
- seatId0: "12",
34
- seatId1: "13",
35
- backSeatId0: "14",
36
- backSeatId1: "15",
37
- }, request.params)
38
45
  end
39
46
 
40
47
  def test_lock_params_with_segments_seats
41
48
  request = Gillbus::LockSeats::Request.new(
42
- trip_id: "2457369573939592570",
49
+ trip_id: '2457369573939592570',
43
50
  segments_seat_ids: {
44
- 0 => ["12", "13"],
45
- 1 => ["14", "15"],
46
- }
51
+ 0 => ['12', '13'],
52
+ 1 => ['14', '15'],
53
+ },
54
+ )
55
+ assert_equal(
56
+ {
57
+ tripId: '2457369573939592570',
58
+ segment0seatId0: '12',
59
+ segment0seatId1: '13',
60
+ segment1seatId0: '14',
61
+ segment1seatId1: '15',
62
+ },
63
+ request.params,
47
64
  )
48
- assert_equal({
49
- tripId: "2457369573939592570",
50
- segment0seatId0: "12",
51
- segment0seatId1: "13",
52
- segment1seatId0: "14",
53
- segment1seatId1: "15",
54
- }, request.params)
55
65
  end
56
66
  end
57
67
 
@@ -61,7 +71,7 @@ class LockSeatsResponseTest < Minitest::Test
61
71
  end
62
72
 
63
73
  def test_lock_seats
64
- assert_equal( 899, lock_seats.time_limit)
74
+ assert_equal(899, lock_seats.time_limit)
65
75
  end
66
76
 
67
77
  def test_dictionary
@@ -2,21 +2,28 @@ require 'test_helper'
2
2
  require 'pry'
3
3
 
4
4
  class ReserveTicketsTest < Minitest::Test
5
-
6
5
  def reserve_tickets
7
6
  Gillbus::ReserveTickets::Response.parse_string(File.read('test/responses/reserveTickets.xml'))
8
7
  end
9
8
 
10
9
  def test_number
11
- assert_equal("8472", reserve_tickets.tickets.first.ticket_number)
10
+ assert_equal('8472', reserve_tickets.tickets.first.ticket_number)
12
11
  end
13
12
 
14
13
  def test_total
15
- assert_equal(Money.new(110_00, "UAH"), reserve_tickets.tickets.first.total_amount)
14
+ assert_equal(Money.new(110_00, 'UAH'), reserve_tickets.tickets.first.total_amount)
16
15
  end
17
16
 
18
17
  def test_date_to_pay
19
18
  assert_equal(DateTime.new(2013, 5, 22, 20, 30, 0, '+3'), reserve_tickets.tickets.first.date_to_pay)
20
19
  end
21
20
 
21
+ 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
+ )
26
+ assert_equal(DateTime.new(2013, 5, 22, 20, 30, 0, '+4'), tickets.tickets.first.date_to_pay)
27
+ assert_equal('MSK', tickets.tickets.first.date_to_pay.zone)
28
+ end
22
29
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class ReturnPositionTest < Minitest::Test
4
4
  def test_request
@@ -7,10 +7,13 @@ class ReturnPositionTest < Minitest::Test
7
7
  system_numbers: [123456],
8
8
  )
9
9
 
10
- assert_equal({
11
- ticketCount: 1,
12
- systemNumber0: 123456,
13
- }, request.params)
10
+ assert_equal(
11
+ {
12
+ ticketCount: 1,
13
+ systemNumber0: 123456,
14
+ },
15
+ request.params,
16
+ )
14
17
  end
15
18
 
16
19
  def test_success_response
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SearchTripsRequestTest < Minitest::Test
4
-
5
4
  def test_params
6
5
  req = Gillbus::SearchTrips::Request.new(
7
6
  start_date_search: Date.new(2013, 2, 4),
@@ -21,14 +20,14 @@ class SearchTripsRequestTest < Minitest::Test
21
20
  student_year: 2,
22
21
  isic: 'ISIC#2',
23
22
  with_seat: false,
24
- }
23
+ },
25
24
  ],
26
25
  )
27
26
 
28
27
  expected_params = {
29
- startDateSearch: "04.02.2013",
30
- selectedModes: "3;8",
31
- roundTrip: "1",
28
+ startDateSearch: '04.02.2013',
29
+ selectedModes: '3;8',
30
+ roundTrip: '1',
32
31
  passenger0birthday: '01.01.1990',
33
32
  passenger0studentTicket: 'STUDENTTICKET#1',
34
33
  passenger0studentYear: 1,
@@ -43,11 +42,9 @@ class SearchTripsRequestTest < Minitest::Test
43
42
 
44
43
  assert_equal expected_params, req.params
45
44
  end
46
-
47
45
  end
48
46
 
49
47
  class SearchTripsResponseTest < Minitest::Test
50
-
51
48
  def get_empty_search_trips
52
49
  Gillbus::SearchTrips::Response.parse_string(File.read('test/responses/searchTrips-empty.xml'))
53
50
  end
@@ -83,9 +80,9 @@ class SearchTripsResponseTest < Minitest::Test
83
80
 
84
81
  def test_fields_parsing
85
82
  response = get_successful_search_trips
86
- assert_equal Date.new(2014,8,23), response.trips.first.start_date
87
- assert_equal Money.new(1410_00, "RUB"), response.trips.first.total_cost
88
- assert_equal Money.new(1410_00, "RUB"), response.trips.first.tariffs.first.cost
83
+ assert_equal Date.new(2014, 8, 23), response.trips.first.start_date
84
+ assert_equal Money.new(1410_00, 'RUB'), response.trips.first.total_cost
85
+ assert_equal Money.new(1410_00, 'RUB'), response.trips.first.tariffs.first.cost
89
86
  assert_equal 'Europe/Moscow', response.trips.first.start_timezone
90
87
  assert_equal 'Europe/Moscow', response.trips.first.end_timezone
91
88
  assert_equal true, response.trips.first.fake_time_in_road
@@ -114,29 +111,29 @@ class SearchTripsResponseTest < Minitest::Test
114
111
 
115
112
  services = {
116
113
  1 => 'Кофе',
117
- 15 => 'Wi-Fi'
114
+ 15 => 'Wi-Fi',
118
115
  }
119
116
  luggage_options = [
120
117
  'В стоимость входит провоз 2 единиц багажа свыше 80 кг.',
121
118
  'Ручная кладь 20см x 40см x 30см входит в стоимость билета.',
122
- 'Превышение по багажу оплачивается в размере 1% от стоимости тарифа.'
119
+ 'Превышение по багажу оплачивается в размере 1% от стоимости тарифа.',
123
120
  ]
124
121
  seating_options = [
125
- 'Свободная рассадка.'
122
+ 'Свободная рассадка.',
126
123
  ]
127
124
  technical_stops = [
128
- 'Технические остановки осуществляются каждые 2-3 часа.'
125
+ 'Технические остановки осуществляются каждые 2-3 часа.',
129
126
  ]
130
127
  critical_info = [
131
- 'ВНИМАНИЕ: Особые условия паспортного режима пересечения пропускного пункта (только с паспортами РБ и РФ).'
128
+ 'ВНИМАНИЕ: Особые условия паспортного режима пересечения пропускного пункта (только с паспортами РБ и РФ).',
132
129
  ]
133
130
  resource_options = [
134
- 'Посадка начинается за 10 мин.'
131
+ 'Посадка начинается за 10 мин.',
135
132
  ]
136
133
  other_options = [
137
134
  'Переправа',
138
135
  'Трансфер',
139
- 'Cкидка при покупке раунд-трипа'
136
+ 'Cкидка при покупке раунд-трипа',
140
137
  ]
141
138
 
142
139
  assert_equal services.values, options.services.map(&:name)
@@ -173,7 +170,7 @@ class SearchTripsResponseTest < Minitest::Test
173
170
  def test_faking_response
174
171
  trip = Gillbus::Trip.new(
175
172
  id: '12345',
176
- start_date: Date.today
173
+ start_date: Date.today,
177
174
  )
178
175
  assert_equal '12345', trip.id
179
176
  assert_equal Date.today, trip.start_date
@@ -188,5 +185,4 @@ class SearchTripsResponseTest < Minitest::Test
188
185
  assert_equal true, response.trips.first.fake_time_in_road
189
186
  assert_equal 2, response.trips.first.segments.size
190
187
  end
191
-
192
188
  end