go_transit 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/go_transit/api_resource.rb +44 -0
  3. data/lib/go_transit/client.rb +16 -0
  4. data/lib/go_transit/errors.rb +13 -0
  5. data/lib/go_transit/resources/fare/fare_category/ticket/fare.rb +5 -0
  6. data/lib/go_transit/resources/fare/fare_category/ticket.rb +5 -0
  7. data/lib/go_transit/resources/fare/fare_category.rb +5 -0
  8. data/lib/go_transit/resources/fare.rb +17 -0
  9. data/lib/go_transit/resources/metadata.rb +9 -0
  10. data/lib/go_transit/resources/schedule/all_lines/line/variant.rb +5 -0
  11. data/lib/go_transit/resources/schedule/all_lines/line.rb +5 -0
  12. data/lib/go_transit/resources/schedule/all_lines.rb +18 -0
  13. data/lib/go_transit/resources/schedule/journey/sch_journey/service/link.rb +6 -0
  14. data/lib/go_transit/resources/schedule/journey/sch_journey/service/transfer.rb +5 -0
  15. data/lib/go_transit/resources/schedule/journey/sch_journey/service/trip/stop.rb +9 -0
  16. data/lib/go_transit/resources/schedule/journey/sch_journey/service/trip.rb +8 -0
  17. data/lib/go_transit/resources/schedule/journey/sch_journey/service.rb +9 -0
  18. data/lib/go_transit/resources/schedule/journey/sch_journey.rb +5 -0
  19. data/lib/go_transit/resources/schedule/journey.rb +11 -0
  20. data/lib/go_transit/resources/schedule/line/trip/stop.rb +9 -0
  21. data/lib/go_transit/resources/schedule/line/trip.rb +5 -0
  22. data/lib/go_transit/resources/schedule/line.rb +5 -0
  23. data/lib/go_transit/resources/schedule/trip/stop/arrival_time.rb +5 -0
  24. data/lib/go_transit/resources/schedule/trip/stop/departure_time.rb +5 -0
  25. data/lib/go_transit/resources/schedule/trip/stop/track.rb +5 -0
  26. data/lib/go_transit/resources/schedule/trip/stop.rb +6 -0
  27. data/lib/go_transit/resources/schedule/trip.rb +6 -0
  28. data/lib/go_transit/resources/schedule.rb +31 -0
  29. data/lib/go_transit/resources/service_at_a_glance/trip.rb +14 -0
  30. data/lib/go_transit/resources/service_at_a_glance.rb +29 -0
  31. data/lib/go_transit/resources/service_update/exceptions/trip/stop.rb +19 -0
  32. data/lib/go_transit/resources/service_update/exceptions/trip.rb +14 -0
  33. data/lib/go_transit/resources/service_update/exceptions.rb +29 -0
  34. data/lib/go_transit/resources/service_update/message/line.rb +5 -0
  35. data/lib/go_transit/resources/service_update/message/stop.rb +5 -0
  36. data/lib/go_transit/resources/service_update/message/trip.rb +5 -0
  37. data/lib/go_transit/resources/service_update/message.rb +7 -0
  38. data/lib/go_transit/resources/service_update/service_guarantee/stop.rb +5 -0
  39. data/lib/go_transit/resources/service_update/service_guarantee.rb +11 -0
  40. data/lib/go_transit/resources/service_update/union_departures/trip/stop.rb +5 -0
  41. data/lib/go_transit/resources/service_update/union_departures/trip.rb +10 -0
  42. data/lib/go_transit/resources/service_update/union_departures.rb +11 -0
  43. data/lib/go_transit/resources/service_update.rb +41 -0
  44. data/lib/go_transit/resources/stop/destination/line.rb +5 -0
  45. data/lib/go_transit/resources/stop/destination.rb +11 -0
  46. data/lib/go_transit/resources/stop/facility.rb +5 -0
  47. data/lib/go_transit/resources/stop/line.rb +5 -0
  48. data/lib/go_transit/resources/stop/next_service/line.rb +10 -0
  49. data/lib/go_transit/resources/stop/next_service.rb +11 -0
  50. data/lib/go_transit/resources/stop/parking.rb +5 -0
  51. data/lib/go_transit/resources/stop/place/stop.rb +5 -0
  52. data/lib/go_transit/resources/stop/place.rb +5 -0
  53. data/lib/go_transit/resources/stop/station.rb +14 -0
  54. data/lib/go_transit/resources/stop.rb +41 -0
  55. data/lib/go_transit/response.rb +30 -0
  56. data/lib/go_transit/version.rb +3 -0
  57. data/lib/go_transit.rb +67 -0
  58. metadata +210 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b427876f28482bccc9bc67073baaa1909bad6d3e5e72d9a04f2d17fdeda5ed6f
4
+ data.tar.gz: fc02cfe20e250e6132debe7144bf0e024d2e4bd0e3abb03036f9e1024a2d47eb
5
+ SHA512:
6
+ metadata.gz: 07432de000d4d7acd545153d575c243581aae65f9f76851e106bd21951a901779162118453048c15bc51f792b60daffb1a02c02d648c8dd9f8fb18e4cd684aa9
7
+ data.tar.gz: 5e0b9da7d99f54b9ac820a6939fdc8e81cd642eb65f6f2fd55c0d23e94fa3d8700e6c8502b7dc14d5e71fc1947ad18d21610b7a6ae5744c71beb66677932c74f
@@ -0,0 +1,44 @@
1
+ module GoTransit
2
+ class ApiResource
3
+ def initialize(params)
4
+ hydrate(params)
5
+ end
6
+
7
+ private
8
+
9
+ def hydrate(params)
10
+ params.each_pair do |key, value|
11
+ if collection?(value)
12
+ sub_key, sub_value = value.first
13
+ key = sub_key.pluralize
14
+ value = build_object(sub_key.singularize, sub_value)
15
+ elsif value.kind_of?(Hash)
16
+ value = build_object(key, value)
17
+ elsif value.kind_of?(Array)
18
+ value = build_object(key.singularize, value)
19
+ key = key.pluralize
20
+ end
21
+ send("#{key.to_s.underscore}=", value)
22
+ end
23
+ end
24
+
25
+ def build_object(name, params)
26
+ klass = get_klass(name)
27
+ if params.kind_of?(Array)
28
+ params.map { |param| klass.new(param) }
29
+ else
30
+ klass.new(params)
31
+ end
32
+ end
33
+
34
+ def get_klass(name)
35
+ Object.const_get("#{self.class.name}::#{name}")
36
+ end
37
+
38
+ def collection?(value)
39
+ return false unless value.kind_of?(Hash)
40
+ key, data = value.first
41
+ data.kind_of?(Array)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+ require "json"
2
+ require "net/http"
3
+
4
+ module GoTransit
5
+ class Client
6
+ BASE_URL = "http://api.openmetrolinx.com/OpenDataAPI/api".freeze
7
+ API_VERSION = "V1".freeze
8
+
9
+ def get(path)
10
+ uri = URI("#{BASE_URL}/#{API_VERSION}/#{path}?key=#{GoTransit.api_key}")
11
+ response = Net::HTTP.get_response(uri)
12
+ json = JSON.parse(response.body)
13
+ Response.new(json)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module GoTransit
2
+ class ApiError < StandardError
3
+ def initialize(metadata)
4
+ @message = metadata.error_message
5
+ end
6
+ end
7
+
8
+ NoContentError = Class.new(ApiError)
9
+ BadRequestError = Class.new(StandardError)
10
+ UnauthorizedError = Class.new(StandardError)
11
+ ForbiddenError = Class.new(StandardError)
12
+ NotFoundError = Class.new(StandardError)
13
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Fare::FareCategory::Ticket::Fare < ApiResource
3
+ attr_accessor :type, :amount, :category
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Fare::FareCategory::Ticket < ApiResource
3
+ attr_accessor :type, :fares
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Fare::FareCategory < ApiResource
3
+ attr_accessor :type, :tickets
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module GoTransit
2
+ class Fare < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :fare_categories
6
+
7
+ def self.get(from_stop_code:, to_stop_code:, operational_day: nil)
8
+ client = Client.new
9
+ response = client.get("Fares/#{from_stop_code}/#{to_stop_code}/#{operational_day}")
10
+ new(response.data)
11
+ end
12
+
13
+ def each(&block)
14
+ fare_categories.each(&block)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module GoTransit
2
+ class Metadata < ApiResource
3
+ attr_accessor :time_stamp, :error_code, :error_message
4
+
5
+ def code
6
+ error_code.to_i
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::AllLines::Line::Variant < ApiResource
3
+ attr_accessor :code, :display, :direction
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::AllLines::Line < ApiResource
3
+ attr_accessor :name, :code, :is_bus, :is_train, :variants
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module GoTransit
2
+ class Schedule::AllLines < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :lines
6
+
7
+ def self.all(date:)
8
+ formatted_date = date.strftime("%Y%m%d")
9
+ client = Client.new
10
+ response = client.get("Schedule/Line/All/#{formatted_date}")
11
+ new(response.data)
12
+ end
13
+
14
+ def each(&block)
15
+ lines.each(&block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney::Service::Link < ApiResource
3
+ attr_accessor :from_trip, :from_stop_code, :to_trip, :to_stop_code,
4
+ :transfer_duration
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney::Service::Transfer < ApiResource
3
+ attr_accessor :code, :order, :time
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney::Service::Trip::Stop < ApiResource
3
+ attr_accessor :code, :order, :time, :sorting_time, :is_major
4
+
5
+ def major?
6
+ is_major.to_i.positive?
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney::Service::Trip < ApiResource
3
+ attr_accessor :number, :display, :line, :direction, :line_variant,
4
+ :type, :stops, :destination_stop_code, :depart_from_code,
5
+ :depart_from_alternative_code, :depart_from_timing_point,
6
+ :trip_pattern_id
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney::Service < ApiResource
3
+ attr_accessor :colour, :type, :direction, :code, :start_time, :end_time,
4
+ :duration, :accessible, :trips, :transfers, :links,
5
+ :start_sort_time, :end_sort_time, :trip_hash, :transfer_count
6
+
7
+ alias :transfer_links :links
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Journey::SchJourney < ApiResource
3
+ attr_accessor :date, :time, :to, :from, :services
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module GoTransit
2
+ class Schedule::Journey < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :sch_journeys
6
+
7
+ def each(&block)
8
+ sch_journeys.each(&block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module GoTransit
2
+ class Schedule::Line::Trip::Stop < ApiResource
3
+ attr_accessor :code, :order, :time, :sorting_time, :is_major
4
+
5
+ def major?
6
+ is_major.to_i.positive?
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Line::Trip < ApiResource
3
+ attr_accessor :number, :display, :stops
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Line < ApiResource
3
+ attr_accessor :code, :direction, :type, :trips
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Trip::Stop::ArrivalTime < ApiResource
3
+ attr_accessor :scheduled, :computed, :status
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Trip::Stop::DepartureTime < ApiResource
3
+ attr_accessor :scheduled, :computed, :status
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Schedule::Trip::Stop::Track < ApiResource
3
+ attr_accessor :scheduled, :actual
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module GoTransit
2
+ class Schedule::Trip::Stop < ApiResource
3
+ attr_accessor :arrival_time, :departure_time, :track, :code, :status,
4
+ :remark
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module GoTransit
2
+ class Schedule::Trip < ApiResource
3
+ attr_accessor :number, :destination, :longitude, :latitude, :status,
4
+ :time_stamp, :stops
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ module GoTransit
2
+ class Schedule < ApiResource
3
+ attr_accessor :lines, :trips
4
+
5
+ def self.journey(date:, from_stop_code:, to_stop_code:, start_time:,
6
+ max_journey:)
7
+ formatted_date = date.strftime("%Y%m%d")
8
+ client = Client.new
9
+ response = client.get(
10
+ "Schedule/Journey/#{formatted_date}/#{from_stop_code}/" +
11
+ "#{to_stop_code}/#{start_time}/#{max_journey}"
12
+ )
13
+ Schedule::Journey.new(response.data)
14
+ end
15
+
16
+ def self.line(date:, line_code:, line_direction:)
17
+ formatted_date = date.strftime("%Y%m%d")
18
+ client = Client.new
19
+ response = client.get(
20
+ "Schedule/Line/#{formatted_date}/#{line_code}/#{line_direction}"
21
+ )
22
+ new(response.data).lines
23
+ end
24
+
25
+ def self.trip(date:, trip_number:)
26
+ client = Client.new
27
+ response = client.get("Schedule/Trip/#{date}/#{trip_number}")
28
+ new(response.data).trips
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module GoTransit
2
+ class ServiceAtAGlance::Trip < ApiResource
3
+ attr_accessor :bus_type, :cars, :trip_number, :start_time,
4
+ :end_time, :line_code, :route_number, :variant_dir,
5
+ :display, :latitude, :longitude, :is_in_motion,
6
+ :delay_seconds, :course, :first_stop_code, :last_stop_code,
7
+ :prev_stop_code, :next_stop_code, :at_station_code,
8
+ :modified_date, :occupancy_percentage
9
+
10
+ def in_motion?
11
+ is_in_motion.to_i.positive?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module GoTransit
2
+ class ServiceAtAGlance < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :trips
6
+
7
+ def self.buses
8
+ client = Client.new
9
+ response = client.get("ServiceataGlance/Buses/All")
10
+ new(response.data)
11
+ end
12
+
13
+ def self.trains
14
+ client = Client.new
15
+ response = client.get("ServiceataGlance/Trains/All")
16
+ new(response.data)
17
+ end
18
+
19
+ def self.upx
20
+ client = Client.new
21
+ response = client.get("ServiceataGlance/UPX/All")
22
+ new(response.data)
23
+ end
24
+
25
+ def each(&block)
26
+ trips.each(&block)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Exceptions::Trip::Stop < ApiResource
3
+ attr_accessor :order, :id, :sch_arrival, :sch_departure, :name,
4
+ :is_stopping, :is_cancelled, :is_override, :code,
5
+ :actual_time, :service_type
6
+
7
+ def stopping?
8
+ is_stopping.to_i.positive?
9
+ end
10
+
11
+ def cancelled?
12
+ is_cancelled.to_i.positive?
13
+ end
14
+
15
+ def override?
16
+ is_override.to_i.positive?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Exceptions::Trip < ApiResource
3
+ attr_accessor :trip_number, :trip_name, :is_cancelled, :is_override,
4
+ :stops
5
+
6
+ def cancelled?
7
+ is_cancelled.to_i.positive?
8
+ end
9
+
10
+ def override?
11
+ is_override.to_i.positive?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Exceptions < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :trips
6
+
7
+ def self.train
8
+ client = Client.new
9
+ response = client.get("ServiceUpdate/Exceptions/Train")
10
+ new(response.data)
11
+ end
12
+
13
+ def self.bus
14
+ client = Client.new
15
+ response = client.get("ServiceUpdate/Exceptions/Bus")
16
+ new(response.data)
17
+ end
18
+
19
+ def self.all
20
+ client = Client.new
21
+ response = client.get("ServiceUpdate/Exceptions/All")
22
+ new(response.data)
23
+ end
24
+
25
+ def each(&block)
26
+ trips.each(&block)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Message::Line < ApiResource
3
+ attr_accessor :code
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Message::Stop < ApiResource
3
+ attr_accessor :code, :name
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Message::Trip < ApiResource
3
+ attr_accessor :trip_number
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module GoTransit
2
+ class ServiceUpdate::Message < ApiResource
3
+ attr_accessor :code, :parent_code, :status, :posted_date_time,
4
+ :subject_english, :subject_french, :body_english,
5
+ :body_french, :category, :sub_category, :lines, :stops, :trips
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class ServiceUpdate::ServiceGuarantee::Stop < ApiResource
3
+ attr_accessor :code, :scope, :reason_en, :reason_fr
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module GoTransit
2
+ class ServiceUpdate::ServiceGuarantee < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :stops
6
+
7
+ def each(&block)
8
+ stops.each(&block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class ServiceUpdate::UnionDepartures::Trip::Stop < ApiResource
3
+ attr_accessor :name, :code
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module GoTransit
2
+ class ServiceUpdate::UnionDepartures::Trip < ApiResource
3
+ attr_accessor :info, :trip_number, :platform, :service, :service_type,
4
+ :time, :stops
5
+
6
+ def platforms
7
+ platform.split("&").collect(&:strip)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module GoTransit
2
+ class ServiceUpdate::UnionDepartures < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :trips
6
+
7
+ def each(&block)
8
+ trips.each(&block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module GoTransit
2
+ class ServiceUpdate < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :messages
6
+
7
+ def self.service_alerts
8
+ client = Client.new
9
+ response = client.get("ServiceUpdate/ServiceAlert/All")
10
+ new(response.data)
11
+ end
12
+
13
+ def self.information_alerts
14
+ client = Client.new
15
+ response = client.get("ServiceUpdate/InformationAlert/All")
16
+ new(response.data)
17
+ end
18
+
19
+ def self.marketing_alerts
20
+ client = Client.new
21
+ response = client.get("ServiceUpdate/MarketingAlert/All")
22
+ new(response.data)
23
+ end
24
+
25
+ def self.union_departures
26
+ client = Client.new
27
+ response = client.get("ServiceUpdate/UnionDepartures/All")
28
+ ServiceUpdate::UnionDepartures.new(response.data)
29
+ end
30
+
31
+ def self.service_guarantee(trip_number:, operational_day:)
32
+ client = Client.new
33
+ response = client.get("ServiceUpdate/ServiceGuarantee/#{trip_number}/#{operational_day}")
34
+ ServiceUpdate::ServiceGuarantee.new(response.data)
35
+ end
36
+
37
+ def each(&block)
38
+ messages.each(&block)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Destination::Line < ApiResource
3
+ attr_accessor :code, :display, :direction, :destination_stop
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module GoTransit
2
+ class Stop::Destination < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :code, :name, :lines
6
+
7
+ def each(&block)
8
+ lines.each(&block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Facility < ApiResource
3
+ attr_accessor :code, :description, :description_fr
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Line < ApiResource
3
+ attr_accessor :code, :display, :direction, :destination_stop
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module GoTransit
2
+ class Stop::NextService::Line < ApiResource
3
+ attr_accessor :stop_code, :line_code, :line_name, :service_type,
4
+ :direction_code, :direction_name,
5
+ :scheduled_departure_time, :computed_departure_time,
6
+ :departure_status, :scheduled_platform, :actual_platform,
7
+ :trip_order, :trip_number, :update_time, :status,
8
+ :latitude, :longitude
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module GoTransit
2
+ class Stop::NextService < ApiResource
3
+ include Enumerable
4
+
5
+ attr_accessor :lines
6
+
7
+ def each(&block)
8
+ lines.each(&block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Parking < ApiResource
3
+ attr_accessor :name, :name_fr, :park_spots, :type
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Place::Stop < ApiResource
3
+ attr_accessor :code, :name, :name_fr
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module GoTransit
2
+ class Stop::Place < ApiResource
3
+ attr_accessor :code, :name, :longitude, :latitude, :radius, :stops
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module GoTransit
2
+ class Stop::Station < ApiResource
3
+ attr_accessor :location_code, :public_stop_id, :location_name,
4
+ :location_type
5
+
6
+ def train?
7
+ location_type.include?("Train")
8
+ end
9
+
10
+ def bus?
11
+ location_type.include?("Bus")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module GoTransit
2
+ class Stop < ApiResource
3
+ attr_accessor :zone_code, :street_number, :intersection, :city, :street_name,
4
+ :code, :stop_name, :stop_name_fr, :is_bus, :is_train, :longitude,
5
+ :latitude, :driving_directions, :driving_directions_fr,
6
+ :boarding_info, :boarding_info_fr, :ticket_sales, :ticket_sales_fr,
7
+ :facilities, :parkings, :place, :stations, :lines, :name
8
+
9
+ def self.all
10
+ client = Client.new
11
+ response = client.get("Stop/All")
12
+ new(response.data).stations
13
+ end
14
+
15
+ def self.details(stop_code:)
16
+ client = Client.new
17
+ response = client.get("Stop/Details/#{stop_code}")
18
+ new(response.data)
19
+ end
20
+
21
+ def self.next_service(stop_code:)
22
+ client = Client.new
23
+ response = client.get("Stop/NextService/#{stop_code}")
24
+ Stop::NextService.new(response.data)
25
+ end
26
+
27
+ def self.destinations(stop_code:, from_time:, to_time:)
28
+ client = Client.new
29
+ response = client.get("Stop/Destinations/#{stop_code}/#{from_time}/#{to_time}")
30
+ Stop::Destination.new(response.data)
31
+ end
32
+
33
+ def bus?
34
+ is_bus.to_i.positive?
35
+ end
36
+
37
+ def train?
38
+ is_train.to_i.positive?
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ module GoTransit
2
+ class Response
3
+ attr_reader :metadata, :data
4
+
5
+ delegate :code, :error_message, to: :metadata
6
+
7
+ def initialize(payload)
8
+ @metadata = Metadata.new(payload.delete("Metadata"))
9
+ @data = payload_data(payload)
10
+ throw_error
11
+ end
12
+
13
+ private
14
+
15
+ def payload_data(payload)
16
+ return payload.values.first unless payload.values.first.kind_of?(Array)
17
+ payload
18
+ end
19
+
20
+ def throw_error
21
+ return if code == 200
22
+ raise NoContentError.new(metadata) if code == 204
23
+ raise BadRequestError.new(metadata) if code == 400
24
+ raise UnauthorizedError.new(metadata) if code == 401
25
+ raise ForbiddenError.new(metadata) if code == 403
26
+ raise NotFoundError.new(metadata) if code == 404
27
+ raise StandardError.new(metadata)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module GoTransit
2
+ VERSION = "0.6.0"
3
+ end
data/lib/go_transit.rb ADDED
@@ -0,0 +1,67 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+ require "active_support/core_ext/string"
5
+
6
+ require "go_transit/client"
7
+ require "go_transit/errors"
8
+ require "go_transit/response"
9
+ require "go_transit/api_resource"
10
+ require "go_transit/resources/metadata"
11
+ require "go_transit/resources/stop"
12
+ require "go_transit/resources/stop/station"
13
+ require "go_transit/resources/stop/next_service"
14
+ require "go_transit/resources/stop/next_service/line"
15
+ require "go_transit/resources/stop/line"
16
+ require "go_transit/resources/stop/facility"
17
+ require "go_transit/resources/stop/parking"
18
+ require "go_transit/resources/stop/place"
19
+ require "go_transit/resources/stop/place/stop"
20
+ require "go_transit/resources/stop/destination"
21
+ require "go_transit/resources/stop/destination/line"
22
+ require "go_transit/resources/service_at_a_glance"
23
+ require "go_transit/resources/service_at_a_glance/trip"
24
+ require "go_transit/resources/service_update"
25
+ require "go_transit/resources/service_update/message"
26
+ require "go_transit/resources/service_update/message/line"
27
+ require "go_transit/resources/service_update/message/stop"
28
+ require "go_transit/resources/service_update/message/trip"
29
+ require "go_transit/resources/service_update/union_departures"
30
+ require "go_transit/resources/service_update/union_departures/trip"
31
+ require "go_transit/resources/service_update/union_departures/trip/stop"
32
+ require "go_transit/resources/service_update/service_guarantee"
33
+ require "go_transit/resources/service_update/service_guarantee/stop"
34
+ require "go_transit/resources/service_update/exceptions"
35
+ require "go_transit/resources/service_update/exceptions/trip"
36
+ require "go_transit/resources/service_update/exceptions/trip/stop"
37
+ require "go_transit/resources/fare"
38
+ require "go_transit/resources/fare/fare_category"
39
+ require "go_transit/resources/fare/fare_category/ticket"
40
+ require "go_transit/resources/fare/fare_category/ticket/fare"
41
+ require "go_transit/resources/schedule"
42
+ require "go_transit/resources/schedule/trip"
43
+ require "go_transit/resources/schedule/trip/stop"
44
+ require "go_transit/resources/schedule/trip/stop/arrival_time"
45
+ require "go_transit/resources/schedule/trip/stop/departure_time"
46
+ require "go_transit/resources/schedule/trip/stop/track"
47
+ require "go_transit/resources/schedule/line"
48
+ require "go_transit/resources/schedule/line/trip"
49
+ require "go_transit/resources/schedule/line/trip/stop"
50
+ require "go_transit/resources/schedule/all_lines"
51
+ require "go_transit/resources/schedule/all_lines/line"
52
+ require "go_transit/resources/schedule/all_lines/line/variant"
53
+ require "go_transit/resources/schedule/journey"
54
+ require "go_transit/resources/schedule/journey/sch_journey"
55
+ require "go_transit/resources/schedule/journey/sch_journey/service"
56
+ require "go_transit/resources/schedule/journey/sch_journey/service/link"
57
+ require "go_transit/resources/schedule/journey/sch_journey/service/transfer"
58
+ require "go_transit/resources/schedule/journey/sch_journey/service/trip"
59
+ require "go_transit/resources/schedule/journey/sch_journey/service/trip/stop"
60
+
61
+ module GoTransit
62
+ @api_key = ""
63
+
64
+ class << self
65
+ attr_accessor :api_key
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_transit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Mazur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: '0.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: '0.17'
125
+ description:
126
+ email:
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - lib/go_transit.rb
132
+ - lib/go_transit/api_resource.rb
133
+ - lib/go_transit/client.rb
134
+ - lib/go_transit/errors.rb
135
+ - lib/go_transit/resources/fare.rb
136
+ - lib/go_transit/resources/fare/fare_category.rb
137
+ - lib/go_transit/resources/fare/fare_category/ticket.rb
138
+ - lib/go_transit/resources/fare/fare_category/ticket/fare.rb
139
+ - lib/go_transit/resources/metadata.rb
140
+ - lib/go_transit/resources/schedule.rb
141
+ - lib/go_transit/resources/schedule/all_lines.rb
142
+ - lib/go_transit/resources/schedule/all_lines/line.rb
143
+ - lib/go_transit/resources/schedule/all_lines/line/variant.rb
144
+ - lib/go_transit/resources/schedule/journey.rb
145
+ - lib/go_transit/resources/schedule/journey/sch_journey.rb
146
+ - lib/go_transit/resources/schedule/journey/sch_journey/service.rb
147
+ - lib/go_transit/resources/schedule/journey/sch_journey/service/link.rb
148
+ - lib/go_transit/resources/schedule/journey/sch_journey/service/transfer.rb
149
+ - lib/go_transit/resources/schedule/journey/sch_journey/service/trip.rb
150
+ - lib/go_transit/resources/schedule/journey/sch_journey/service/trip/stop.rb
151
+ - lib/go_transit/resources/schedule/line.rb
152
+ - lib/go_transit/resources/schedule/line/trip.rb
153
+ - lib/go_transit/resources/schedule/line/trip/stop.rb
154
+ - lib/go_transit/resources/schedule/trip.rb
155
+ - lib/go_transit/resources/schedule/trip/stop.rb
156
+ - lib/go_transit/resources/schedule/trip/stop/arrival_time.rb
157
+ - lib/go_transit/resources/schedule/trip/stop/departure_time.rb
158
+ - lib/go_transit/resources/schedule/trip/stop/track.rb
159
+ - lib/go_transit/resources/service_at_a_glance.rb
160
+ - lib/go_transit/resources/service_at_a_glance/trip.rb
161
+ - lib/go_transit/resources/service_update.rb
162
+ - lib/go_transit/resources/service_update/exceptions.rb
163
+ - lib/go_transit/resources/service_update/exceptions/trip.rb
164
+ - lib/go_transit/resources/service_update/exceptions/trip/stop.rb
165
+ - lib/go_transit/resources/service_update/message.rb
166
+ - lib/go_transit/resources/service_update/message/line.rb
167
+ - lib/go_transit/resources/service_update/message/stop.rb
168
+ - lib/go_transit/resources/service_update/message/trip.rb
169
+ - lib/go_transit/resources/service_update/service_guarantee.rb
170
+ - lib/go_transit/resources/service_update/service_guarantee/stop.rb
171
+ - lib/go_transit/resources/service_update/union_departures.rb
172
+ - lib/go_transit/resources/service_update/union_departures/trip.rb
173
+ - lib/go_transit/resources/service_update/union_departures/trip/stop.rb
174
+ - lib/go_transit/resources/stop.rb
175
+ - lib/go_transit/resources/stop/destination.rb
176
+ - lib/go_transit/resources/stop/destination/line.rb
177
+ - lib/go_transit/resources/stop/facility.rb
178
+ - lib/go_transit/resources/stop/line.rb
179
+ - lib/go_transit/resources/stop/next_service.rb
180
+ - lib/go_transit/resources/stop/next_service/line.rb
181
+ - lib/go_transit/resources/stop/parking.rb
182
+ - lib/go_transit/resources/stop/place.rb
183
+ - lib/go_transit/resources/stop/place/stop.rb
184
+ - lib/go_transit/resources/stop/station.rb
185
+ - lib/go_transit/response.rb
186
+ - lib/go_transit/version.rb
187
+ homepage: https://github.com/jmazur/go-transit-ruby
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: 2.3.0
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubygems_version: 3.4.13
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Ruby Interface for the Go Transit API
210
+ test_files: []