go_transit 1.0.2 → 1.2.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: ca67b4c62a86192aa19a8b7461f868df809dae60a943ff0d7c90dcc00bc036f4
4
- data.tar.gz: ff33fdcf0cdbd1a51c0d44070980489e5f846ad7f05cf24a0619f31fe8397b62
3
+ metadata.gz: 7b30c2d11058a8d509c7950071d7392ecbdf56463063613da290604125ca67f0
4
+ data.tar.gz: 2906067cbfd752a3e5c7182459015f5a6843ecec6badd49a2ec0746a3ebbce35
5
5
  SHA512:
6
- metadata.gz: 3263a94c43424ab0ef6f36907cd95b372ffee7503d0e3a601d05e8500c13136639bf790054ca0de5dc83608b99d7d48ddba792f41f62975db3345edd6996efeb
7
- data.tar.gz: 9455209aab1e8bd6502ee86bb279cf50d98a97ceb3941e21d7f37eed68d61c13fe32d0d42ac53ef12ff9d67375137d021f96eb89b037adff8247b5aa30b99b76
6
+ metadata.gz: ac888ca4fe0a81be3390d69b117a790cb3129d523e46a9c496dd5a8a04736ebfe295f9b10dc65ae532c344bcc96516d7c90abefb810872ee0e6c6282aadfaef3
7
+ data.tar.gz: aa24ae455d0fa37299ebe2bc7209d4eaa8495e92bb79a454a8a96f57e2227452f2051548a9859d3438d83f1c0c5cc599ff683b7164fcf5a4b1aa24111740e75c
@@ -42,7 +42,11 @@ 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)
46
50
  end
47
51
  end
48
52
  end
@@ -8,9 +8,17 @@ module GoTransit
8
8
  def get(path)
9
9
  uri = URI("#{GoTransit.base_url}/#{API_VERSION}/#{path}"\
10
10
  "?key=#{GoTransit.api_key}")
11
- response = Net::HTTP.get_response(uri)
12
- json = JSON.parse(response.body)
13
- Response.new(json)
11
+ http_response = Net::HTTP.get_response(uri)
12
+ Response.new(parse_body(http_response), http_response.code.to_i)
13
+ end
14
+
15
+ private
16
+
17
+ def parse_body(http_response)
18
+ JSON.parse(http_response.body)
19
+ rescue JSON::ParserError
20
+ { "Metadata" => { "ErrorCode" => http_response.code,
21
+ "ErrorMessage" => http_response.message } }
14
22
  end
15
23
  end
16
24
  end
@@ -10,4 +10,5 @@ module GoTransit
10
10
  UnauthorizedError = Class.new(ApiError)
11
11
  ForbiddenError = Class.new(ApiError)
12
12
  NotFoundError = Class.new(ApiError)
13
+ TooManyRequestsError = Class.new(ApiError)
13
14
  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
@@ -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
@@ -2,4 +2,4 @@ module GoTransit
2
2
  class Schedule::Journey::SchJourney < ApiResource
3
3
  attr_accessor :date, :time, :to, :from, :services
4
4
  end
5
- end
5
+ 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,5 @@
1
1
  module GoTransit
2
2
  class Schedule::Trip::Stop::ArrivalTime < ApiResource
3
3
  attr_accessor :scheduled, :computed, :status
4
-
5
- def scheduled_utc
6
- to_utc(scheduled)
7
- end
8
-
9
- def computed_utc
10
- to_utc(computed)
11
- end
12
4
  end
13
5
  end
@@ -1,13 +1,5 @@
1
1
  module GoTransit
2
2
  class Schedule::Trip::Stop::DepartureTime < ApiResource
3
3
  attr_accessor :scheduled, :computed, :status
4
-
5
- def scheduled_utc
6
- to_utc(scheduled)
7
- end
8
-
9
- def computed_utc
10
- to_utc(computed)
11
- end
12
4
  end
13
5
  end
@@ -6,5 +6,9 @@ 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
9
13
  end
10
14
  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
@@ -4,26 +4,39 @@ module GoTransit
4
4
 
5
5
  delegate :code, :error_message, to: :metadata
6
6
 
7
- def initialize(payload)
8
- @metadata = Metadata.new(payload.delete("Metadata"))
7
+ def initialize(payload, http_status = nil)
8
+ @http_status = http_status
9
+ @metadata = Metadata.new(payload.delete("Metadata") || fallback_metadata)
9
10
  @data = payload_data(payload)
10
11
  throw_error
11
12
  end
12
13
 
13
14
  private
14
15
 
16
+ attr_reader :http_status
17
+
18
+ def fallback_metadata
19
+ { "ErrorCode" => http_status.to_s, "ErrorMessage" => "HTTP #{http_status}" }
20
+ end
21
+
15
22
  def payload_data(payload)
16
23
  return payload.values.first unless payload.values.first.kind_of?(Array)
17
24
  payload
18
25
  end
19
26
 
20
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
+ raise TooManyRequestsError.new(metadata) if http_status == 429
21
33
  return if code == 200
22
34
  raise NoContentError.new(metadata) if code == 204
23
35
  raise BadRequestError.new(metadata) if code == 400
24
36
  raise UnauthorizedError.new(metadata) if code == 401
25
37
  raise ForbiddenError.new(metadata) if code == 403
26
38
  raise NotFoundError.new(metadata) if code == 404
39
+ raise TooManyRequestsError.new(metadata) if code == 429
27
40
  raise StandardError.new(metadata)
28
41
  end
29
42
  end
@@ -1,3 +1,3 @@
1
1
  module GoTransit
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
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.0.2
4
+ version: 1.2.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: 2025-04-07 00:00:00.000000000 Z
11
+ date: 2026-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '0.17'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0.17'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: timecop
127
127
  requirement: !ruby/object:Gem::Requirement