Class: Weese::Rail::MetroRail

Inherits:
Object
  • Object
show all
Includes:
RequiresLine, RequiresStation, Weese::Requests::Requester
Defined in:
lib/weese/rail/metro_rail.rb

Overview

MetroRail client. Used for accessing MetroRail-related WMATA APIs. See RequiresLine and RequiresStation for all API calls.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequiresLine

#stations

Methods included from Weese::Requests::Requester

#fetch, #request

Methods included from RequiresStation

#elevator_and_escalator_incidents, #incidents, #next_trains, #parking_information, #path_from, #station_information, #station_to_station, #timings

Constructor Details

#initialize(api_key) ⇒ MetroRail

A MetroRail client, used for accessing all MetroRail-related APIs

Parameters:



26
27
28
# File 'lib/weese/rail/metro_rail.rb', line 26

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyString

Returns WMATA API key.

Returns:



19
20
21
# File 'lib/weese/rail/metro_rail.rb', line 19

def api_key
  @api_key
end

Instance Method Details

#circuitsHash

All track circuits including those on pocket tracks and crossovers. Each track circuit may include references to its right and left neighbors. WMATA Documentation

Returns:

  • (Hash)

    Response JSON

Raises:



112
113
114
115
116
117
118
119
120
# File 'lib/weese/rail/metro_rail.rb', line 112

def circuits
  fetch(
    Requests::Request.new(
      @api_key,
      Rail::Urls::CIRCUITS,
      contentType: 'json'
    )
  )
end

#entrances(radius_at_coordinates) ⇒ Hash

A list of nearby station entrances based on latitude, longitude, and radius (meters). WMATA Documentation

Parameters:

  • radius_at_coordinates (RadiusAtCoordinates)

    Radius and lat/long to look around

Returns:

  • (Hash)

    Response JSON

Raises:



58
59
60
61
62
63
64
65
66
# File 'lib/weese/rail/metro_rail.rb', line 58

def entrances(radius_at_coordinates)
  fetch(
    Requests::Request.new(
      @api_key,
      Rail::Urls::ENTRANCES,
      radius_at_coordinates.to_h
    )
  )
end

#linesHash

Basic information on all MetroRail lines. WMATA Documentation

Returns:

  • (Hash)

    Response JSON

Raises:



38
39
40
41
42
43
44
45
46
# File 'lib/weese/rail/metro_rail.rb', line 38

def lines
  fetch(
    Requests::Request.new(
      api_key,
      Rail::Urls::LINES,
      {}
    )
  )
end

#positionsHash

Uniquely identifiable trains in service and what track circuits they currently occupy. WMATA Documentation

Returns:

  • (Hash)

    Response JSON

Raises:



76
77
78
79
80
81
82
83
84
# File 'lib/weese/rail/metro_rail.rb', line 76

def positions
  fetch(
    Requests::Request.new(
      @api_key,
      Rail::Urls::POSITIONS,
      contentType: 'json'
    )
  )
end

#routesHash

Returns an ordered list of mostly revenue (and some lead) track circuits, arranged by line and track number. WMATA Documentation

Returns:

  • (Hash)

    Response JSON

Raises:



94
95
96
97
98
99
100
101
102
# File 'lib/weese/rail/metro_rail.rb', line 94

def routes
  fetch(
    Requests::Request.new(
      @api_key,
      Rail::Urls::ROUTES,
      contentType: 'json'
    )
  )
end