weese 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/weese/bus/metro_bus.rb +68 -0
- data/lib/weese/bus/route.rb +604 -0
- data/lib/weese/bus/stop.rb +72 -0
- data/lib/weese/bus/urls.rb +17 -0
- data/lib/weese/deserialize.rb +19 -0
- data/lib/weese/location.rb +57 -0
- data/lib/weese/rail/line.rb +86 -0
- data/lib/weese/rail/metro_rail.rb +123 -0
- data/lib/weese/rail/station.rb +282 -0
- data/lib/weese/rail/urls.rb +23 -0
- data/lib/weese/requests.rb +68 -0
- data/lib/weese/version.rb +6 -0
- data/lib/weese.rb +18 -0
- data/weese.gemspec +41 -0
- metadata +141 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
# Extension to String for deserializing JSON
|
|
6
|
+
class String
|
|
7
|
+
#
|
|
8
|
+
# Convert this {String} into a JSON Hash
|
|
9
|
+
#
|
|
10
|
+
# @raise [WeeseError] If JSON parse fails
|
|
11
|
+
#
|
|
12
|
+
# @return [Hash] Hash representing the given JSON
|
|
13
|
+
#
|
|
14
|
+
def deserialize
|
|
15
|
+
JSON.parse(self)
|
|
16
|
+
rescue JSON::ParserError => e
|
|
17
|
+
raise WeeseError, e.to_s
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Weese
|
|
4
|
+
# Classes relating to locations in latitude and longtidue, and radiuses in meters.
|
|
5
|
+
module Location
|
|
6
|
+
# A radius in meters at a {Coordinates}
|
|
7
|
+
class RadiusAtCoordinates
|
|
8
|
+
# @return [Numeric] Radius in meters around coordinates
|
|
9
|
+
attr_accessor :radius
|
|
10
|
+
# @return [Coordinates] A latitude and longitude
|
|
11
|
+
attr_accessor :coordinates
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Create a Radius at a Coordinates
|
|
15
|
+
#
|
|
16
|
+
# @param [Numeric] radius Distance in meters to check from the given coordinates
|
|
17
|
+
# @param [Coordinates] coordinates Latitude and Longitude to
|
|
18
|
+
#
|
|
19
|
+
def initialize(radius, coordinates)
|
|
20
|
+
@radius = radius
|
|
21
|
+
@coordinates = coordinates
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Converts this object to a hash
|
|
26
|
+
#
|
|
27
|
+
# @return [Hash] Hash containing radius, latitude and longitude
|
|
28
|
+
#
|
|
29
|
+
def to_h
|
|
30
|
+
{
|
|
31
|
+
radius: radius,
|
|
32
|
+
latitude: coordinates.latitude,
|
|
33
|
+
longitude: coordinates.longitude
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# A latitude and longitude
|
|
39
|
+
class Coordinates
|
|
40
|
+
# @return [Numeric] A latitude
|
|
41
|
+
attr_accessor :latitude
|
|
42
|
+
# @return [Numeric] A longitude
|
|
43
|
+
attr_accessor :longitude
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Creates a latitude and longitude pair
|
|
47
|
+
#
|
|
48
|
+
# @param [Numeric] latitude A latitude
|
|
49
|
+
# @param [Numeric] longitude A longitude
|
|
50
|
+
#
|
|
51
|
+
def initialize(latitude, longitude)
|
|
52
|
+
@latitude = latitude
|
|
53
|
+
@longitude = longitude
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Weese
|
|
4
|
+
module Rail
|
|
5
|
+
# WMATA Line Codes and Line helper methods
|
|
6
|
+
module Line
|
|
7
|
+
RD = 'RD' # Red line code
|
|
8
|
+
BL = 'BL' # Blue line code
|
|
9
|
+
YL = 'YL' # Yellow line code
|
|
10
|
+
OR = 'OR' # Orange line code
|
|
11
|
+
GR = 'GR' # Green line code
|
|
12
|
+
SV = 'SV' # Silver line code
|
|
13
|
+
YLRP = 'YLRP' # Yellow Line Rush Plus line code. Deprecated.
|
|
14
|
+
|
|
15
|
+
# Extensions to String relating to Lines
|
|
16
|
+
class String
|
|
17
|
+
#
|
|
18
|
+
# Checks if this {String} is a Line code
|
|
19
|
+
#
|
|
20
|
+
# @return [bool] If the current string is a Line Code
|
|
21
|
+
#
|
|
22
|
+
def line?
|
|
23
|
+
case self
|
|
24
|
+
when Line::RD, Line::BL, Line::YL, Line::YL, Line::OR, Line::GR, Line::SV, Line::YLRP
|
|
25
|
+
true
|
|
26
|
+
else
|
|
27
|
+
false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Line name for the current Line
|
|
33
|
+
#
|
|
34
|
+
# @return [String] Human-presentable Line name
|
|
35
|
+
#
|
|
36
|
+
def line_name
|
|
37
|
+
case self
|
|
38
|
+
when Line::RD
|
|
39
|
+
'Red'
|
|
40
|
+
when Line::BL
|
|
41
|
+
'Blue'
|
|
42
|
+
when Line::YL
|
|
43
|
+
'Yellow'
|
|
44
|
+
when Line::OR
|
|
45
|
+
'Orange'
|
|
46
|
+
when Line::GR
|
|
47
|
+
'Green'
|
|
48
|
+
when Line::SV
|
|
49
|
+
'Silver'
|
|
50
|
+
when Line::YLRP
|
|
51
|
+
'Yellow Line Rush Plus'
|
|
52
|
+
else
|
|
53
|
+
raise 'Invalid line'
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# These requests require a Line
|
|
60
|
+
module RequiresLine
|
|
61
|
+
include Requests::Requester
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
# Station location and address information for all stations on the given line.
|
|
65
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe330c WMATA Documentation}
|
|
66
|
+
#
|
|
67
|
+
# @param [String] line A Line code
|
|
68
|
+
#
|
|
69
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
70
|
+
#
|
|
71
|
+
# @return [Hash] JSON Response
|
|
72
|
+
#
|
|
73
|
+
def stations(line = nil)
|
|
74
|
+
query = line ? { LineCode: line } : {}
|
|
75
|
+
|
|
76
|
+
fetch(
|
|
77
|
+
Requests::Request.new(
|
|
78
|
+
@api_key,
|
|
79
|
+
Rail::Urls::STATIONS,
|
|
80
|
+
query
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'weese/requests'
|
|
4
|
+
require 'weese/rail/urls'
|
|
5
|
+
require 'weese/rail/station'
|
|
6
|
+
require 'weese/rail/line'
|
|
7
|
+
require 'weese/location'
|
|
8
|
+
|
|
9
|
+
module Weese
|
|
10
|
+
# Module containing everything MetroRail. Most important class: {MetroRail}.
|
|
11
|
+
module Rail
|
|
12
|
+
# MetroRail client. Used for accessing MetroRail-related WMATA APIs. See {RequiresLine} and {RequiresStation} for all API calls.
|
|
13
|
+
class MetroRail
|
|
14
|
+
include Requests::Requester
|
|
15
|
+
include Rail::RequiresStation
|
|
16
|
+
include Rail::RequiresLine
|
|
17
|
+
|
|
18
|
+
# @return [String] WMATA API key
|
|
19
|
+
attr_accessor :api_key
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# A MetroRail client, used for accessing all MetroRail-related APIs
|
|
23
|
+
#
|
|
24
|
+
# @param [String] api_key WMATA API Key, get one at {http://developer.wmata.com}
|
|
25
|
+
#
|
|
26
|
+
def initialize(api_key)
|
|
27
|
+
@api_key = api_key
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Basic information on all MetroRail lines.
|
|
32
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe330c WMATA Documentation}
|
|
33
|
+
#
|
|
34
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
35
|
+
#
|
|
36
|
+
# @return [Hash] Response JSON
|
|
37
|
+
#
|
|
38
|
+
def lines
|
|
39
|
+
fetch(
|
|
40
|
+
Requests::Request.new(
|
|
41
|
+
api_key,
|
|
42
|
+
Rail::Urls::LINES,
|
|
43
|
+
{}
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
# A list of nearby station entrances based on latitude, longitude, and radius (meters).
|
|
50
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe330f WMATA Documentation}
|
|
51
|
+
#
|
|
52
|
+
# @param [RadiusAtCoordinates] radius_at_coordinates Radius and lat/long to look around
|
|
53
|
+
#
|
|
54
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
55
|
+
#
|
|
56
|
+
# @return [Hash] Response JSON
|
|
57
|
+
#
|
|
58
|
+
def entrances(radius_at_coordinates)
|
|
59
|
+
fetch(
|
|
60
|
+
Requests::Request.new(
|
|
61
|
+
@api_key,
|
|
62
|
+
Rail::Urls::ENTRANCES,
|
|
63
|
+
radius_at_coordinates.to_h
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# Uniquely identifiable trains in service and what track circuits they currently occupy.
|
|
70
|
+
# {https://developer.wmata.com/docs/services/5763fa6ff91823096cac1057/operations/5763fb35f91823096cac1058 WMATA Documentation}
|
|
71
|
+
#
|
|
72
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
73
|
+
#
|
|
74
|
+
# @return [Hash] Response JSON
|
|
75
|
+
#
|
|
76
|
+
def positions
|
|
77
|
+
fetch(
|
|
78
|
+
Requests::Request.new(
|
|
79
|
+
@api_key,
|
|
80
|
+
Rail::Urls::POSITIONS,
|
|
81
|
+
contentType: 'json'
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Returns an ordered list of mostly revenue (and some lead) track circuits, arranged by line and track number.
|
|
88
|
+
# {https://developer.wmata.com/docs/services/5763fa6ff91823096cac1057/operations/57641afc031f59363c586dca WMATA Documentation}
|
|
89
|
+
#
|
|
90
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
91
|
+
#
|
|
92
|
+
# @return [Hash] Response JSON
|
|
93
|
+
#
|
|
94
|
+
def routes
|
|
95
|
+
fetch(
|
|
96
|
+
Requests::Request.new(
|
|
97
|
+
@api_key,
|
|
98
|
+
Rail::Urls::ROUTES,
|
|
99
|
+
contentType: 'json'
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#
|
|
105
|
+
# All track circuits including those on pocket tracks and crossovers. Each track circuit may include references to its right and left neighbors.
|
|
106
|
+
# {https://developer.wmata.com/docs/services/5763fa6ff91823096cac1057/operations/57644238031f59363c586dcb WMATA Documentation}
|
|
107
|
+
#
|
|
108
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
109
|
+
#
|
|
110
|
+
# @return [Hash] Response JSON
|
|
111
|
+
#
|
|
112
|
+
def circuits
|
|
113
|
+
fetch(
|
|
114
|
+
Requests::Request.new(
|
|
115
|
+
@api_key,
|
|
116
|
+
Rail::Urls::CIRCUITS,
|
|
117
|
+
contentType: 'json'
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Weese
|
|
4
|
+
module Rail
|
|
5
|
+
# Constants for WMATA station codes
|
|
6
|
+
module Station
|
|
7
|
+
A01 = 'A01' # A WMATA Station code
|
|
8
|
+
A02 = 'A02' # A WMATA Station code
|
|
9
|
+
A03 = 'A03' # A WMATA Station code
|
|
10
|
+
A04 = 'A04' # A WMATA Station code
|
|
11
|
+
A05 = 'A05' # A WMATA Station code
|
|
12
|
+
A06 = 'A06' # A WMATA Station code
|
|
13
|
+
A07 = 'A07' # A WMATA Station code
|
|
14
|
+
A08 = 'A08' # A WMATA Station code
|
|
15
|
+
A09 = 'A09' # A WMATA Station code
|
|
16
|
+
A10 = 'A10' # A WMATA Station code
|
|
17
|
+
A11 = 'A11' # A WMATA Station code
|
|
18
|
+
A12 = 'A12' # A WMATA Station code
|
|
19
|
+
A13 = 'A13' # A WMATA Station code
|
|
20
|
+
A14 = 'A14' # A WMATA Station code
|
|
21
|
+
A15 = 'A15' # A WMATA Station code
|
|
22
|
+
B01 = 'B01' # A WMATA Station code
|
|
23
|
+
B02 = 'B02' # A WMATA Station code
|
|
24
|
+
B03 = 'B03' # A WMATA Station code
|
|
25
|
+
B04 = 'B04' # A WMATA Station code
|
|
26
|
+
B05 = 'B05' # A WMATA Station code
|
|
27
|
+
B06 = 'B06' # A WMATA Station code
|
|
28
|
+
B07 = 'B07' # A WMATA Station code
|
|
29
|
+
B08 = 'B08' # A WMATA Station code
|
|
30
|
+
B09 = 'B09' # A WMATA Station code
|
|
31
|
+
B10 = 'B10' # A WMATA Station code
|
|
32
|
+
B11 = 'B11' # A WMATA Station code
|
|
33
|
+
B35 = 'B35' # A WMATA Station code
|
|
34
|
+
C01 = 'C01' # A WMATA Station code
|
|
35
|
+
C02 = 'C02' # A WMATA Station code
|
|
36
|
+
C03 = 'C03' # A WMATA Station code
|
|
37
|
+
C04 = 'C04' # A WMATA Station code
|
|
38
|
+
C05 = 'C05' # A WMATA Station code
|
|
39
|
+
C06 = 'C06' # A WMATA Station code
|
|
40
|
+
C07 = 'C07' # A WMATA Station code
|
|
41
|
+
C08 = 'C08' # A WMATA Station code
|
|
42
|
+
C09 = 'C09' # A WMATA Station code
|
|
43
|
+
C10 = 'C10' # A WMATA Station code
|
|
44
|
+
C12 = 'C12' # A WMATA Station code
|
|
45
|
+
C13 = 'C13' # A WMATA Station code
|
|
46
|
+
C14 = 'C14' # A WMATA Station code
|
|
47
|
+
C15 = 'C15' # A WMATA Station code
|
|
48
|
+
D01 = 'D01' # A WMATA Station code
|
|
49
|
+
D02 = 'D02' # A WMATA Station code
|
|
50
|
+
D03 = 'D03' # A WMATA Station code
|
|
51
|
+
D04 = 'D04' # A WMATA Station code
|
|
52
|
+
D05 = 'D05' # A WMATA Station code
|
|
53
|
+
D06 = 'D06' # A WMATA Station code
|
|
54
|
+
D07 = 'D07' # A WMATA Station code
|
|
55
|
+
D08 = 'D08' # A WMATA Station code
|
|
56
|
+
D09 = 'D09' # A WMATA Station code
|
|
57
|
+
D10 = 'D10' # A WMATA Station code
|
|
58
|
+
D11 = 'D11' # A WMATA Station code
|
|
59
|
+
D12 = 'D12' # A WMATA Station code
|
|
60
|
+
D13 = 'D13' # A WMATA Station code
|
|
61
|
+
E01 = 'E01' # A WMATA Station code
|
|
62
|
+
E02 = 'E02' # A WMATA Station code
|
|
63
|
+
E03 = 'E03' # A WMATA Station code
|
|
64
|
+
E04 = 'E04' # A WMATA Station code
|
|
65
|
+
E05 = 'E05' # A WMATA Station code
|
|
66
|
+
E06 = 'E06' # A WMATA Station code
|
|
67
|
+
E07 = 'E07' # A WMATA Station code
|
|
68
|
+
E08 = 'E08' # A WMATA Station code
|
|
69
|
+
E09 = 'E09' # A WMATA Station code
|
|
70
|
+
E10 = 'E10' # A WMATA Station code
|
|
71
|
+
F01 = 'F01' # A WMATA Station code
|
|
72
|
+
F02 = 'F02' # A WMATA Station code
|
|
73
|
+
F03 = 'F03' # A WMATA Station code
|
|
74
|
+
F04 = 'F04' # A WMATA Station code
|
|
75
|
+
F05 = 'F05' # A WMATA Station code
|
|
76
|
+
F06 = 'F06' # A WMATA Station code
|
|
77
|
+
F07 = 'F07' # A WMATA Station code
|
|
78
|
+
F08 = 'F08' # A WMATA Station code
|
|
79
|
+
F09 = 'F09' # A WMATA Station code
|
|
80
|
+
F10 = 'F10' # A WMATA Station code
|
|
81
|
+
F11 = 'F11' # A WMATA Station code
|
|
82
|
+
G01 = 'G01' # A WMATA Station code
|
|
83
|
+
G02 = 'G02' # A WMATA Station code
|
|
84
|
+
G03 = 'G03' # A WMATA Station code
|
|
85
|
+
G04 = 'G04' # A WMATA Station code
|
|
86
|
+
G05 = 'G05' # A WMATA Station code
|
|
87
|
+
J02 = 'J02' # A WMATA Station code
|
|
88
|
+
J03 = 'J03' # A WMATA Station code
|
|
89
|
+
K01 = 'K01' # A WMATA Station code
|
|
90
|
+
K02 = 'K02' # A WMATA Station code
|
|
91
|
+
K03 = 'K03' # A WMATA Station code
|
|
92
|
+
K04 = 'K04' # A WMATA Station code
|
|
93
|
+
K05 = 'K05' # A WMATA Station code
|
|
94
|
+
K06 = 'K06' # A WMATA Station code
|
|
95
|
+
K07 = 'K07' # A WMATA Station code
|
|
96
|
+
K08 = 'K08' # A WMATA Station code
|
|
97
|
+
N01 = 'N01' # A WMATA Station code
|
|
98
|
+
N02 = 'N02' # A WMATA Station code
|
|
99
|
+
N03 = 'N03' # A WMATA Station code
|
|
100
|
+
N04 = 'N04' # A WMATA Station code
|
|
101
|
+
N06 = 'N06' # A WMATA Station code
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# These requests require a Station
|
|
105
|
+
module RequiresStation
|
|
106
|
+
include Requests::Requester
|
|
107
|
+
|
|
108
|
+
#
|
|
109
|
+
# Distance, fare information, and estimated travel time between any two stations, including those on different lines.
|
|
110
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe3313 WMATA Documentation}
|
|
111
|
+
#
|
|
112
|
+
# @param [String] from_station Station code to start trip at. Optional.
|
|
113
|
+
# @param [String] to_destination_station Destination station code. Optional.
|
|
114
|
+
#
|
|
115
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
116
|
+
#
|
|
117
|
+
# @return [Hash] JSON Response
|
|
118
|
+
#
|
|
119
|
+
def station_to_station(from_station = nil, to_destination_station = nil)
|
|
120
|
+
query = {}
|
|
121
|
+
|
|
122
|
+
query['FromStationCode'] = from_station if from_station
|
|
123
|
+
|
|
124
|
+
query['ToStationCode'] = to_destination_station if to_destination_station
|
|
125
|
+
|
|
126
|
+
fetch(
|
|
127
|
+
Requests::Request.new(
|
|
128
|
+
@api_key,
|
|
129
|
+
Rail::Urls::STATION_TO_STATION,
|
|
130
|
+
query
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
#
|
|
136
|
+
# List of reported elevator and escalator outages at a given station.
|
|
137
|
+
# {https://developer.wmata.com/docs/services/54763641281d83086473f232/operations/54763641281d830c946a3d76 WMATA Documentation}
|
|
138
|
+
#
|
|
139
|
+
# @param [String] station A station code
|
|
140
|
+
#
|
|
141
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
142
|
+
#
|
|
143
|
+
# @return [Hash] JSON Response
|
|
144
|
+
#
|
|
145
|
+
def elevator_and_escalator_incidents(station = nil)
|
|
146
|
+
query = station ? { StationCode: station } : {}
|
|
147
|
+
|
|
148
|
+
fetch(
|
|
149
|
+
Requests::Request.new(
|
|
150
|
+
@api_key,
|
|
151
|
+
Rail::Urls::ELEVATOR_AND_ESCALATOR_INCIDENTS,
|
|
152
|
+
query
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
# Reported rail incidents (significant disruptions and delays to normal service)
|
|
159
|
+
# {https://developer.wmata.com/docs/services/54763641281d83086473f232/operations/54763641281d830c946a3d77 WMATA Documentation}
|
|
160
|
+
#
|
|
161
|
+
# @param [String] station A station code
|
|
162
|
+
#
|
|
163
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
164
|
+
#
|
|
165
|
+
# @return [Hash] JSON Response
|
|
166
|
+
#
|
|
167
|
+
def incidents(station = nil)
|
|
168
|
+
query = station ? { StationCode: station } : {}
|
|
169
|
+
|
|
170
|
+
fetch(
|
|
171
|
+
Requests::Request.new(
|
|
172
|
+
@api_key,
|
|
173
|
+
Rail::Urls::INCIDENTS,
|
|
174
|
+
query
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
#
|
|
180
|
+
# Next train arrivals for the given station.
|
|
181
|
+
# {https://developer.wmata.com/docs/services/547636a6f9182302184cda78/operations/547636a6f918230da855363f WMATA Documentation}
|
|
182
|
+
#
|
|
183
|
+
# @param [String] station A station code
|
|
184
|
+
#
|
|
185
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
186
|
+
#
|
|
187
|
+
# @return [Hash] JSON Response
|
|
188
|
+
#
|
|
189
|
+
def next_trains(station)
|
|
190
|
+
fetch(
|
|
191
|
+
Requests::Request.new(
|
|
192
|
+
@api_key,
|
|
193
|
+
[Rail::Urls::NEXT_TRAINS, station].join('/'),
|
|
194
|
+
{}
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
#
|
|
200
|
+
# Location and address information at the given station.
|
|
201
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe3310 WMATA Documentation}
|
|
202
|
+
#
|
|
203
|
+
# @param [String] station A station code
|
|
204
|
+
#
|
|
205
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
206
|
+
#
|
|
207
|
+
# @return [Hash] JSON Response
|
|
208
|
+
#
|
|
209
|
+
def station_information(station)
|
|
210
|
+
fetch(
|
|
211
|
+
Requests::Request.new(
|
|
212
|
+
@api_key,
|
|
213
|
+
Rail::Urls::INFORMATION,
|
|
214
|
+
StationCode: station
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
#
|
|
220
|
+
# Parking information for the given station.
|
|
221
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe330d WMATA Documentation}
|
|
222
|
+
#
|
|
223
|
+
# @param [String] station A station code
|
|
224
|
+
#
|
|
225
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
226
|
+
#
|
|
227
|
+
# @return [Hash] JSON Response
|
|
228
|
+
#
|
|
229
|
+
def parking_information(station)
|
|
230
|
+
fetch(
|
|
231
|
+
Requests::Request.new(
|
|
232
|
+
@api_key,
|
|
233
|
+
Rail::Urls::PARKING_INFORMATION,
|
|
234
|
+
StationCode: station
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
#
|
|
240
|
+
# Stations and distances between two stations on the same line.
|
|
241
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe330e WMATA Documentation}
|
|
242
|
+
#
|
|
243
|
+
# @param [String] station Starting station code
|
|
244
|
+
# @param [String] to_destination_station Destination station code
|
|
245
|
+
#
|
|
246
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
247
|
+
#
|
|
248
|
+
# @return [Hash] JSON Response
|
|
249
|
+
#
|
|
250
|
+
def path_from(station, to_destination_station)
|
|
251
|
+
fetch(
|
|
252
|
+
Requests::Request.new(
|
|
253
|
+
@api_key,
|
|
254
|
+
Rail::Urls::PATH,
|
|
255
|
+
FromStationCode: station,
|
|
256
|
+
ToStationCode: to_destination_station
|
|
257
|
+
)
|
|
258
|
+
)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
#
|
|
262
|
+
# Opening and scheduled first/last train times for the given station.
|
|
263
|
+
# {https://developer.wmata.com/docs/services/5476364f031f590f38092507/operations/5476364f031f5909e4fe3312 WMATA Documentation}
|
|
264
|
+
#
|
|
265
|
+
# @param [String] station A station code
|
|
266
|
+
#
|
|
267
|
+
# @raise [WeeseError] If request or JSON parse fails
|
|
268
|
+
#
|
|
269
|
+
# @return [Hash] JSON Response
|
|
270
|
+
#
|
|
271
|
+
def timings(station)
|
|
272
|
+
fetch(
|
|
273
|
+
Requests::Request.new(
|
|
274
|
+
@api_key,
|
|
275
|
+
Rail::Urls::TIMINGS,
|
|
276
|
+
StationCode: station
|
|
277
|
+
)
|
|
278
|
+
)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Weese
|
|
4
|
+
module Rail
|
|
5
|
+
# URLS for MetroRail related endpoints
|
|
6
|
+
module Urls
|
|
7
|
+
LINES = 'https://api.wmata.com/Rail.svc/json/jLines' # WMATA Endpoints
|
|
8
|
+
ENTRANCES = 'https://api.wmata.com/Rail.svc/json/jStationEntrances' # WMATA Endpoints
|
|
9
|
+
POSITIONS = 'https://api.wmata.com/TrainPositions/TrainPositions' # WMATA Endpoints
|
|
10
|
+
ROUTES = 'https://api.wmata.com/TrainPositions/StandardRoutes' # WMATA Endpoints
|
|
11
|
+
CIRCUITS = 'https://api.wmata.com/TrainPositions/TrackCircuits' # WMATA Endpoints
|
|
12
|
+
ELEVATOR_AND_ESCALATOR_INCIDENTS = 'https://api.wmata.com/Incidents.svc/json/ElevatorIncidents' # WMATA Endpoints
|
|
13
|
+
INCIDENTS = 'https://api.wmata.com/Incidents.svc/json/Incidents' # WMATA Endpoints
|
|
14
|
+
NEXT_TRAINS = 'https://api.wmata.com/StationPrediction.svc/json/GetPrediction/' # WMATA Endpoints
|
|
15
|
+
INFORMATION = 'https://api.wmata.com/Rail.svc/json/jStationInfo' # WMATA Endpoints
|
|
16
|
+
PARKING_INFORMATION = 'https://api.wmata.com/Rail.svc/json/jStationParking' # WMATA Endpoints
|
|
17
|
+
PATH = 'https://api.wmata.com/Rail.svc/json/jPath' # WMATA Endpoints
|
|
18
|
+
TIMINGS = 'https://api.wmata.com/Rail.svc/json/jStationTimes' # WMATA Endpoints
|
|
19
|
+
STATION_TO_STATION = 'https://api.wmata.com/Rail.svc/json/jSrcStationToDstStationInfo' # WMATA Endpoints
|
|
20
|
+
STATIONS = 'https://api.wmata.com/Rail.svc/json/jStations' # WMATA Endpoint
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'weese/deserialize'
|
|
5
|
+
|
|
6
|
+
module Weese
|
|
7
|
+
# Structures related to making API requests
|
|
8
|
+
module Requests
|
|
9
|
+
# Everything needed to make an HTTP request
|
|
10
|
+
class Request
|
|
11
|
+
# @return [String] WMATA API key
|
|
12
|
+
attr_accessor :api_key
|
|
13
|
+
# @return [String] URL
|
|
14
|
+
attr_accessor :path
|
|
15
|
+
# @return [Hash] Query parameters
|
|
16
|
+
attr_accessor :query
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Create a Request
|
|
20
|
+
#
|
|
21
|
+
# @param [String] api_key API key to make this Request with
|
|
22
|
+
# @param [String] path URL to make Request to
|
|
23
|
+
# @param [Hash] query Query parameters to append to Request
|
|
24
|
+
#
|
|
25
|
+
def initialize(api_key, path, query)
|
|
26
|
+
@api_key = api_key
|
|
27
|
+
@path = path
|
|
28
|
+
@query = query
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Actually making the HTTP request
|
|
33
|
+
module Requester
|
|
34
|
+
#
|
|
35
|
+
# Make a request to WMATA API
|
|
36
|
+
#
|
|
37
|
+
# @param [Request] wmata_request Request to send to WMATA API
|
|
38
|
+
#
|
|
39
|
+
# @raise [WeeseError] If the requests fails in any way
|
|
40
|
+
#
|
|
41
|
+
# @return [String] Body of response
|
|
42
|
+
#
|
|
43
|
+
def request(wmata_request)
|
|
44
|
+
response = Faraday.get(wmata_request.path) do |request|
|
|
45
|
+
request.params = wmata_request.query
|
|
46
|
+
request.headers['api_key'] = wmata_request.api_key
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
return response.body if response.success?
|
|
50
|
+
|
|
51
|
+
raise WeeseError, "#{response.status}, #{response.body}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#
|
|
55
|
+
# Makes a request to WMATA API & deserializes the response into a Hash
|
|
56
|
+
#
|
|
57
|
+
# @param [Request] wmata_request Request to send to WMATA API
|
|
58
|
+
#
|
|
59
|
+
# @raise [WeeseError] If the requests fails in any way
|
|
60
|
+
#
|
|
61
|
+
# @return [Hash] Hash of response JSON
|
|
62
|
+
#
|
|
63
|
+
def fetch(wmata_request)
|
|
64
|
+
request(wmata_request).deserialize
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
data/lib/weese.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'weese/version'
|
|
4
|
+
|
|
5
|
+
require 'weese/rail/metro_rail'
|
|
6
|
+
require 'weese/rail/line'
|
|
7
|
+
require 'weese/rail/station'
|
|
8
|
+
|
|
9
|
+
require 'weese/bus/metro_bus'
|
|
10
|
+
require 'weese/bus/route'
|
|
11
|
+
require 'weese/bus/stop'
|
|
12
|
+
|
|
13
|
+
require 'weese/location'
|
|
14
|
+
|
|
15
|
+
module Weese
|
|
16
|
+
# Error output buy all functions in this gem
|
|
17
|
+
class WeeseError < StandardError; end
|
|
18
|
+
end
|