dcmetro 0.0.2 → 0.0.3
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 +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -0
- data/.travis.yml +14 -0
- data/README.md +32 -2
- data/Rakefile +9 -1
- data/dcmetro.gemspec +4 -2
- data/features/alerts.feature +9 -0
- data/features/external.feature +43 -0
- data/features/lines.feature +21 -0
- data/features/station.feature +18 -0
- data/features/step_definitions/api_test_steps.rb +28 -0
- data/features/support/env.rb +24 -0
- data/lib/dcmetro/cli/application.rb +59 -10
- data/lib/dcmetro/version.rb +14 -2
- data/lib/dcmetro.rb +119 -39
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc313326de3ac26b92b875af66674b2ca9a38a30
|
4
|
+
data.tar.gz: ac7a212cd6cec05143267728e2e7c66b5a949074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2c0675d498fdb34f53900671a11af6442efd934e0b318804c470a26bdb3b182d82dda92e08e4fb23bbd88f6065f0c7ce4ab5e1c41177a478a00a697ee5aef8c
|
7
|
+
data.tar.gz: e48582d557f17e3d75cc9af0fe576f35864db2f18456c17f0f893d782aa5c835745bbec403538dad9050d69ac92f4230c8365d0e8a58ce6f0c5937ec16840466
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# DCMetro
|
1
|
+
# DCMetro
|
2
|
+
[](http://badge.fury.io/rb/dcmetro)
|
3
|
+
[](https://travis-ci.org/kencrocken/dcmetro)
|
4
|
+
[](https://coveralls.io/github/kencrocken/dcmetro?branch=master)
|
2
5
|
|
3
6
|
Rails class and a command line interface to access the Washington, D.C. Metro Rail API. Returns the systemwide alerts, lines, stations and arrival times for the lines at each station.
|
4
7
|
|
@@ -18,6 +21,17 @@ Or install it yourself as:
|
|
18
21
|
|
19
22
|
$ gem install dcmetro
|
20
23
|
|
24
|
+
####An ENV variable must be set either in your shell for the CLI or where ever you keep such variables in your Rails apps.
|
25
|
+
|
26
|
+
The variable needs to be set to `DCMETRO_KEY`
|
27
|
+
|
28
|
+
It is recommended that a key is requested from https://developer.wmata.com/
|
29
|
+
|
30
|
+
For the CLI, in the `.bash_profile` set the following:
|
31
|
+
`EXPORT DCMETRO_KEY = <<replace with api key from WMATA>>`
|
32
|
+
|
33
|
+
Don't forget to `source .bash_profile` after making the changes.
|
34
|
+
|
21
35
|
## Usage
|
22
36
|
###Rails App
|
23
37
|
|
@@ -49,9 +63,25 @@ Commands:
|
|
49
63
|
dcmetro alerts # Display DC Metro system wide alerts.
|
50
64
|
dcmetro help [COMMAND] # Describe available commands or one specific command
|
51
65
|
dcmetro line COLOR # Display metro rail lines, if COLOR, displays rail stations on the COLOR line
|
52
|
-
dcmetro station
|
66
|
+
dcmetro station STARTING,DEST # Display metro station train arrival and departure times and travel info.
|
53
67
|
```
|
54
68
|
|
69
|
+
### CHANGELOG
|
70
|
+
##### Changes in 0.0.2
|
71
|
+
|
72
|
+
1. Updates the api calls to the new format
|
73
|
+
2. Fixes a bug if multiple stations are returned
|
74
|
+
3. Requires the use of an env variable for the API key
|
75
|
+
4. Requires rest-client
|
76
|
+
##### Changes in 0.0.3
|
77
|
+
|
78
|
+
1. Adds station to station travel information
|
79
|
+
2. Expanded test coverage
|
80
|
+
3. Refactors code so that the Information Class merely returns information
|
81
|
+
Any parsing is now done in the CLI application
|
82
|
+
|
83
|
+
# Bug: If no stations are returned app pukes
|
84
|
+
# Bug: Pentagon and Pentagon City confuses app
|
55
85
|
|
56
86
|
## Contributing
|
57
87
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'cucumber'
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
7
|
+
t.cucumber_opts = "DCMETRO_KEY=#{ENV['DCMETRO_KEY']} features --format pretty"
|
8
|
+
end
|
9
|
+
|
2
10
|
|
data/dcmetro.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Dcmetro::VERSION
|
9
9
|
spec.authors = ["Ken Crocken"]
|
10
10
|
spec.email = ["kcrocken@gmail.com"]
|
11
|
-
spec.summary = %q{Returns DC Metro information, including train schedules.}
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Returns DC Metro Rails information, including train schedules.}
|
12
|
+
spec.description = %q{Washington, DC Metro Rails information, including lines, stations and arrival/departure predictions.}
|
13
13
|
spec.homepage = "https://github.com/kencrocken/dcmetro"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "aruba"
|
28
|
+
spec.add_development_dependency "coveralls"
|
27
29
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
@check
|
2
|
+
Feature: External calls to WMATA api
|
3
|
+
|
4
|
+
When I call WMATA api
|
5
|
+
Then the response should be "200"
|
6
|
+
And should return "JSON"
|
7
|
+
And should contain "the desired information"
|
8
|
+
|
9
|
+
|
10
|
+
Scenario: Check Alerts
|
11
|
+
When I send a GET request for "WMATA Alerts"
|
12
|
+
Then the response should be "200"
|
13
|
+
Then should return "JSON"
|
14
|
+
And should contain "Incidents"
|
15
|
+
|
16
|
+
Scenario: Check Lines
|
17
|
+
When I send a GET request for "WMATA Lines"
|
18
|
+
Then the response should be "200"
|
19
|
+
And should return "JSON"
|
20
|
+
And should contain "Lines"
|
21
|
+
|
22
|
+
Scenario: Check Stations on a Line
|
23
|
+
When I send a GET request for "WMATA Lines Red"
|
24
|
+
Then the response should be "200"
|
25
|
+
And should return "JSON"
|
26
|
+
And should contain "Stations"
|
27
|
+
|
28
|
+
Scenario: Check Stations arrival/departure times
|
29
|
+
When I send a GET request for "WMATA Station Gallery"
|
30
|
+
Then the response should be "200"
|
31
|
+
And should return "JSON"
|
32
|
+
And should contain "Line"
|
33
|
+
And should contain "DestinationName"
|
34
|
+
And should contain "Min"
|
35
|
+
|
36
|
+
@wip
|
37
|
+
Scenario: Check travel time, distance and fare between two stations
|
38
|
+
When I send a GET request for "WMATA Station Gallery College"
|
39
|
+
Then the response should be "200"
|
40
|
+
And should return "JSON"
|
41
|
+
And should contain "CompositeMiles"
|
42
|
+
And should contain "RailFare"
|
43
|
+
And should contain "RailTime"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: check dcmetro lines
|
2
|
+
|
3
|
+
In order to check lines
|
4
|
+
When I run `dcmetro lines`
|
5
|
+
Then metro lines should be displayed
|
6
|
+
|
7
|
+
Scenario: check lines
|
8
|
+
When I run `dcmetro line`
|
9
|
+
Then the stdout should contain "Green\nBlue\nSilver\nRed\nOrange\nYellow"
|
10
|
+
|
11
|
+
Scenario: check lines
|
12
|
+
When I run `dcmetro lines`
|
13
|
+
Then the stdout should contain "Green\nBlue\nSilver\nRed\nOrange\nYellow"
|
14
|
+
|
15
|
+
Scenario: check red line for Gallery Place
|
16
|
+
When I run `dcmetro line red`
|
17
|
+
Then the stdout should contain "Gallery"
|
18
|
+
|
19
|
+
Scenario: check green line for Gallery Place
|
20
|
+
When I run `dcmetro line green`
|
21
|
+
Then the stdout should contain "Gallery"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: check dcmetro station predictions
|
2
|
+
|
3
|
+
In order to station predictions
|
4
|
+
When I run `dcmetro station STATION`
|
5
|
+
Then train predictions for STATION should be displayed
|
6
|
+
|
7
|
+
Scenario: check gallery predictions
|
8
|
+
When I run `dcmetro station gallery`
|
9
|
+
Then the stdout should contain "===== Gallery Pl-Chinatown ====="
|
10
|
+
|
11
|
+
Scenario: check predictions from partial name
|
12
|
+
When I run `dcmetro station gall`
|
13
|
+
Then the stdout should contain "===== Gallery Pl-Chinatown ====="
|
14
|
+
|
15
|
+
Scenario: check predictions returning more than one station
|
16
|
+
When I run `dcmetro station g` interactively
|
17
|
+
And I type "5"
|
18
|
+
Then the stdout should contain "===== Gallery Pl-Chinatown ====="
|
@@ -0,0 +1,28 @@
|
|
1
|
+
When(/^I send a GET request for "([^"]*)"$/) do |path|
|
2
|
+
case path
|
3
|
+
when "WMATA Alerts"
|
4
|
+
@last_response = X.alerts
|
5
|
+
when "WMATA Lines"
|
6
|
+
@last_response = X.line
|
7
|
+
when "WMATA Lines Red"
|
8
|
+
@last_response = X.line "Red"
|
9
|
+
when "WMATA Station Gallery"
|
10
|
+
@last_response = X.station "Gallery place"
|
11
|
+
when "WMATA Station Gallery College"
|
12
|
+
@last_response = X.station "Gallery", "College"
|
13
|
+
else
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^the response should be "([^"]*)"$/) do |status|
|
19
|
+
@last_response.code == status.to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
Then(/^should return "([^"]*)"$/) do |arg1|
|
23
|
+
valid_json?(@last_response)
|
24
|
+
end
|
25
|
+
|
26
|
+
Then(/^should contain "([^"]*)"$/) do |arg1|
|
27
|
+
@last_response[arg1]
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'aruba/cucumber'
|
5
|
+
require 'json'
|
6
|
+
require 'rest-client'
|
7
|
+
require 'dcmetro'
|
8
|
+
|
9
|
+
DCMETRO_KEY=ENV['DCMETRO_KEY']
|
10
|
+
API_KEY = DCMETRO_KEY
|
11
|
+
BASE_URL="http://api.wmata.com"
|
12
|
+
|
13
|
+
X = DCMetro::Information.new
|
14
|
+
|
15
|
+
Before ("@check ") do
|
16
|
+
def valid_json?(json)
|
17
|
+
begin
|
18
|
+
JSON.parse(json)
|
19
|
+
true
|
20
|
+
rescue
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'json'
|
3
|
-
require '
|
3
|
+
require 'rest-client'
|
4
4
|
|
5
5
|
#
|
6
6
|
# This is the command line interface using Thor
|
@@ -16,7 +16,9 @@ module DCMetro
|
|
16
16
|
# => *** Alert! Alert! ***
|
17
17
|
|
18
18
|
x = DCMetro::Information.new
|
19
|
-
|
19
|
+
|
20
|
+
alerts = parse_json x.alerts
|
21
|
+
display_alerts alerts
|
20
22
|
end
|
21
23
|
|
22
24
|
desc 'line COLOR', 'Display metro rail lines, if COLOR, displays rail stations on the COLOR line'
|
@@ -31,15 +33,26 @@ module DCMetro
|
|
31
33
|
x = DCMetro::Information.new
|
32
34
|
|
33
35
|
if !color.nil?
|
34
|
-
x.line(color)
|
36
|
+
line = parse_json x.line(color)
|
37
|
+
line["Stations"].each { |station| puts station['Name']}
|
35
38
|
else
|
36
|
-
|
39
|
+
lines = parse_json x.line
|
40
|
+
lines["Lines"].each do |line|
|
41
|
+
color = get_color(line['LineCode'])
|
42
|
+
|
43
|
+
puts "#{color}#{line['DisplayName']}#{COLOR_OFF}"
|
44
|
+
end
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
48
|
+
desc "lines", "invokes line method"
|
49
|
+
def lines color=nil
|
50
|
+
invoke :line
|
51
|
+
end
|
52
|
+
|
40
53
|
desc 'station NAME', 'Display metro station train arrival and departure times.'
|
41
54
|
method_option :alerts, :aliases => '-a', :type => :boolean, :description => "Display Metro wide alerts."
|
42
|
-
def station(
|
55
|
+
def station(from, to=nil)
|
43
56
|
#
|
44
57
|
# $dcmetro station Greenbelt
|
45
58
|
# => Displays the departure and arrival times at the Greenbelt Station
|
@@ -51,20 +64,48 @@ module DCMetro
|
|
51
64
|
x = DCMetro::Information.new
|
52
65
|
|
53
66
|
if options[:alerts]
|
54
|
-
y = x.alerts
|
67
|
+
y = parse_json x.alerts
|
55
68
|
display_alerts y
|
56
69
|
end
|
57
70
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
if to.nil?
|
72
|
+
x = parse_json x.station(from)
|
73
|
+
train_time = x['Trains'].empty? ? "Sorry, there is no information for #{from}." : display_trains(x['Trains'])
|
74
|
+
puts train_time if !train_time.kind_of?(Array)
|
75
|
+
train_time
|
76
|
+
else
|
77
|
+
x = x.station(from,to)
|
78
|
+
y = parse_json x
|
79
|
+
display_travel_info y
|
80
|
+
|
81
|
+
end
|
62
82
|
end
|
63
83
|
|
64
84
|
private
|
65
85
|
|
66
86
|
no_commands do
|
67
87
|
|
88
|
+
def get_color line_code
|
89
|
+
case line_code
|
90
|
+
when "GR"
|
91
|
+
GREEN
|
92
|
+
when "BL"
|
93
|
+
BLUE
|
94
|
+
when "OR"
|
95
|
+
ORANGE
|
96
|
+
when "SV"
|
97
|
+
SILVER
|
98
|
+
when "YL"
|
99
|
+
YELLOW
|
100
|
+
else
|
101
|
+
RED
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_json response
|
106
|
+
JSON.parse(response)
|
107
|
+
end
|
108
|
+
|
68
109
|
def display_alerts alerts
|
69
110
|
#
|
70
111
|
# Formats the display of the alerts
|
@@ -87,6 +128,14 @@ module DCMetro
|
|
87
128
|
end
|
88
129
|
end
|
89
130
|
|
131
|
+
def display_travel_info information
|
132
|
+
information = information['StationToStationInfos'][0]
|
133
|
+
railFare = information['RailFare']
|
134
|
+
puts "Distance: #{information['CompositeMiles']} Miles\n"
|
135
|
+
puts "Estimate Travel Time: #{information['RailTime']} Minutes\n"
|
136
|
+
puts "\n*** Fare Information ***\nOff Peak Time: $#{railFare['OffPeakTime']}\nPeak Time: $#{railFare['PeakTime']}\nSenior/Disabled: $#{railFare['SeniorDisabled']}"
|
137
|
+
end
|
138
|
+
|
90
139
|
end
|
91
140
|
|
92
141
|
end
|
data/lib/dcmetro/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Dcmetro
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
end
|
4
4
|
|
5
5
|
### Changes in 0.0.2
|
@@ -10,4 +10,16 @@ end
|
|
10
10
|
#
|
11
11
|
# Requires the use of an env variable for the API key
|
12
12
|
#
|
13
|
-
# Requires rest-client
|
13
|
+
# Requires rest-client
|
14
|
+
|
15
|
+
### Changes in 0.0.3
|
16
|
+
#
|
17
|
+
# Adds station to station travel information
|
18
|
+
#
|
19
|
+
# Expanded test coverage
|
20
|
+
#
|
21
|
+
# Refactors code so that the Information Class merely returns information
|
22
|
+
# Any parsing is now done in the CLI application
|
23
|
+
#
|
24
|
+
# Bug: If no stations are returned app pukes
|
25
|
+
# Bug: Pentagon and Pentagon City confuses app
|
data/lib/dcmetro.rb
CHANGED
@@ -3,21 +3,27 @@ require_relative 'dcmetro/cli/application'
|
|
3
3
|
|
4
4
|
module DCMetro
|
5
5
|
class Information
|
6
|
-
attr_accessor :metro_incidents, :metro_lines, :metro_stations, :station_code, :metro_time
|
6
|
+
attr_accessor :metro_incidents, :metro_lines, :metro_stations, :station_code, :metro_time, :travel_info
|
7
|
+
|
8
|
+
BASE_URL="https://api.wmata.com"
|
7
9
|
|
8
10
|
def initialize
|
9
|
-
@metro_incidents =
|
10
|
-
@metro_lines =
|
11
|
+
@metro_incidents = metro_incidents
|
12
|
+
@metro_lines = metro_lines
|
11
13
|
@metro_stations = metro_stations
|
12
14
|
@station_code = ""
|
13
15
|
@metro_time = metro_time
|
16
|
+
@travel_info = travel_info
|
14
17
|
end
|
15
18
|
|
16
19
|
def alerts
|
17
20
|
#
|
18
21
|
# Makes the api call and returns the alerts
|
22
|
+
@metro_incidents = RestClient.get "#{BASE_URL}/Incidents.svc/json/Incidents", :params => {
|
23
|
+
"api_key" => API_KEY,
|
24
|
+
"subscription-key" => API_KEY
|
25
|
+
}
|
19
26
|
|
20
|
-
@metro_incidents
|
21
27
|
end ### alerts
|
22
28
|
|
23
29
|
def line(color=nil)
|
@@ -27,14 +33,44 @@ module DCMetro
|
|
27
33
|
|
28
34
|
if !color.nil?
|
29
35
|
color = color.downcase
|
30
|
-
|
31
|
-
|
36
|
+
|
37
|
+
case color
|
38
|
+
when "red"
|
39
|
+
color = "RD"
|
40
|
+
when "green"
|
41
|
+
color = "GR"
|
42
|
+
when "yellow"
|
43
|
+
color = "YL"
|
44
|
+
when "blue"
|
45
|
+
color = "BL"
|
46
|
+
when "orange"
|
47
|
+
color = "OR"
|
48
|
+
else
|
49
|
+
color = "SV"
|
50
|
+
end
|
51
|
+
|
52
|
+
@metro_stations = RestClient.get "#{BASE_URL}/Rail.svc/json/jStations", :params => {
|
53
|
+
"LineCode" => color,
|
54
|
+
"api_key" => API_KEY,
|
55
|
+
"subscription-key" => API_KEY
|
56
|
+
}
|
57
|
+
|
58
|
+
# @metro_stations = parse_json metro_stations
|
59
|
+
# @metro_stations['Stations']
|
32
60
|
else
|
33
|
-
@metro_lines
|
61
|
+
@metro_lines = RestClient.get "#{BASE_URL}/Rail.svc/json/JLines", :params => {
|
62
|
+
"api_key" => API_KEY,
|
63
|
+
"subscription-key" => API_KEY
|
64
|
+
}
|
65
|
+
|
66
|
+
# @metro_lines = metro_lines
|
67
|
+
# @metro_lines['Lines']
|
68
|
+
|
69
|
+
# @metro_lines = get_all_stations
|
34
70
|
end
|
35
71
|
end ### line
|
36
72
|
|
37
|
-
def station(
|
73
|
+
def station(source,destination=nil)
|
38
74
|
#
|
39
75
|
# Makes the api call to return all stations in the Metro rail system and
|
40
76
|
# then grabs the specific station passed by the user
|
@@ -43,43 +79,85 @@ module DCMetro
|
|
43
79
|
stations_check = []
|
44
80
|
|
45
81
|
# forming the api call
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
82
|
+
@metro_stations = JSON.parse(get_all_stations)
|
83
|
+
|
84
|
+
if destination.nil?
|
85
|
+
# Iterates through the response checking if the station name passed by the user
|
86
|
+
# is included in the return response
|
87
|
+
@metro_stations['Stations'].each do |station_name|
|
88
|
+
if station_name['Name'].downcase.include? source.downcase
|
89
|
+
# if the names of the station matches the user's station, the station
|
90
|
+
# is pushed to an array
|
91
|
+
stations_check.push(station_name)
|
92
|
+
end
|
57
93
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
puts
|
72
|
-
|
94
|
+
# Oddly, the api seems to return some stations twice - since some stations have more than
|
95
|
+
# one line. Though the additional station information is contained in each instance of the
|
96
|
+
# station.
|
97
|
+
# We limit our array to only unique station names, hopefully limiting the array to a single item
|
98
|
+
stations_check.uniq! { |station| station['Name'] }
|
99
|
+
|
100
|
+
# If the array length is greater than 1, we ask the user to be more specific and
|
101
|
+
# return the names of the stations
|
102
|
+
if stations_check.length > 1
|
103
|
+
puts "****Multiple stations found****"
|
104
|
+
stations_check.each_with_index do |station,i|
|
105
|
+
puts "#{i} #{station['Name']}"
|
106
|
+
end
|
107
|
+
puts "****Please be more specific, enter the number below ****"
|
108
|
+
specific = STDIN.gets.chomp.to_i
|
109
|
+
station_time stations_check[specific]
|
110
|
+
else
|
111
|
+
# We pass the station the station_time method to grab the predictions
|
112
|
+
station_time stations_check[0]
|
73
113
|
end
|
74
|
-
abort "****Please be more specific****"
|
75
114
|
else
|
76
|
-
|
77
|
-
|
115
|
+
stations = [source, destination]
|
116
|
+
station_code = []
|
117
|
+
stations.each do |station|
|
118
|
+
@metro_stations['Stations'].each do |station_name|
|
119
|
+
if station_name['Name'].downcase.include? station.downcase
|
120
|
+
station_code << station_name
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
station_code.uniq! { |station| station['Name'] }
|
125
|
+
if station_code.length > 2
|
126
|
+
puts "****Multiple stations found****"
|
127
|
+
station_code.each_with_index do |station,i|
|
128
|
+
puts "#{i} #{station['Name']}"
|
129
|
+
end
|
130
|
+
puts "****Please be more specific****"
|
131
|
+
puts "Enter the number of your starting station."
|
132
|
+
start = STDIN.gets.chomp.to_i
|
133
|
+
puts "Enter the number of your destination station."
|
134
|
+
destination = STDIN.gets.chomp.to_i
|
135
|
+
@travel_info = RestClient.get "#{BASE_URL}/Rail.svc/json/jSrcStationToDstStationInfo", :params => {
|
136
|
+
"FromStationCode" => station_code[start]['Code'],
|
137
|
+
"ToStationCode" => station_code[destination]['Code'],
|
138
|
+
"api_key" => API_KEY,
|
139
|
+
"subscription-key" => API_KEY
|
140
|
+
}
|
141
|
+
else
|
142
|
+
@travel_info = RestClient.get "#{BASE_URL}/Rail.svc/json/jSrcStationToDstStationInfo", :params => {
|
143
|
+
"FromStationCode" => station_code[0]['Code'],
|
144
|
+
"ToStationCode" => station_code[1]['Code'],
|
145
|
+
"api_key" => API_KEY,
|
146
|
+
"subscription-key" => API_KEY
|
147
|
+
}
|
148
|
+
end
|
78
149
|
end
|
79
150
|
end ### station
|
80
151
|
|
81
152
|
private
|
82
153
|
|
154
|
+
def get_all_stations
|
155
|
+
return RestClient.get "#{BASE_URL}/Rail.svc/json/jStations", :params => {
|
156
|
+
"api_key" => API_KEY,
|
157
|
+
"subscription-key" => API_KEY
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
83
161
|
#
|
84
162
|
# This makes an api call to grab the train arrival and departure predictions.
|
85
163
|
# If more than one line is present at a station, such is concatenated and
|
@@ -97,8 +175,10 @@ module DCMetro
|
|
97
175
|
end
|
98
176
|
|
99
177
|
# The call to the api is made and the prediction times are returned
|
100
|
-
|
101
|
-
|
178
|
+
@metro_time = RestClient.get "#{BASE_URL}/StationPrediction.svc/json/GetPrediction/#{@station_code}", :params => {
|
179
|
+
"api_key" => API_KEY,
|
180
|
+
"subscription-key" => API_KEY
|
181
|
+
}
|
102
182
|
@metro_time
|
103
183
|
end
|
104
184
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcmetro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Crocken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,7 +80,36 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
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: coveralls
|
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
|
+
description: Washington, DC Metro Rails information, including lines, stations and
|
112
|
+
arrival/departure predictions.
|
84
113
|
email:
|
85
114
|
- kcrocken@gmail.com
|
86
115
|
executables:
|
@@ -88,13 +117,21 @@ executables:
|
|
88
117
|
extensions: []
|
89
118
|
extra_rdoc_files: []
|
90
119
|
files:
|
120
|
+
- ".coveralls.yml"
|
91
121
|
- ".gitignore"
|
122
|
+
- ".travis.yml"
|
92
123
|
- Gemfile
|
93
124
|
- LICENSE.txt
|
94
125
|
- README.md
|
95
126
|
- Rakefile
|
96
127
|
- bin/dcmetro
|
97
128
|
- dcmetro.gemspec
|
129
|
+
- features/alerts.feature
|
130
|
+
- features/external.feature
|
131
|
+
- features/lines.feature
|
132
|
+
- features/station.feature
|
133
|
+
- features/step_definitions/api_test_steps.rb
|
134
|
+
- features/support/env.rb
|
98
135
|
- lib/dcmetro.rb
|
99
136
|
- lib/dcmetro/cli/application.rb
|
100
137
|
- lib/dcmetro/version.rb
|
@@ -121,5 +158,11 @@ rubyforge_project:
|
|
121
158
|
rubygems_version: 2.4.5
|
122
159
|
signing_key:
|
123
160
|
specification_version: 4
|
124
|
-
summary: Returns DC Metro information, including train schedules.
|
125
|
-
test_files:
|
161
|
+
summary: Returns DC Metro Rails information, including train schedules.
|
162
|
+
test_files:
|
163
|
+
- features/alerts.feature
|
164
|
+
- features/external.feature
|
165
|
+
- features/lines.feature
|
166
|
+
- features/station.feature
|
167
|
+
- features/step_definitions/api_test_steps.rb
|
168
|
+
- features/support/env.rb
|