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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b30c2d11058a8d509c7950071d7392ecbdf56463063613da290604125ca67f0
4
- data.tar.gz: 2906067cbfd752a3e5c7182459015f5a6843ecec6badd49a2ec0746a3ebbce35
3
+ metadata.gz: 84243aa4bc3cdb3d2a86f340ca75d60258e93e98bb9977f32d36ec05b2222932
4
+ data.tar.gz: 40069a1839ae01fd8053053398ef33607ee4af557a9c1f8f7b891e2ee91807c1
5
5
  SHA512:
6
- metadata.gz: ac888ca4fe0a81be3390d69b117a790cb3129d523e46a9c496dd5a8a04736ebfe295f9b10dc65ae532c344bcc96516d7c90abefb810872ee0e6c6282aadfaef3
7
- data.tar.gz: aa24ae455d0fa37299ebe2bc7209d4eaa8495e92bb79a454a8a96f57e2227452f2051548a9859d3438d83f1c0c5cc599ff683b7164fcf5a4b1aa24111740e75c
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
@@ -11,4 +11,5 @@ module GoTransit
11
11
  ForbiddenError = Class.new(ApiError)
12
12
  NotFoundError = Class.new(ApiError)
13
13
  TooManyRequestsError = Class.new(ApiError)
14
+ MissingAnchorDateError = Class.new(StandardError)
14
15
  end
@@ -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
@@ -2,5 +2,10 @@ module GoTransit
2
2
  class Schedule::Trip::Stop < ApiResource
3
3
  attr_accessor :arrival_time, :departure_time, :track, :code, :status,
4
4
  :remark
5
+
6
+ def anchor_date=(date)
7
+ arrival_time.anchor_date = date
8
+ departure_time.anchor_date = date
9
+ end
5
10
  end
6
11
  end
@@ -10,5 +10,9 @@ module GoTransit
10
10
  def time_stamp_local
11
11
  to_local(time_stamp)
12
12
  end
13
+
14
+ def anchor_date=(date)
15
+ stops.each { |stop| stop.anchor_date = date }
16
+ end
13
17
  end
14
18
  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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GoTransit
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
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.2.0
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-13 00:00:00.000000000 Z
11
+ date: 2026-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport