Class: OnebusawaySDK::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/onebusaway_sdk/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: ENV["ONEBUSAWAY_API_KEY"], base_url: ENV["ONEBUSAWAY_SDK_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["ONEBUSAWAY_API_KEY"])

    Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["ONEBUSAWAY_SDK_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/onebusaway_sdk/client.rb', line 126

def initialize(
  api_key: ENV["ONEBUSAWAY_API_KEY"],
  base_url: ENV["ONEBUSAWAY_SDK_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= "https://api.pugetsound.onebusaway.org"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"ONEBUSAWAY_API_KEY\"")
  end

  @api_key = api_key.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )

  @agencies_with_coverage = OnebusawaySDK::Resources::AgenciesWithCoverage.new(client: self)
  @agency = OnebusawaySDK::Resources::Agency.new(client: self)
  @vehicles_for_agency = OnebusawaySDK::Resources::VehiclesForAgency.new(client: self)
  @config = OnebusawaySDK::Resources::Config.new(client: self)
  @current_time = OnebusawaySDK::Resources::CurrentTime.new(client: self)
  @stops_for_location = OnebusawaySDK::Resources::StopsForLocation.new(client: self)
  @stops_for_route = OnebusawaySDK::Resources::StopsForRoute.new(client: self)
  @stops_for_agency = OnebusawaySDK::Resources::StopsForAgency.new(client: self)
  @stop = OnebusawaySDK::Resources::Stop.new(client: self)
  @stop_ids_for_agency = OnebusawaySDK::Resources::StopIDsForAgency.new(client: self)
  @schedule_for_stop = OnebusawaySDK::Resources::ScheduleForStop.new(client: self)
  @route = OnebusawaySDK::Resources::Route.new(client: self)
  @route_ids_for_agency = OnebusawaySDK::Resources::RouteIDsForAgency.new(client: self)
  @routes_for_location = OnebusawaySDK::Resources::RoutesForLocation.new(client: self)
  @routes_for_agency = OnebusawaySDK::Resources::RoutesForAgency.new(client: self)
  @schedule_for_route = OnebusawaySDK::Resources::ScheduleForRoute.new(client: self)
  @arrival_and_departure = OnebusawaySDK::Resources::ArrivalAndDeparture.new(client: self)
  @trip = OnebusawaySDK::Resources::Trip.new(client: self)
  @trips_for_location = OnebusawaySDK::Resources::TripsForLocation.new(client: self)
  @trip_details = OnebusawaySDK::Resources::TripDetails.new(client: self)
  @trip_for_vehicle = OnebusawaySDK::Resources::TripForVehicle.new(client: self)
  @trips_for_route = OnebusawaySDK::Resources::TripsForRoute.new(client: self)
  @report_problem_with_stop = OnebusawaySDK::Resources::ReportProblemWithStop.new(client: self)
  @report_problem_with_trip = OnebusawaySDK::Resources::ReportProblemWithTrip.new(client: self)
  @search_for_stop = OnebusawaySDK::Resources::SearchForStop.new(client: self)
  @search_for_route = OnebusawaySDK::Resources::SearchForRoute.new(client: self)
  @block = OnebusawaySDK::Resources::Block.new(client: self)
  @shape = OnebusawaySDK::Resources::Shape.new(client: self)
end

Instance Attribute Details

#agencies_with_coverageOnebusawaySDK::Resources::AgenciesWithCoverage (readonly)



22
23
24
# File 'lib/onebusaway_sdk/client.rb', line 22

def agencies_with_coverage
  @agencies_with_coverage
end

#agencyOnebusawaySDK::Resources::Agency (readonly)



25
26
27
# File 'lib/onebusaway_sdk/client.rb', line 25

def agency
  @agency
end

#api_keyString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/onebusaway_sdk/client.rb', line 19

def api_key
  @api_key
end

#arrival_and_departureOnebusawaySDK::Resources::ArrivalAndDeparture (readonly)



70
71
72
# File 'lib/onebusaway_sdk/client.rb', line 70

def arrival_and_departure
  @arrival_and_departure
end

#blockOnebusawaySDK::Resources::Block (readonly)



100
101
102
# File 'lib/onebusaway_sdk/client.rb', line 100

def block
  @block
end

#configOnebusawaySDK::Resources::Config (readonly)



31
32
33
# File 'lib/onebusaway_sdk/client.rb', line 31

def config
  @config
end

#current_timeOnebusawaySDK::Resources::CurrentTime (readonly)



34
35
36
# File 'lib/onebusaway_sdk/client.rb', line 34

def current_time
  @current_time
end

#report_problem_with_stopOnebusawaySDK::Resources::ReportProblemWithStop (readonly)



88
89
90
# File 'lib/onebusaway_sdk/client.rb', line 88

def report_problem_with_stop
  @report_problem_with_stop
end

#report_problem_with_tripOnebusawaySDK::Resources::ReportProblemWithTrip (readonly)



91
92
93
# File 'lib/onebusaway_sdk/client.rb', line 91

def report_problem_with_trip
  @report_problem_with_trip
end

#routeOnebusawaySDK::Resources::Route (readonly)



55
56
57
# File 'lib/onebusaway_sdk/client.rb', line 55

def route
  @route
end

#route_ids_for_agencyOnebusawaySDK::Resources::RouteIDsForAgency (readonly)



58
59
60
# File 'lib/onebusaway_sdk/client.rb', line 58

def route_ids_for_agency
  @route_ids_for_agency
end

#routes_for_agencyOnebusawaySDK::Resources::RoutesForAgency (readonly)



64
65
66
# File 'lib/onebusaway_sdk/client.rb', line 64

def routes_for_agency
  @routes_for_agency
end

#routes_for_locationOnebusawaySDK::Resources::RoutesForLocation (readonly)



61
62
63
# File 'lib/onebusaway_sdk/client.rb', line 61

def routes_for_location
  @routes_for_location
end

#schedule_for_routeOnebusawaySDK::Resources::ScheduleForRoute (readonly)



67
68
69
# File 'lib/onebusaway_sdk/client.rb', line 67

def schedule_for_route
  @schedule_for_route
end

#schedule_for_stopOnebusawaySDK::Resources::ScheduleForStop (readonly)



52
53
54
# File 'lib/onebusaway_sdk/client.rb', line 52

def schedule_for_stop
  @schedule_for_stop
end

#search_for_routeOnebusawaySDK::Resources::SearchForRoute (readonly)



97
98
99
# File 'lib/onebusaway_sdk/client.rb', line 97

def search_for_route
  @search_for_route
end

#search_for_stopOnebusawaySDK::Resources::SearchForStop (readonly)



94
95
96
# File 'lib/onebusaway_sdk/client.rb', line 94

def search_for_stop
  @search_for_stop
end

#shapeOnebusawaySDK::Resources::Shape (readonly)



103
104
105
# File 'lib/onebusaway_sdk/client.rb', line 103

def shape
  @shape
end

#stopOnebusawaySDK::Resources::Stop (readonly)



46
47
48
# File 'lib/onebusaway_sdk/client.rb', line 46

def stop
  @stop
end

#stop_ids_for_agencyOnebusawaySDK::Resources::StopIDsForAgency (readonly)



49
50
51
# File 'lib/onebusaway_sdk/client.rb', line 49

def stop_ids_for_agency
  @stop_ids_for_agency
end

#stops_for_agencyOnebusawaySDK::Resources::StopsForAgency (readonly)



43
44
45
# File 'lib/onebusaway_sdk/client.rb', line 43

def stops_for_agency
  @stops_for_agency
end

#stops_for_locationOnebusawaySDK::Resources::StopsForLocation (readonly)



37
38
39
# File 'lib/onebusaway_sdk/client.rb', line 37

def stops_for_location
  @stops_for_location
end

#stops_for_routeOnebusawaySDK::Resources::StopsForRoute (readonly)



40
41
42
# File 'lib/onebusaway_sdk/client.rb', line 40

def stops_for_route
  @stops_for_route
end

#tripOnebusawaySDK::Resources::Trip (readonly)



73
74
75
# File 'lib/onebusaway_sdk/client.rb', line 73

def trip
  @trip
end

#trip_detailsOnebusawaySDK::Resources::TripDetails (readonly)



79
80
81
# File 'lib/onebusaway_sdk/client.rb', line 79

def trip_details
  @trip_details
end

#trip_for_vehicleOnebusawaySDK::Resources::TripForVehicle (readonly)



82
83
84
# File 'lib/onebusaway_sdk/client.rb', line 82

def trip_for_vehicle
  @trip_for_vehicle
end

#trips_for_locationOnebusawaySDK::Resources::TripsForLocation (readonly)



76
77
78
# File 'lib/onebusaway_sdk/client.rb', line 76

def trips_for_location
  @trips_for_location
end

#trips_for_routeOnebusawaySDK::Resources::TripsForRoute (readonly)



85
86
87
# File 'lib/onebusaway_sdk/client.rb', line 85

def trips_for_route
  @trips_for_route
end

#vehicles_for_agencyOnebusawaySDK::Resources::VehiclesForAgency (readonly)



28
29
30
# File 'lib/onebusaway_sdk/client.rb', line 28

def vehicles_for_agency
  @vehicles_for_agency
end