tubeline 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: 8602b8e17f8e9c65d86a294c114209c8297edd4b
4
+ data.tar.gz: eb5d69ef644537c210424dc3c225745979ccd060
5
+ SHA512:
6
+ metadata.gz: be6a730224fb665a7d34fdbb1dd8da67512e25bc5a8e0790fed4532570a492fda4f9082ec9583726ae23502e78b3fb02101abacc1146d44d30272bb6f8b46c62
7
+ data.tar.gz: 6445df07f63a622a8716f9ed775ddf582e91e199875ebc6297393e7da5119a3ae03482e4511405e2a189cd2c0f0097146281af38507cce01f4aaceec5866bfc3
data/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+ code: public domain
2
+ data: check with TFL - http://www.tfl.gov.uk/businessandpartners/syndication/default.aspx
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # tubeline
2
+ ## A super-simple method of accessing the tube status API
3
+
4
+ ```ruby
5
+
6
+ pp Tubeline.status
7
+
8
+ {:bakerloo=>
9
+ {:name=>"Bakerloo",
10
+ :line_id=>1,
11
+ :active=>true,
12
+ :technical=>"DisruptedService",
13
+ :description=>"Part Closure",
14
+ :explanation=>
15
+ "No service Stonebridge Park to Harrow & Wealdstone due to planned engineering work. GOOD SERVICE on the rest of the line. Rail Replacement bus service in operation. "},
16
+ :central=>
17
+ {:name=>"Central",
18
+ :line_id=>2,
19
+ :active=>true,
20
+ :technical=>"GoodService",
21
+ :description=>"Good Service",
22
+ :explanation=>""},
23
+ :circle=>
24
+ {:name=>"Circle",
25
+ :line_id=>7,
26
+ :active=>true,
27
+ :technical=>"GoodService",
28
+ :description=>"Good Service",
29
+ :explanation=>""},
30
+ :district=>
31
+ {:name=>"District",
32
+ :line_id=>9,
33
+ :active=>true,
34
+ :technical=>"DisruptedService",
35
+ :description=>"Part Closure",
36
+ :explanation=>
37
+ "No service between Turnham Green and Ealing Broadway due to planned engineering work. GOOD SERVICE on the rest of the line."},
38
+ :hammersmith_and_city=>
39
+ {:name=>"Hammersmith and City",
40
+ :line_id=>8,
41
+ :active=>true,
42
+ :technical=>"GoodService",
43
+ :description=>"Good Service",
44
+ :explanation=>""}
45
+ ...
46
+ }
47
+
48
+ ```
49
+
50
+ ### is it finished?
51
+
52
+ No, this library is under development, and breaking changes is a very real possibility. The features I need:
53
+
54
+ * caching - every thirty seconds, with a cache key to assist invalidation.
55
+ * branch line status - northern, overground and dlr all have complex lines, so an overall status isn't always relevant.
data/Rakefile ADDED
@@ -0,0 +1,174 @@
1
+ # Rakegem - from https://github.com/mojombo/rakegem
2
+ # released under the following license:
3
+ #
4
+ # The MIT License
5
+ #
6
+ # Copyright (c) Tom Preston-Werner
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+
26
+ require 'rake'
27
+ require 'date'
28
+
29
+ #############################################################################
30
+ #
31
+ # Helper functions
32
+ #
33
+ #############################################################################
34
+
35
+ def name
36
+ @name ||= Dir['*.gemspec'].first.split('.').first
37
+ end
38
+
39
+ def version
40
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
41
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
42
+ end
43
+
44
+ def date
45
+ Date.today.to_s
46
+ end
47
+
48
+ def rubyforge_project
49
+ name
50
+ end
51
+
52
+ def gemspec_file
53
+ "#{name}.gemspec"
54
+ end
55
+
56
+ def gem_file
57
+ "#{name}-#{version}.gem"
58
+ end
59
+
60
+ def replace_header(head, header_name)
61
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
62
+ end
63
+
64
+ #############################################################################
65
+ #
66
+ # Standard tasks
67
+ #
68
+ #############################################################################
69
+
70
+ task :default => :test
71
+
72
+ require 'rake/testtask'
73
+ Rake::TestTask.new(:test) do |test|
74
+ test.libs << 'lib' << 'test'
75
+ test.pattern = 'test/*_test.rb'
76
+ test.verbose = true
77
+ end
78
+
79
+ desc "Generate RCov test coverage and open in your browser"
80
+ task :coverage do
81
+ require 'rcov'
82
+ sh "rm -fr coverage"
83
+ sh "rcov test/test_*.rb"
84
+ sh "open coverage/index.html"
85
+ end
86
+
87
+ require 'rdoc/task'
88
+ Rake::RDocTask.new do |rdoc|
89
+ rdoc.rdoc_dir = 'rdoc'
90
+ rdoc.title = "#{name} #{version}"
91
+ rdoc.rdoc_files.include('README*')
92
+ rdoc.rdoc_files.include('lib/**/*.rb')
93
+ end
94
+
95
+ desc "Open an irb session preloaded with this library"
96
+ task :console do
97
+ sh "irb -rubygems -r ./lib/#{name}.rb"
98
+ end
99
+
100
+ #############################################################################
101
+ #
102
+ # Custom tasks (add your own tasks here)
103
+ #
104
+ #############################################################################
105
+
106
+
107
+
108
+ #############################################################################
109
+ #
110
+ # Packaging tasks
111
+ #
112
+ #############################################################################
113
+
114
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
115
+ task :release => :build do
116
+ unless `git branch` =~ /^\* master$/
117
+ puts "You must be on the master branch to release!"
118
+ exit!
119
+ end
120
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
121
+ sh "git tag v#{version}"
122
+ sh "git push origin master"
123
+ sh "git push origin v#{version}"
124
+ sh "gem push pkg/#{name}-#{version}.gem"
125
+ end
126
+
127
+ desc "Build #{gem_file} into the pkg directory"
128
+ task :build => :gemspec do
129
+ sh "mkdir -p pkg"
130
+ sh "gem build #{gemspec_file}"
131
+ sh "mv #{gem_file} pkg"
132
+ end
133
+
134
+ desc "Generate #{gemspec_file}"
135
+ task :gemspec => :validate do
136
+ # read spec file and split out manifest section
137
+ spec = File.read(gemspec_file)
138
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
139
+
140
+ # replace name version and date
141
+ replace_header(head, :name)
142
+ replace_header(head, :version)
143
+ replace_header(head, :date)
144
+ #comment this out if your rubyforge_project has a different name
145
+ replace_header(head, :rubyforge_project)
146
+
147
+ # determine file list from git ls-files
148
+ files = `git ls-files`.
149
+ split("\n").
150
+ sort.
151
+ reject { |file| file =~ /^\./ }.
152
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
153
+ map { |file| " #{file}" }.
154
+ join("\n")
155
+
156
+ # piece file back together and write
157
+ manifest = " s.files = %w[\n#{files}\n ]\n"
158
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
159
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
160
+ puts "Updated #{gemspec_file}"
161
+ end
162
+
163
+ desc "Validate #{gemspec_file}"
164
+ task :validate do
165
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
166
+ unless libfiles.empty?
167
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
168
+ exit!
169
+ end
170
+ unless Dir['VERSION*'].empty?
171
+ puts "A `VERSION` file at root level violates Gem best practices."
172
+ exit!
173
+ end
174
+ end
data/lib/tubeline.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "nokogiri"
2
+ require "net/http"
3
+
4
+ module Tubeline
5
+ VERSION = "0.1"
6
+ STATUS_ENDPOINT = "http://cloud.tfl.gov.uk/TrackerNet/LineStatus"
7
+
8
+ def self.status
9
+ doc = Nokogiri::XML.parse fetch_xml
10
+
11
+ doc.css("LineStatus").inject(Hash.new) do |hash, line_status|
12
+ status = Hash[line_status.css("Status").first.attributes.map{|k, v| [k, v.to_s] }]
13
+ line = Hash[line_status.css("Line").first.attributes.map{|k, v| [k, v.to_s]}]
14
+ line_status = Hash[line_status.attributes.map{|k, v| [k, v.to_s] }]
15
+
16
+ hash.update(line["Name"].gsub(/\W/, "_").downcase.to_sym => {
17
+ name: line["Name"],
18
+ line_id: line["ID"].to_i,
19
+ active: status["IsActive"] == "true",
20
+ technical: status["CssClass"],
21
+ description: status["Description"],
22
+ explanation: line_status["StatusDetails"]
23
+ })
24
+ end
25
+ end
26
+
27
+ def self.fetch_xml
28
+ Net::HTTP.get URI.parse STATUS_ENDPOINT
29
+ end
30
+ end
@@ -0,0 +1,135 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <ArrayOfLineStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservices.lul.co.uk/">
3
+ <LineStatus ID="0" StatusDetails="No service Stonebridge Park to Harrow &amp; Wealdstone due to planned engineering work. GOOD SERVICE on the rest of the line. Rail Replacement bus service in operation. ">
4
+ <BranchDisruptions>
5
+ <BranchDisruption>
6
+ <StationTo ID="100" Name="Harrow &amp; Wealdstone" />
7
+ <StationFrom ID="223" Name="Stonebridge Park" />
8
+ </BranchDisruption>
9
+ </BranchDisruptions>
10
+ <Line ID="1" Name="Bakerloo" />
11
+ <Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
12
+ <StatusType ID="1" Description="Line" />
13
+ </Status>
14
+ </LineStatus>
15
+ <LineStatus ID="1" StatusDetails="">
16
+ <BranchDisruptions />
17
+ <Line ID="2" Name="Central" />
18
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
19
+ <StatusType ID="1" Description="Line" />
20
+ </Status>
21
+ </LineStatus>
22
+ <LineStatus ID="10" StatusDetails="">
23
+ <BranchDisruptions />
24
+ <Line ID="7" Name="Circle" />
25
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
26
+ <StatusType ID="1" Description="Line" />
27
+ </Status>
28
+ </LineStatus>
29
+ <LineStatus ID="2" StatusDetails="No service between Turnham Green and Ealing Broadway due to planned engineering work. GOOD SERVICE on the rest of the line.">
30
+ <BranchDisruptions>
31
+ <BranchDisruption>
32
+ <StationTo ID="61" Name="Ealing Broadway" />
33
+ <StationFrom ID="238" Name="Turnham Green" />
34
+ </BranchDisruption>
35
+ </BranchDisruptions>
36
+ <Line ID="9" Name="District" />
37
+ <Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
38
+ <StatusType ID="1" Description="Line" />
39
+ </Status>
40
+ </LineStatus>
41
+ <LineStatus ID="8" StatusDetails="">
42
+ <BranchDisruptions />
43
+ <Line ID="8" Name="Hammersmith and City" />
44
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
45
+ <StatusType ID="1" Description="Line" />
46
+ </Status>
47
+ </LineStatus>
48
+ <LineStatus ID="4" StatusDetails="">
49
+ <BranchDisruptions />
50
+ <Line ID="4" Name="Jubilee" />
51
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
52
+ <StatusType ID="1" Description="Line" />
53
+ </Status>
54
+ </LineStatus>
55
+ <LineStatus ID="9" StatusDetails="">
56
+ <BranchDisruptions />
57
+ <Line ID="11" Name="Metropolitan" />
58
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
59
+ <StatusType ID="1" Description="Line" />
60
+ </Status>
61
+ </LineStatus>
62
+ <LineStatus ID="5" StatusDetails="">
63
+ <BranchDisruptions />
64
+ <Line ID="5" Name="Northern" />
65
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
66
+ <StatusType ID="1" Description="Line" />
67
+ </Status>
68
+ </LineStatus>
69
+ <LineStatus ID="6" StatusDetails="No service between Hammersmith and Uxbridge / Osterley due to planned engineering work. A rail replacement bus service operates. GOOD SERVICE on the rest of the line.">
70
+ <BranchDisruptions>
71
+ <BranchDisruption>
72
+ <StationTo ID="170" Name="Osterley" />
73
+ <StationFrom ID="95" Name="Hammersmith" />
74
+ </BranchDisruption>
75
+ <BranchDisruption>
76
+ <StationTo ID="244" Name="Uxbridge" />
77
+ <StationFrom ID="95" Name="Hammersmith" />
78
+ </BranchDisruption>
79
+ </BranchDisruptions>
80
+ <Line ID="6" Name="Piccadilly" />
81
+ <Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
82
+ <StatusType ID="1" Description="Line" />
83
+ </Status>
84
+ </LineStatus>
85
+ <LineStatus ID="7" StatusDetails="">
86
+ <BranchDisruptions />
87
+ <Line ID="3" Name="Victoria" />
88
+ <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
89
+ <StatusType ID="1" Description="Line" />
90
+ </Status>
91
+ </LineStatus>
92
+ <LineStatus ID="11" StatusDetails="Train service resumes at 06.15hrs Monday.">
93
+ <BranchDisruptions />
94
+ <Line ID="12" Name="Waterloo and City" />
95
+ <Status ID="CS" CssClass="DisruptedService" Description="Planned Closure" IsActive="true">
96
+ <StatusType ID="1" Description="Line" />
97
+ </Status>
98
+ </LineStatus>
99
+ <LineStatus ID="82" StatusDetails="No service between Clapham Junction and Willesden Junction, no service between New Cross Gate and Crystal Palace / West Croydon. &#xA;No service between Queens Park and Watford Junction due to planned engineering work. GOOD SERVICE on all other routes. Tickets will be accepted on London Underground and London Buses via any reasonable route.">
100
+ <BranchDisruptions>
101
+ <BranchDisruption>
102
+ <StationTo ID="365" Name="Watford Junction" />
103
+ <StationFrom ID="183" Name="Queen's Park" />
104
+ </BranchDisruption>
105
+ <BranchDisruption>
106
+ <StationTo ID="269" Name="Willesden Junction" />
107
+ <StationFrom ID="302" Name="Clapham Junction" />
108
+ </BranchDisruption>
109
+ <BranchDisruption>
110
+ <StationTo ID="305" Name="Crystal Palace" />
111
+ <StationFrom ID="155" Name="New Cross Gate" />
112
+ </BranchDisruption>
113
+ <BranchDisruption>
114
+ <StationTo ID="366" Name="West Croydon" />
115
+ <StationFrom ID="155" Name="New Cross Gate" />
116
+ </BranchDisruption>
117
+ </BranchDisruptions>
118
+ <Line ID="82" Name="Overground" />
119
+ <Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
120
+ <StatusType ID="1" Description="Line" />
121
+ </Status>
122
+ </LineStatus>
123
+ <LineStatus ID="81" StatusDetails="No service Bow Church to Stratford due to planned engineering work. GOOD SERVICE on the rest of the line. Rail Replacement bus service in operation Stratford, Pudding Mill Lane, Bow Church.&#xA;London Underground will accept valid tickets via any reasonable route.">
124
+ <BranchDisruptions>
125
+ <BranchDisruption>
126
+ <StationTo ID="224" Name="Stratford" />
127
+ <StationFrom ID="293" Name="Bow Church" />
128
+ </BranchDisruption>
129
+ </BranchDisruptions>
130
+ <Line ID="81" Name="DLR" />
131
+ <Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
132
+ <StatusType ID="1" Description="Line" />
133
+ </Status>
134
+ </LineStatus>
135
+ </ArrayOfLineStatus>
@@ -0,0 +1,14 @@
1
+ require "tubeline"
2
+ require "minitest/autorun"
3
+
4
+ module Tubeline
5
+ def self.fetch_xml
6
+ File.read(File.join(File.dirname(__FILE__), "fixtures", "response.xml"))
7
+ end
8
+ end
9
+
10
+ class TubelineTest < MiniTest::Unit::TestCase
11
+ def test_parsing
12
+ assert_equal Tubeline.status[:central][:technical], "GoodService"
13
+ end
14
+ end
data/tubeline.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'tubeline'
7
+ s.version = '0.1'
8
+ s.date = '2013-11-17'
9
+
10
+ s.summary = "London Underground status API"
11
+ s.description = "A ruby library for interacting with the London Underground Tube status API"
12
+
13
+ s.authors = ["Luke Carpenter"]
14
+ s.email = 'luke@ghostworks.io'
15
+ s.homepage = 'https://ghostworks.github.io/tubeline'
16
+
17
+ s.require_paths = %w[lib]
18
+
19
+ s.rdoc_options = ["--charset=UTF-8"]
20
+ s.extra_rdoc_files = %w[README.md LICENSE]
21
+
22
+ s.add_dependency('nokogiri')
23
+
24
+ # = MANIFEST =
25
+ s.files = %w[
26
+ LICENSE
27
+ README.md
28
+ Rakefile
29
+ lib/tubeline.rb
30
+ test/fixtures/response.xml
31
+ test/tubeline_test.rb
32
+ tubeline.gemspec
33
+ ]
34
+ # = MANIFEST =
35
+
36
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
37
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tubeline
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Luke Carpenter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A ruby library for interacting with the London Underground Tube status
28
+ API
29
+ email: luke@ghostworks.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - README.md
34
+ - LICENSE
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - lib/tubeline.rb
40
+ - test/fixtures/response.xml
41
+ - test/tubeline_test.rb
42
+ - tubeline.gemspec
43
+ homepage: https://ghostworks.github.io/tubeline
44
+ licenses: []
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.0.3
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: London Underground status API
67
+ test_files: []
68
+ has_rdoc: