Class: Weese::Bus::MetroBus

Inherits:
Object
  • Object
show all
Includes:
RequiresRoute, RequiresStop, Requests::Requester
Defined in:
lib/weese/bus/metro_bus.rb

Overview

MetroBus client. Used for accessing MetroBus-related WMATA APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequiresRoute

#incidents, #path, #positions, #route_schedule

Methods included from Requests::Requester

#fetch, #request

Methods included from RequiresStop

#next_buses, #stop_schedule

Constructor Details

#initialize(api_key) ⇒ MetroBus

MetroBus client. Used for accessing MetroBus related endpoints

Parameters:



23
24
25
# File 'lib/weese/bus/metro_bus.rb', line 23

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyString

Returns WMATA API key.

Returns:



16
17
18
# File 'lib/weese/bus/metro_bus.rb', line 16

def api_key
  @api_key
end

Instance Method Details

#routesHash

List of all bus route variants. WMATA Documentation

Returns:

  • (Hash)

    JSON Response

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/weese/bus/metro_bus.rb', line 35

def routes
  fetch(
    Requests::Request.new(
      @api_key,
      Bus::Urls::ROUTES,
      {}
    )
  )
end

#stops(radius_at_coordinates = nil) ⇒ Hash

Nearby bus stops based on latitude, longitude, and radius. WMATA Documentation

Parameters:

  • radius_at_coordinates (RadiusAtCoordinates) (defaults to: nil)

    A radius in meters around a lat/long

Returns:

  • (Hash)

    JSON Response

Raises:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/weese/bus/metro_bus.rb', line 55

def stops(radius_at_coordinates = nil)
  query = radius_at_coordinates ? radius_at_coordinates.to_h : {}

  fetch(
    Requests::Request.new(
      @api_key,
      Bus::Urls::STOPS,
      query
    )
  )
end