Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Style/StringLiterals:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
go_transit (1.1.0)
go_transit (1.2.0)
activesupport

GEM
Expand Down
6 changes: 5 additions & 1 deletion lib/go_transit/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def collection?(value)
end

def to_utc(date)
date.in_time_zone("America/Toronto").utc
to_local(date).utc
end

def to_local(date, timezone: "America/Toronto")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

date.in_time_zone(timezone)
end
end
end
4 changes: 4 additions & 0 deletions lib/go_transit/resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def code
def time_stamp_utc
to_utc(time_stamp)
end

def time_stamp_local
to_local(time_stamp)
end
end
end
2 changes: 1 addition & 1 deletion lib/go_transit/resources/schedule/journey/sch_journey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module GoTransit
class Schedule::Journey::SchJourney < ApiResource
attr_accessor :date, :time, :to, :from, :services
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ def start_time_utc
def end_time_utc
to_utc(end_time)
end

def start_time_local
to_local(start_time)
end

def end_time_local
to_local(end_time)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module GoTransit
class Schedule::Journey::SchJourney::Service::Transfer < ApiResource
attr_accessor :code, :order, :time
end
end
end
8 changes: 8 additions & 0 deletions lib/go_transit/resources/schedule/line/trip/stop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ class Schedule::Line::Trip::Stop < ApiResource
def major?
is_major.to_i.positive?
end

def time_utc
to_utc(time)
end

def time_local
to_local(time)
end
end
end
4 changes: 4 additions & 0 deletions lib/go_transit/resources/schedule/trip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ class Schedule::Trip < ApiResource
def time_stamp_utc
to_utc(time_stamp)
end

def time_stamp_local
to_local(time_stamp)
end
end
end
8 changes: 0 additions & 8 deletions lib/go_transit/resources/schedule/trip/stop/arrival_time.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module GoTransit
class Schedule::Trip::Stop::ArrivalTime < ApiResource
attr_accessor :scheduled, :computed, :status

def scheduled_utc
to_utc(scheduled)
end

def computed_utc
to_utc(computed)
end
end
end
8 changes: 0 additions & 8 deletions lib/go_transit/resources/schedule/trip/stop/departure_time.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module GoTransit
class Schedule::Trip::Stop::DepartureTime < ApiResource
attr_accessor :scheduled, :computed, :status

def scheduled_utc
to_utc(scheduled)
end

def computed_utc
to_utc(computed)
end
end
end
4 changes: 4 additions & 0 deletions lib/go_transit/resources/service_at_a_glance/trip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ def in_motion?
def modified_date_utc
to_utc(modified_date)
end

def modified_date_local
to_local(modified_date)
end
end
end
4 changes: 4 additions & 0 deletions lib/go_transit/resources/service_update/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ class ServiceUpdate::Message < ApiResource
def posted_date_time_utc
to_utc(posted_date_time)
end

def posted_date_time_local
to_local(posted_date_time)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def platforms
def time_utc
to_utc(time)
end

def time_local
to_local(time)
end
end
end
12 changes: 12 additions & 0 deletions lib/go_transit/resources/stop/next_service/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@ def computed_departure_time_utc
def update_time_utc
to_utc(update_time)
end

def scheduled_departure_time_local
to_local(scheduled_departure_time)
end

def computed_departure_time_local
to_local(computed_departure_time)
end

def update_time_local
to_local(update_time)
end
end
end
2 changes: 1 addition & 1 deletion lib/go_transit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GoTransit
VERSION = "1.1.0".freeze
VERSION = "1.2.0".freeze

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
21 changes: 16 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,22 @@ This gem exposes the Go Transit API endpoints and hydrates objects related to th

## Dates & Times
All dates & times returned from the GO Transit API are in the `America/Toronto`
timezone. All date and time fields have an additional method to convert into
UTC. For example `departure_time_utc` on a stop will return the regular
`departure_time` converted unto UTC.
timezone, returned as plain, unconverted strings, exactly as the API sent
them. Every date and time field has two additional methods: `_utc`
converts it into a UTC `Time`, and `_local` returns it as a proper
`ActiveSupport::TimeWithZone` in `America/Toronto`, without shifting the
value itself. For example, `departure_time_utc` on a stop returns the
regular `departure_time` converted to UTC, and `departure_time_local`
returns the same time zoned to Toronto instead.

## Missing Test Data
At the time of development I was unable to get test data for the following endpoints. Some of these seem like they are restricted access endpoints and my key is unable to fetch any data. I'm not sure if the others are caused by API issues. These endpoints *should* work assuming the documenation is correct, but the lack of data means testing was not possible. If you are able to get data for these endpoints please open a PR and submit it, it would greatly help development.
At the time of development I was unable to get test data for the following
endpoints. Some of these seem like they are restricted access endpoints and my
key is unable to fetch any data. I'm not sure if the others are caused by API
issues. These endpoints *should* work assuming the documenation is correct, but
the lack of data means testing was not possible. If you are able to get data for
these endpoints please open a PR and submit it, it would greatly help
development.

* `GET api/V1/ServiceataGlance/UPX/All` - 204 No Content
* `GET api/V1/ServiceUpdate/ServiceGuarantee/{TripNumber}/{OperationalDay}` - 204 No Content
Expand All @@ -89,7 +99,8 @@ At the time of development I was unable to get test data for the following endpo
* `GET api/V1/Fleet/Consist/Engine/{EngineNumber}` - 403 Forbidden

## Changing the API base url
In some cases you may want to change the base go transit API url. You can use the `custom_base_url` config to set one:
In some cases you may want to change the base go transit API url. You can use
the `custom_base_url` config to set one:

```ruby
GoTransit.configure do |config|
Expand Down
13 changes: 13 additions & 0 deletions spec/resources/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@
end
end
end

describe "#time_stamp_local" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "returns the timestamp zoned to toronto time, unshifted" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Timecop.travel("2023-09-14") do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

toronto_time = "2023-09-14 12:00:00"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

metadata = GoTransit::Metadata.new(time_stamp: toronto_time)

result = metadata.time_stamp_local

expect(result).to eq(toronto_time.in_time_zone("America/Toronto"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.describe GoTransit::Schedule::Journey::SchJourney::Service::Trip::Stop do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

describe "#major?" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

context "when is_major is 1" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "is major" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Journey::SchJourney::Service::Trip::Stop.new(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [81/80]

is_major: "1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

)

expect(stop).to be_major
end
end

context "when is_major is not 1" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "is not major" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Journey::SchJourney::Service::Trip::Stop.new(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [81/80]

is_major: "0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

)

expect(stop).not_to be_major
end
end
end
end
30 changes: 30 additions & 0 deletions spec/resources/schedule/journey/sch_journey/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,34 @@
end
end
end

describe "#start_time_local" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "returns the timestamp zoned to toronto time, unshifted" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Timecop.travel("2023-09-14") do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

toronto_time = "2023-09-17 12:00:00"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

service = GoTransit::Schedule::Journey::SchJourney::Service.new(
start_time: toronto_time
)

result = service.start_time_local

expect(result).to eq(toronto_time.in_time_zone("America/Toronto"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
end

describe "#end_time_local" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "returns the timestamp zoned to toronto time, unshifted" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Timecop.travel("2023-09-14") do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

toronto_time = "2023-09-17 12:00:00"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

service = GoTransit::Schedule::Journey::SchJourney::Service.new(
end_time: toronto_time
)

result = service.end_time_local

expect(result).to eq(toronto_time.in_time_zone("America/Toronto"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
end
end
45 changes: 45 additions & 0 deletions spec/resources/schedule/line/trip/stop_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
RSpec.describe GoTransit::Schedule::Line::Trip::Stop do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [34/25]
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

describe "#major?" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

context "when is_major is 1" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "is major" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Line::Trip::Stop.new(is_major: "1")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.


expect(stop).to be_major
end
end

context "when is_major is not 1" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "is not major" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Line::Trip::Stop.new(is_major: "0")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.


expect(stop).not_to be_major
end
end
end

describe "#time_utc" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "converts the timestamp from toronto time to UTC time" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Timecop.travel("2023-09-14") do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

toronto_time = "2023-09-17 12:00:00"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Line::Trip::Stop.new(time: toronto_time)

result = stop.time_utc

expect(result).to eq("2023-09-17 16:00:00".to_datetime)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
end

describe "#time_local" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "returns the timestamp zoned to toronto time, unshifted" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Timecop.travel("2023-09-14") do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

toronto_time = "2023-09-17 12:00:00"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

stop = GoTransit::Schedule::Line::Trip::Stop.new(time: toronto_time)

result = stop.time_local

expect(result).to eq(toronto_time.in_time_zone("America/Toronto"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
end
end
31 changes: 0 additions & 31 deletions spec/resources/schedule/trip/stop/arrival_time_spec.rb

This file was deleted.

31 changes: 0 additions & 31 deletions spec/resources/schedule/trip/stop/departure_time_spec.rb

This file was deleted.

Loading
Loading