gillbus-v2 0.1.3 → 0.1.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
  SHA256:
3
- metadata.gz: 43f5f66f49c4de6dce6487cd0cf702d49073ca1a870d1097599d5caaeef798c9
4
- data.tar.gz: b413b3fb9ad9e346742bbf2566ffd6b81a2cc9f4e189b60a03d4f106eb954739
3
+ metadata.gz: fde634f5c1184079c313bebd9276de7096506f6e96c77459428cd46ff4018e95
4
+ data.tar.gz: 7b884d4a5c28e577181d831eab5208db26047dd96dac3a129bd7a87d6e515fa1
5
5
  SHA512:
6
- metadata.gz: 1aad4fa134e4e69d6d3e52d9d725768c80e5abeab5055347043ad2eeb488b9506fca7d8b6da7e3b891b1d1398a9e1f098e946804ef0699b2901d8e903e8181b8
7
- data.tar.gz: 18c6a257567c09351c22698c97c7376e3b4a9a5d142eeb9caa6c1547de9438f6dc502582048803f5e4cf1234c8d1cb747318ac113d74f3b19549f9193cace3da
6
+ metadata.gz: 1a5d85ad7349a52c756281bc2bdc13a59742961c20fb749c85f3ca9a095125c69ce710239c69c320a20de432735301ad36b6d5daa457a15cdd9452e00747bc3b
7
+ data.tar.gz: 728db2cc1e1f622f6b259add6ccd7abbf80c19621ab89f5b6b99283b0ef8de733c93f78e8e74670a54e8b9c08abd6a03910930a83d49e6f92a5d63407a0e0c36
data/README.md CHANGED
@@ -188,6 +188,36 @@ response.vehicles
188
188
  response.points
189
189
  ```
190
190
 
191
+ ### Get trip seats
192
+
193
+ Example of usage:
194
+
195
+ ```ruby
196
+ response = client.get_trip_seats(
197
+ trip_id: "123",
198
+ date: Date.today + 1,
199
+ back_date: Date.today + 5,
200
+ passengers_count: 1,
201
+ )
202
+
203
+ response.seat_maps.each do |seat_map|
204
+ # Array of all seats
205
+ seat_map.seats
206
+
207
+ # Seats by floor
208
+ seat_map.floors.each do |floor|
209
+ # Array of floor seats
210
+ seat_map.floor_seats(floor)
211
+ # Array of arrays of seats
212
+ seat_map.floor_seat_map(floor)
213
+ # Print the same result
214
+ puts seat_map.format_seats(floor: floor)
215
+ end
216
+ end
217
+ ```
218
+
219
+ See `Structs::SegmentSeatMap` for details.
220
+
191
221
  ## Development
192
222
 
193
223
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -26,8 +26,11 @@ require "gillbus/v2/structs/trip"
26
26
  require "gillbus/v2/structs/carrier"
27
27
  require "gillbus/v2/structs/vehicle"
28
28
  require "gillbus/v2/structs/point"
29
+ require "gillbus/v2/structs/seat"
30
+ require "gillbus/v2/structs/segment_seat_map"
29
31
 
30
32
  require "gillbus/v2/responses/base"
31
33
  require "gillbus/v2/responses/authenticate"
32
34
  require "gillbus/v2/responses/locations"
33
35
  require "gillbus/v2/responses/search_trips"
36
+ require "gillbus/v2/responses/trip_seats"
@@ -90,6 +90,17 @@ module Gillbus::V2
90
90
  )
91
91
  end
92
92
 
93
+ def get_trip_seats(trip_id:, date:, back_date: nil, passengers_count: 1)
94
+ params = {
95
+ date: date,
96
+ back_date: back_date,
97
+ pass_count: passengers_count,
98
+ }
99
+ call_api(:get, "/search/v2/trips/#{trip_id}/seats", params,
100
+ response_class: Responses::TripSeats,
101
+ )
102
+ end
103
+
93
104
  private
94
105
 
95
106
  def call_api(http_method, url, params, auth_required: true, response_class: Responses::Base)
@@ -0,0 +1,12 @@
1
+ module Gillbus::V2
2
+ module Responses
3
+ class TripSeats < Base
4
+ def seat_maps
5
+ @seat_maps ||=
6
+ (json_body["maps_seat"] || []).map do |item|
7
+ Structs::SegmentSeatMap.from_raw_data(item)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,26 +1,16 @@
1
1
  module Gillbus::V2
2
- # TODO: use in seatmap response or remove
3
2
  class Structs::Seat < Structs::Base
4
3
  field :id, :string
5
- field :number, :string
4
+ field :number, :string, from: "num"
6
5
 
7
- field :floor, :integer
8
- field :col, :integer
9
- field :row, :integer
6
+ field :seat_type, :string # TODO: Enum
7
+ field :status, :string # TODO: Enum
10
8
 
11
- field :seat_class, :string, from: "class"
12
-
13
- field :status, Enum.(
14
- "EMPTY",
15
- "ORDERED",
16
- "BLOCKED",
17
- "FREE",
18
- "BOOKED",
19
- "SALED",
20
- "SPESIAL",
21
- "REGISTERED",
22
- "TECHNICAL",
23
- "PRIORITY",
24
- )
9
+ # ярус
10
+ field :floor, :integer, from: "z"
11
+ # номер ряда, сверху вниз
12
+ field :row, :integer, from: "x"
13
+ # номер места в ряду, слева направо
14
+ field :col, :integer, from: "y"
25
15
  end
26
16
  end
@@ -0,0 +1,35 @@
1
+ module Gillbus::V2
2
+ class Structs::SegmentSeatMap < Structs::Base
3
+ field :segment_id, :string
4
+ field :seats, [Structs::Seat], from: "map_seat"
5
+
6
+ def floors
7
+ @floors ||= seats.map(&:floor).uniq
8
+ end
9
+
10
+ def floor_seats(floor)
11
+ seats.select { |seat| seat.floor == floor }
12
+ end
13
+
14
+ # Array of arrays (see result of #format_seats)
15
+ def floor_seat_map(floor)
16
+ floor_seats(floor)
17
+ .group_by(&:row)
18
+ .sort_by(&:first)
19
+ .map do |row, row_seats|
20
+ # TODO: reverse order?
21
+ row_seats.sort_by(&:col)
22
+ end
23
+ end
24
+
25
+ def format_seats(floor:, separator: " ")
26
+ rows =
27
+ floor_seat_map(floor).map do |row_seats|
28
+ row_seats
29
+ .map { |seat| "%3s" % seat.number }
30
+ .join(separator)
31
+ end
32
+ rows.join("\n")
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  module Gillbus::V2
2
2
  class Structs::Trip < Structs::Base
3
- field :id, :integer, from: "trip_id"
3
+ field :id, :string, from: "trip_id"
4
4
  field :direct_segments, [Structs::Segment], from: "direct_trip"
5
5
  field :back_segments, [Structs::Segment], from: "back_trip"
6
6
  end
@@ -1,5 +1,5 @@
1
1
  module Gillbus
2
2
  module V2
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gillbus-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Khrebtov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -147,6 +147,7 @@ files:
147
147
  - lib/gillbus/v2/responses/base.rb
148
148
  - lib/gillbus/v2/responses/locations.rb
149
149
  - lib/gillbus/v2/responses/search_trips.rb
150
+ - lib/gillbus/v2/responses/trip_seats.rb
150
151
  - lib/gillbus/v2/structs/access_token.rb
151
152
  - lib/gillbus/v2/structs/base.rb
152
153
  - lib/gillbus/v2/structs/carrier.rb
@@ -162,6 +163,7 @@ files:
162
163
  - lib/gillbus/v2/structs/segment.rb
163
164
  - lib/gillbus/v2/structs/segment_options.rb
164
165
  - lib/gillbus/v2/structs/segment_price.rb
166
+ - lib/gillbus/v2/structs/segment_seat_map.rb
165
167
  - lib/gillbus/v2/structs/segment_tariff.rb
166
168
  - lib/gillbus/v2/structs/trip.rb
167
169
  - lib/gillbus/v2/structs/vehicle.rb