dcmetro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90891b8942382cbf830daf11826f4d4d019931a9
4
+ data.tar.gz: 18fcafc5a952ae46cc8264404e8a459841398307
5
+ SHA512:
6
+ metadata.gz: 9203bd85d858944c7f9729f98b5d4b3d2b85937c60d676701b3f1ff616d3960b960a5d5fe411d7be5db5196efac575b3157dd36eb6d8a01c7b8d0e7c24f52428
7
+ data.tar.gz: 82a9046f638381d1e2f808cb819a7d523184d1f2fdf72fae2e3846304f4499928ff00cdde1e3040b3291c73b5245877d588e00079d6cf3f3f114e73734f79f5f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dcmetro.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ken Crocken
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # DCMetro
2
+
3
+ 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
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dcmetro'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dcmetro
20
+
21
+ ## Usage
22
+ ###Rails App
23
+
24
+ With the gem installed, instantiate a new class in your controller:
25
+
26
+ ```ruby
27
+ class WelcomeController < ApplicationController
28
+
29
+
30
+ def index
31
+ x = DCMetro::Information.new
32
+ @alerts = x.alerts['Incidents']
33
+ @lines = x.line
34
+ @stations = x.line "green"
35
+ @college_park = x.station "college"
36
+ @rosslyn = x.station "ross"
37
+ @fort_totten = x.station "fort"
38
+ @metro_center = x.station "metro"
39
+ end
40
+
41
+ end
42
+ ```
43
+
44
+ ###CLI
45
+
46
+ ```
47
+ $ dcmetro
48
+ Commands:
49
+ dcmetro alerts # Display DC Metro system wide alerts.
50
+ dcmetro help [COMMAND] # Describe available commands or one specific command
51
+ dcmetro line COLOR # Display metro rail lines, if COLOR, displays rail stations on the COLOR line
52
+ dcmetro station NAME # Display metro station train arrival and departure times.
53
+ ```
54
+
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it ( https://github.com/kencrocken/dcmetro/fork )
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dcmetro ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ API_KEY="n2z9aq3redes6k7jekjfzk8q" #"kfgpmgvfgacx98de9q3xazww" #developer's key
4
+
5
+ # Color Reset
6
+ COLOR_OFF="\033[0m" # Text Reset
7
+
8
+ # Line Colors
9
+ RED="\033[0;31m" # Red
10
+ GREEN="\033[0;32m" # Green
11
+ ORANGE="\033[38;5;208m" # Orange
12
+ SILVER="\033[0;90m" # IBlack
13
+ YELLOW="\033[0;93m" # IYellow
14
+ BLUE="\033[0;94m" # IBlue
15
+
16
+ require 'dcmetro'
17
+ # require_relative "dcmetro/cli/application"
18
+
19
+ DCMetro::Cli::Application.start(ARGV)
data/dcmetro.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dcmetro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dcmetro"
8
+ spec.version = Dcmetro::VERSION
9
+ spec.authors = ["Ken Crocken"]
10
+ spec.email = ["kcrocken@gmail.com"]
11
+ spec.summary = %q{Returns DC Metro information, including train schedules.}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["dcmetro"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'thor', '~> 0.18'
22
+ spec.add_dependency 'json'
23
+ spec.add_dependency 'rest_client'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
data/lib/dcmetro.rb ADDED
@@ -0,0 +1,67 @@
1
+ require "dcmetro/version"
2
+ require_relative 'dcmetro/cli/application'
3
+
4
+ module DCMetro
5
+ class Information
6
+ attr_accessor :metro_incidents, :metro_lines, :metro_stations, :station_code, :metro_time
7
+
8
+ def initialize
9
+ @metro_incidents = JSON.parse(RestClient.get "http://api.wmata.com/Incidents.svc/json/Incidents?api_key=#{API_KEY}")
10
+ @metro_lines = JSON.parse(RestClient.get "http://api.wmata.com/Rail.svc/json/JLines?api_key=#{API_KEY}")
11
+ @metro_stations = metro_stations
12
+ @station_code = ""
13
+ @metro_time = metro_time
14
+ end
15
+
16
+ def alerts
17
+ @metro_incidents
18
+ end ### alerts
19
+
20
+ def line(color=nil)
21
+ if !color.nil?
22
+ color = color.downcase
23
+ @metro_stations = JSON.parse(RestClient.get "http://api.wmata.com/Rail.svc/json/jStations?LineCode=#{color}&api_key=#{API_KEY}")
24
+ @metro_stations['Stations']
25
+ else
26
+ @metro_lines['Lines']
27
+ end
28
+ end ### line
29
+
30
+ def station(name)
31
+ url = "http://api.wmata.com/Rail.svc/json/jStations?api_key=#{API_KEY}"
32
+ @metro_stations = JSON.parse(RestClient.get "#{url}")
33
+ @metro_stations['Stations'].each do |station_name|
34
+ if station_name['Name'].downcase.include? name.downcase
35
+ x = station_time station_name
36
+ return x
37
+ end
38
+ end
39
+ end ### station
40
+
41
+ private
42
+
43
+ def station_time(station)
44
+
45
+ # puts station['Code']
46
+ @station_code = station['Code']
47
+ if !station['StationTogether1'].empty?
48
+ @station_code += ",#{station['StationTogether1']}"
49
+ end
50
+ if !station['StationTogether2'].empty?
51
+ @station_code += ",#{station['StationTogether2']}"
52
+ end
53
+ # p @station_code.class
54
+ # @station_code = @station_code[1].nil? ? @station_code[0] : @station_code.join(",")
55
+
56
+ # p @station_code
57
+ url = "http://api.wmata.com/StationPrediction.svc/json/GetPrediction/#{@station_code}?api_key=#{API_KEY}"
58
+ # p url
59
+ @metro_time = JSON.parse(RestClient.get "#{url}")
60
+ # p @metro_time
61
+ @metro_time
62
+ end
63
+
64
+
65
+ end ### Information
66
+
67
+ end ### Metro
@@ -0,0 +1,67 @@
1
+ require 'thor'
2
+ require 'json'
3
+ require 'rest_client'
4
+
5
+ module DCMetro
6
+ module Cli
7
+ class Application < Thor
8
+
9
+ desc 'alerts', 'Display DC Metro system wide alerts.'
10
+ def alerts
11
+ x = DCMetro::Information.new
12
+ display_alerts x.alerts
13
+ end
14
+
15
+ desc 'line COLOR', 'Display metro rail lines, if COLOR, displays rail stations on the COLOR line'
16
+ def line color=nil
17
+ x = DCMetro::Information.new
18
+
19
+ if !color.nil?
20
+ x.line(color).each { |station| puts station['Name']}
21
+ else
22
+ x.line.each { |line| puts line["DisplayName"]}
23
+ end
24
+ end
25
+
26
+ desc 'station NAME', 'Display metro station train arrival and departure times.'
27
+ method_option :alerts, :aliases => '-a', :type => :boolean, :description => "Display Metro wide alerts."
28
+ def station(name)
29
+ x = DCMetro::Information.new
30
+
31
+ if options[:alerts]
32
+ y = x.alerts
33
+ display_alerts y
34
+ end
35
+
36
+ x = x.station(name)
37
+ train_time = x['Trains'].empty? ? "Sorry, there is no information for #{name}." : display_trains(x['Trains'])
38
+ puts train_time if !train_time.kind_of?(Array)
39
+ train_time
40
+
41
+ end
42
+
43
+ private
44
+
45
+ no_commands do
46
+
47
+ def display_alerts alerts
48
+ if alerts['Incidents'].empty?
49
+ puts "*** No alerts reported. ***"
50
+ else
51
+ puts "#{RED}*** ALERT! ALERT! ***#{COLOR_OFF}"
52
+ alerts['Incidents'].each { |incident| puts "#{incident["Description"]}\n\n"}
53
+ end
54
+ end
55
+
56
+ def display_trains trains
57
+ puts "===== #{trains[0]['LocationName']} ====="
58
+ trains.each do |prediction|
59
+ puts "Line: #{prediction['Line']} | Towards: #{prediction['DestinationName']} | Arriving: #{prediction['Min']}"
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Dcmetro
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcmetro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ken Crocken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest_client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - kcrocken@gmail.com
86
+ executables:
87
+ - dcmetro
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/dcmetro
97
+ - dcmetro.gemspec
98
+ - lib/dcmetro.rb
99
+ - lib/dcmetro/cli/application.rb
100
+ - lib/dcmetro/version.rb
101
+ homepage: ''
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Returns DC Metro information, including train schedules.
125
+ test_files: []