go_transit 1.1.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: ee9e60a59caf970a1ede5d1f412722b2710f00265f9e3f24d6da081261f0b044
4
- data.tar.gz: 8992c200e8f9a727c4d37cc96843d972f5c16c3df7c21782511fbee01f644869
3
+ metadata.gz: 84243aa4bc3cdb3d2a86f340ca75d60258e93e98bb9977f32d36ec05b2222932
4
+ data.tar.gz: 40069a1839ae01fd8053053398ef33607ee4af557a9c1f8f7b891e2ee91807c1
5
5
  SHA512:
6
- metadata.gz: 2e9bf26e3c22f7e28c3392e94e914c8c654b01b2ed9d8d42810b042ebff2daa01c115aa01ef23826b03b57eef4e7925b5cf73b12e79c8a2a3ad9b8a5711b94ae
7
- data.tar.gz: d961631c8e1749670904195b61e4e7b5b44e1ed80e306873a34ecbb5b475c6eb51fc6165360524cf4fb151754caef2e0c2c642a2d66dbe56f8b0a803dcfd654f
6
+ metadata.gz: bcb8c6f390868672a075a961631c79762089e0bb84e9eace72be500174352b4b6120789377f7041b65aff7ea1e40a2f2450162939182ac94fe27c0ac055d2c87
7
+ data.tar.gz: ac5a553ddd10f0225cb1a80088bed844c94f8ddc64c1ff2801cfaa9840373b1e52aa09a594f9c90e8c1dfd1625d9806ab96ccbaa06d94e1b4fb77ed11084f73e
@@ -42,7 +42,31 @@ module GoTransit
42
42
  end
43
43
 
44
44
  def to_utc(date)
45
- date.in_time_zone("America/Toronto").utc
45
+ to_local(date).utc
46
+ end
47
+
48
+ def to_local(date, timezone: "America/Toronto")
49
+ date.in_time_zone(timezone)
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
46
70
  end
47
71
  end
48
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
@@ -13,5 +13,9 @@ module GoTransit
13
13
  def time_stamp_utc
14
14
  to_utc(time_stamp)
15
15
  end
16
+
17
+ def time_stamp_local
18
+ to_local(time_stamp)
19
+ end
16
20
  end
17
21
  end
@@ -2,4 +2,4 @@ module GoTransit
2
2
  class Schedule::Journey::SchJourney::Service::Transfer < ApiResource
3
3
  attr_accessor :code, :order, :time
4
4
  end
5
- end
5
+ 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
@@ -13,5 +13,13 @@ module GoTransit
13
13
  def end_time_utc
14
14
  to_utc(end_time)
15
15
  end
16
+
17
+ def start_time_local
18
+ to_local(start_time)
19
+ end
20
+
21
+ def end_time_local
22
+ to_local(end_time)
23
+ end
16
24
  end
17
25
  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
- end
21
+ end
@@ -5,5 +5,13 @@ module GoTransit
5
5
  def major?
6
6
  is_major.to_i.positive?
7
7
  end
8
+
9
+ def time_utc
10
+ to_utc(time)
11
+ end
12
+
13
+ def time_local
14
+ to_local(time)
15
+ end
8
16
  end
9
17
  end
@@ -1,13 +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
4
 
5
5
  def scheduled_utc
6
- to_utc(scheduled)
6
+ to_utc_from_anchor(scheduled, anchor_date)
7
+ end
8
+
9
+ def scheduled_local
10
+ to_local_from_anchor(scheduled, anchor_date)
7
11
  end
8
12
 
9
13
  def computed_utc
10
- to_utc(computed)
14
+ to_utc_from_anchor(computed, anchor_date)
15
+ end
16
+
17
+ def computed_local
18
+ to_local_from_anchor(computed, anchor_date)
11
19
  end
12
20
  end
13
21
  end
@@ -1,13 +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
4
 
5
5
  def scheduled_utc
6
- to_utc(scheduled)
6
+ to_utc_from_anchor(scheduled, anchor_date)
7
+ end
8
+
9
+ def scheduled_local
10
+ to_local_from_anchor(scheduled, anchor_date)
7
11
  end
8
12
 
9
13
  def computed_utc
10
- to_utc(computed)
14
+ to_utc_from_anchor(computed, anchor_date)
15
+ end
16
+
17
+ def computed_local
18
+ to_local_from_anchor(computed, anchor_date)
11
19
  end
12
20
  end
13
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
@@ -6,5 +6,13 @@ module GoTransit
6
6
  def time_stamp_utc
7
7
  to_utc(time_stamp)
8
8
  end
9
+
10
+ def time_stamp_local
11
+ to_local(time_stamp)
12
+ end
13
+
14
+ def anchor_date=(date)
15
+ stops.each { |stop| stop.anchor_date = date }
16
+ end
9
17
  end
10
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
@@ -14,5 +14,9 @@ module GoTransit
14
14
  def modified_date_utc
15
15
  to_utc(modified_date)
16
16
  end
17
+
18
+ def modified_date_local
19
+ to_local(modified_date)
20
+ end
17
21
  end
18
22
  end
@@ -7,5 +7,9 @@ module GoTransit
7
7
  def posted_date_time_utc
8
8
  to_utc(posted_date_time)
9
9
  end
10
+
11
+ def posted_date_time_local
12
+ to_local(posted_date_time)
13
+ end
10
14
  end
11
15
  end
@@ -11,5 +11,9 @@ module GoTransit
11
11
  def time_utc
12
12
  to_utc(time)
13
13
  end
14
+
15
+ def time_local
16
+ to_local(time)
17
+ end
14
18
  end
15
19
  end
@@ -18,5 +18,17 @@ module GoTransit
18
18
  def update_time_utc
19
19
  to_utc(update_time)
20
20
  end
21
+
22
+ def scheduled_departure_time_local
23
+ to_local(scheduled_departure_time)
24
+ end
25
+
26
+ def computed_departure_time_local
27
+ to_local(computed_departure_time)
28
+ end
29
+
30
+ def update_time_local
31
+ to_local(update_time)
32
+ end
21
33
  end
22
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.1.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.1.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