go_transit 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/go_transit/api_resource.rb +20 -0
- data/lib/go_transit/errors.rb +1 -0
- data/lib/go_transit/resources/schedule/journey/sch_journey/service/trip/stop.rb +9 -1
- data/lib/go_transit/resources/schedule/journey/sch_journey.rb +16 -0
- data/lib/go_transit/resources/schedule/trip/stop/arrival_time.rb +17 -1
- data/lib/go_transit/resources/schedule/trip/stop/departure_time.rb +17 -1
- data/lib/go_transit/resources/schedule/trip/stop.rb +5 -0
- data/lib/go_transit/resources/schedule/trip.rb +4 -0
- data/lib/go_transit/resources/schedule.rb +3 -1
- data/lib/go_transit/response.rb +0 -4
- data/lib/go_transit/version.rb +1 -1
- data/lib/go_transit.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84243aa4bc3cdb3d2a86f340ca75d60258e93e98bb9977f32d36ec05b2222932
|
|
4
|
+
data.tar.gz: 40069a1839ae01fd8053053398ef33607ee4af557a9c1f8f7b891e2ee91807c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcb8c6f390868672a075a961631c79762089e0bb84e9eace72be500174352b4b6120789377f7041b65aff7ea1e40a2f2450162939182ac94fe27c0ac055d2c87
|
|
7
|
+
data.tar.gz: ac5a553ddd10f0225cb1a80088bed844c94f8ddc64c1ff2801cfaa9840373b1e52aa09a594f9c90e8c1dfd1625d9806ab96ccbaa06d94e1b4fb77ed11084f73e
|
|
@@ -48,5 +48,25 @@ module GoTransit
|
|
|
48
48
|
def to_local(date, timezone: "America/Toronto")
|
|
49
49
|
date.in_time_zone(timezone)
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
def to_utc_from_anchor(time, trip_date, timezone: "America/Toronto")
|
|
53
|
+
to_local_from_anchor(time, trip_date, timezone: timezone)&.utc
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_local_from_anchor(time, trip_date, timezone: "America/Toronto")
|
|
57
|
+
raise MissingAnchorDateError if trip_date.nil?
|
|
58
|
+
return nil if time.blank?
|
|
59
|
+
hour = time.split(":").first.to_i
|
|
60
|
+
date = determine_date(trip_date, hour)
|
|
61
|
+
"#{date} #{time}".in_time_zone(timezone)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def determine_date(date, hour)
|
|
65
|
+
if hour < GoTransit.service_day_boundary_hour
|
|
66
|
+
date + 1.day
|
|
67
|
+
else
|
|
68
|
+
date
|
|
69
|
+
end
|
|
70
|
+
end
|
|
51
71
|
end
|
|
52
72
|
end
|
data/lib/go_transit/errors.rb
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
module GoTransit
|
|
2
2
|
class Schedule::Journey::SchJourney::Service::Trip::Stop < ApiResource
|
|
3
|
-
attr_accessor :code, :order, :time, :sorting_time, :is_major
|
|
3
|
+
attr_accessor :code, :order, :time, :sorting_time, :is_major, :anchor_date
|
|
4
4
|
|
|
5
5
|
def major?
|
|
6
6
|
is_major.to_i.positive?
|
|
7
7
|
end
|
|
8
|
+
|
|
9
|
+
def time_utc
|
|
10
|
+
to_utc_from_anchor(time, anchor_date)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def time_local
|
|
14
|
+
to_local_from_anchor(time, anchor_date)
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
end
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
module GoTransit
|
|
2
2
|
class Schedule::Journey::SchJourney < ApiResource
|
|
3
3
|
attr_accessor :date, :time, :to, :from, :services
|
|
4
|
+
|
|
5
|
+
def initialize(params)
|
|
6
|
+
super
|
|
7
|
+
propagate_anchor_date
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def propagate_anchor_date
|
|
13
|
+
parsed_date = Date.parse(date)
|
|
14
|
+
services.each do |service|
|
|
15
|
+
service.trips.each do |trip|
|
|
16
|
+
trip.stops.each { |stop| stop.anchor_date = parsed_date }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
4
20
|
end
|
|
5
21
|
end
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
module GoTransit
|
|
2
2
|
class Schedule::Trip::Stop::ArrivalTime < ApiResource
|
|
3
|
-
attr_accessor :scheduled, :computed, :status
|
|
3
|
+
attr_accessor :scheduled, :computed, :status, :anchor_date
|
|
4
|
+
|
|
5
|
+
def scheduled_utc
|
|
6
|
+
to_utc_from_anchor(scheduled, anchor_date)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def scheduled_local
|
|
10
|
+
to_local_from_anchor(scheduled, anchor_date)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def computed_utc
|
|
14
|
+
to_utc_from_anchor(computed, anchor_date)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def computed_local
|
|
18
|
+
to_local_from_anchor(computed, anchor_date)
|
|
19
|
+
end
|
|
4
20
|
end
|
|
5
21
|
end
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
module GoTransit
|
|
2
2
|
class Schedule::Trip::Stop::DepartureTime < ApiResource
|
|
3
|
-
attr_accessor :scheduled, :computed, :status
|
|
3
|
+
attr_accessor :scheduled, :computed, :status, :anchor_date
|
|
4
|
+
|
|
5
|
+
def scheduled_utc
|
|
6
|
+
to_utc_from_anchor(scheduled, anchor_date)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def scheduled_local
|
|
10
|
+
to_local_from_anchor(scheduled, anchor_date)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def computed_utc
|
|
14
|
+
to_utc_from_anchor(computed, anchor_date)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def computed_local
|
|
18
|
+
to_local_from_anchor(computed, anchor_date)
|
|
19
|
+
end
|
|
4
20
|
end
|
|
5
21
|
end
|
|
@@ -26,7 +26,9 @@ module GoTransit
|
|
|
26
26
|
formatted_date = date.strftime("%Y%m%d")
|
|
27
27
|
client = Client.new
|
|
28
28
|
response = client.get("Schedule/Trip/#{formatted_date}/#{trip_number}")
|
|
29
|
-
new(response.data).trips
|
|
29
|
+
trips = new(response.data).trips
|
|
30
|
+
trips.each { |trip| trip.anchor_date = date }
|
|
31
|
+
trips
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
34
|
end
|
data/lib/go_transit/response.rb
CHANGED
|
@@ -25,10 +25,6 @@ module GoTransit
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def throw_error
|
|
28
|
-
# A genuine transport-level 429 always wins, even if the JSON body
|
|
29
|
-
# (when there is one) claims success - GO Transit's own error
|
|
30
|
-
# convention embeds the real code in the body, but an upstream
|
|
31
|
-
# rate limiter returning 429 isn't guaranteed to follow that.
|
|
32
28
|
raise TooManyRequestsError.new(metadata) if http_status == 429
|
|
33
29
|
return if code == 200
|
|
34
30
|
raise NoContentError.new(metadata) if code == 204
|
data/lib/go_transit/version.rb
CHANGED
data/lib/go_transit.rb
CHANGED
|
@@ -62,9 +62,10 @@ require "go_transit/resources/schedule/journey/sch_journey/service/trip/stop"
|
|
|
62
62
|
|
|
63
63
|
module GoTransit
|
|
64
64
|
@api_key = ""
|
|
65
|
+
@service_day_boundary_hour = 4
|
|
65
66
|
|
|
66
67
|
class << self
|
|
67
|
-
attr_accessor :api_key, :custom_base_url
|
|
68
|
+
attr_accessor :api_key, :custom_base_url, :service_day_boundary_hour
|
|
68
69
|
|
|
69
70
|
def configure
|
|
70
71
|
yield self
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: go_transit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Mazur
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|