tramtracker 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -1
- data/README.md +3 -1
- data/Rakefile +7 -0
- data/bin/tramtracker +7 -3
- data/lib/tramtracker.rb +3 -26
- data/lib/tramtracker/api.rb +42 -0
- data/lib/tramtracker/formatters.rb +2 -0
- data/lib/{formatters → tramtracker/formatters}/polling_formatter.rb +0 -0
- data/lib/{formatters → tramtracker/formatters}/print_formatter.rb +0 -0
- data/lib/tramtracker/version.rb +3 -0
- data/spec/fixtures/tramtracker.json +1 -0
- data/spec/lib/tramtracker_spec.rb +20 -0
- data/spec/spec_helper.rb +4 -0
- data/tramtracker.gemspec +2 -1
- metadata +19 -16
- data/lib/formatters.rb +0 -2
- data/test/lib/tramtracker_test.rb +0 -25
- data/test/test_helper.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00d4ac7aef9191bf3c090cdf0fcada77d78efc7e
|
4
|
+
data.tar.gz: d3505d11a726c4922b20d1c33f21b3b467abee15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3b7fd27958fe7ed5600beb784d4054d8307cc57d3b37ee596a0fe162b95fe736e262b891810be3a355ce64325f8917aa5acdf499a4d399870d4801cb9dea67b
|
7
|
+
data.tar.gz: e335e4e39190c1b6360894a03ddefdb42e54dc6fa8a0e01c8de10b65a6e55c01c6d7a5940c6ad39f6481d8b2f02a97622e5cd9e6e6904e760137e1b9f97f242d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0-p353
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Tramtracker
|
2
2
|
===========
|
3
3
|
|
4
|
+
[![Code Climate](https://codeclimate.com/github/stevenocchipinti/tramtracker.png)](https://codeclimate.com/github/stevenocchipinti/tramtracker)
|
5
|
+
|
4
6
|
A commandline tool for Melbourne's TramTracker
|
5
7
|
|
6
8
|
|
@@ -34,5 +36,5 @@ tramtracker -h
|
|
34
36
|
Configuration
|
35
37
|
-------------
|
36
38
|
|
37
|
-
You may create a `~/.tramtracker` file containing the
|
39
|
+
You may create a `~/.tramtracker` file containing the `stop-id` and omit the
|
38
40
|
command line argument
|
data/Rakefile
CHANGED
data/bin/tramtracker
CHANGED
@@ -3,7 +3,6 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
3
3
|
|
4
4
|
require 'optparse'
|
5
5
|
require 'tramtracker'
|
6
|
-
require 'formatters'
|
7
6
|
|
8
7
|
|
9
8
|
formatter_class = Formatters::PrintFormatter
|
@@ -17,6 +16,11 @@ optparse = OptionParser.new do |opts|
|
|
17
16
|
formatter_class = Formatters::PollingFormatter
|
18
17
|
end
|
19
18
|
|
19
|
+
opts.on('-v', '--version', 'Display the version of the gem') do
|
20
|
+
puts "Tramtracker v#{Tramtracker::VERSION}"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
20
24
|
opts.on('-h', '--help', 'Display this screen') do
|
21
25
|
puts opts
|
22
26
|
exit
|
@@ -26,7 +30,7 @@ optparse.parse!
|
|
26
30
|
|
27
31
|
|
28
32
|
id = ARGV[0]
|
29
|
-
id ||= File.read(dotfile) if File.exists?(dotfile)
|
33
|
+
id ||= File.read(dotfile).chomp! if File.exists?(dotfile)
|
30
34
|
unless id
|
31
35
|
puts optparse
|
32
36
|
exit 1
|
@@ -34,7 +38,7 @@ end
|
|
34
38
|
|
35
39
|
|
36
40
|
begin
|
37
|
-
formatter_class.new(Tramtracker.new(id)).report
|
41
|
+
formatter_class.new(Tramtracker::API.new(id)).report
|
38
42
|
rescue Interrupt
|
39
43
|
# Prevent the Exception stack trace from being printed upon ctrl-c
|
40
44
|
puts # This just puts the next prompt on its own line
|
data/lib/tramtracker.rb
CHANGED
@@ -1,26 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
attr_accessor :stop_id
|
5
|
-
|
6
|
-
def initialize(stop_id)
|
7
|
-
@stop_id = stop_id
|
8
|
-
end
|
9
|
-
|
10
|
-
def get
|
11
|
-
regex = /\d*\) Rte (\d*)<br>\r\n(\d*)/
|
12
|
-
open(url).read.scan(regex).collect do |route, minutes|
|
13
|
-
{
|
14
|
-
route: route,
|
15
|
-
minutes: minutes
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def url
|
23
|
-
"http://www.tramtracker.com.au/?id=#{@stop_id}"
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
1
|
+
require 'tramtracker/api'
|
2
|
+
require 'tramtracker/formatters'
|
3
|
+
require 'tramtracker/version'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module Tramtracker
|
6
|
+
class API
|
7
|
+
DATE_FORMAT = "/Date(%Q%z)/"
|
8
|
+
attr_accessor :stop_id
|
9
|
+
|
10
|
+
def initialize(stop_id)
|
11
|
+
@stop_id = stop_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def get
|
15
|
+
api_response["responseObject"].collect do |tram|
|
16
|
+
{
|
17
|
+
route: tram["RouteNo"],
|
18
|
+
minutes: minutes_until(tram["PredictedArrivalDateTime"])
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def api_url
|
27
|
+
"http://www.tramtracker.com.au/Controllers/GetNextPredictionsForStop.ashx?stopNo=#{@stop_id}&routeNo=0&isLowFloor=false"
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_response
|
31
|
+
JSON.parse(open(api_url).read).tap do |response|
|
32
|
+
@request_time = DateTime.strptime(response["timeResponded"], DATE_FORMAT)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def minutes_until(timestamp)
|
37
|
+
arrival_time = DateTime.strptime(timestamp, DATE_FORMAT)
|
38
|
+
((arrival_time - @request_time) * 24 * 60).to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errorMessage":null,"hasError":false,"hasResponse":true,"responseObject":[{"__type":"NextPredictedRoutesCollectionInfo","AirConditioned":false,"Destination":"Melb Uni","DisplayAC":false,"DisruptionMessage":{"DisplayType":"Text","MessageCount":0,"Messages":[]},"HasDisruption":false,"HasSpecialEvent":false,"HeadBoardRouteNo":"64","InternalRouteNo":64,"IsLowFloorTram":false,"IsTTAvailable":true,"PredictedArrivalDateTime":"\/Date(1393935009000+1100)\/","RouteNo":"64","SpecialEventMessage":"","TripID":0,"VehicleNo":78},{"__type":"NextPredictedRoutesCollectionInfo","AirConditioned":false,"Destination":"Melb Uni","DisplayAC":false,"DisruptionMessage":{"DisplayType":"Text","MessageCount":0,"Messages":[]},"HasDisruption":false,"HasSpecialEvent":false,"HeadBoardRouteNo":"64","InternalRouteNo":64,"IsLowFloorTram":false,"IsTTAvailable":true,"PredictedArrivalDateTime":"\/Date(1393936260000+1100)\/","RouteNo":"64","SpecialEventMessage":"","TripID":0,"VehicleNo":180},{"__type":"NextPredictedRoutesCollectionInfo","AirConditioned":false,"Destination":"Melb Uni","DisplayAC":false,"DisruptionMessage":{"DisplayType":"Text","MessageCount":0,"Messages":[]},"HasDisruption":false,"HasSpecialEvent":false,"HeadBoardRouteNo":"64","InternalRouteNo":64,"IsLowFloorTram":false,"IsTTAvailable":true,"PredictedArrivalDateTime":"\/Date(1393958220000+1100)\/","RouteNo":"64","SpecialEventMessage":"","TripID":0,"VehicleNo":-1}],"timeRequested":"\/Date(1393934736826+1100)\/","timeResponded":"\/Date(1393934737712+1100)\/","webMethodCalled":"GetNextPredictedRoutesCollection"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Tramtracker::API do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@tramtracker = Tramtracker::API.new(1111)
|
7
|
+
@mock_response = File.read("spec/fixtures/tramtracker.json")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".get" do
|
11
|
+
it "returns an array of hashes with route and time data" do
|
12
|
+
@tramtracker.stub :open, OpenStruct.new({:read => @mock_response}) do
|
13
|
+
@tramtracker.get.must_include({route: "64", minutes: 4})
|
14
|
+
@tramtracker.get.must_include({route: "64", minutes: 25})
|
15
|
+
@tramtracker.get.must_include({route: "64", minutes: 391})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tramtracker.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require './lib/tramtracker/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |gem|
|
6
7
|
gem.name = "tramtracker"
|
7
|
-
gem.version =
|
8
|
+
gem.version = Tramtracker::VERSION
|
8
9
|
gem.authors = ["Steven Occhipinti"]
|
9
10
|
gem.email = ["dev@stevenocchipinti.com"]
|
10
11
|
gem.description = "A commandline tool for Melbourne's TramTracker"
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramtracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steven Occhipinti
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A commandline tool for Melbourne's TramTracker
|
15
14
|
email:
|
@@ -25,37 +24,41 @@ files:
|
|
25
24
|
- README.md
|
26
25
|
- Rakefile
|
27
26
|
- bin/tramtracker
|
28
|
-
- lib/formatters.rb
|
29
|
-
- lib/formatters/polling_formatter.rb
|
30
|
-
- lib/formatters/print_formatter.rb
|
31
27
|
- lib/tramtracker.rb
|
32
|
-
-
|
33
|
-
-
|
28
|
+
- lib/tramtracker/api.rb
|
29
|
+
- lib/tramtracker/formatters.rb
|
30
|
+
- lib/tramtracker/formatters/polling_formatter.rb
|
31
|
+
- lib/tramtracker/formatters/print_formatter.rb
|
32
|
+
- lib/tramtracker/version.rb
|
33
|
+
- spec/fixtures/tramtracker.json
|
34
|
+
- spec/lib/tramtracker_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
34
36
|
- tramtracker.gemspec
|
35
37
|
homepage: https://github.com/stevenocchipinti/tramtracker
|
36
38
|
licenses: []
|
39
|
+
metadata: {}
|
37
40
|
post_install_message:
|
38
41
|
rdoc_options: []
|
39
42
|
require_paths:
|
40
43
|
- lib
|
41
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
45
|
requirements:
|
44
|
-
- -
|
46
|
+
- - '>='
|
45
47
|
- !ruby/object:Gem::Version
|
46
48
|
version: '0'
|
47
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
50
|
requirements:
|
50
|
-
- -
|
51
|
+
- - '>='
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
54
|
requirements: []
|
54
55
|
rubyforge_project:
|
55
|
-
rubygems_version:
|
56
|
+
rubygems_version: 2.2.2
|
56
57
|
signing_key:
|
57
|
-
specification_version:
|
58
|
+
specification_version: 4
|
58
59
|
summary: CLI TramTracker
|
59
60
|
test_files:
|
60
|
-
-
|
61
|
-
-
|
61
|
+
- spec/fixtures/tramtracker.json
|
62
|
+
- spec/lib/tramtracker_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
has_rdoc:
|
data/lib/formatters.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
describe Tramtracker do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@tramtracker = Tramtracker.new(1725)
|
7
|
-
@mock_response = <<-EOS
|
8
|
-
ID: 1725<br>\r\n
|
9
|
-
1) Rte 100<br>\r\n1 mins *<br>\r\n
|
10
|
-
2) Rte 101<br>\r\n10 mins *!<br>\r\n
|
11
|
-
3) Rte 102<br>\r\n20 mins *!<br>"
|
12
|
-
EOS
|
13
|
-
end
|
14
|
-
|
15
|
-
describe ".get" do
|
16
|
-
it "returns an array of hashes with route and time data" do
|
17
|
-
@tramtracker.stub :open, OpenStruct.new({:read => @mock_response}) do
|
18
|
-
@tramtracker.get.must_include({route: "100", minutes: "1"})
|
19
|
-
@tramtracker.get.must_include({route: "101", minutes: "10"})
|
20
|
-
@tramtracker.get.must_include({route: "102", minutes: "20"})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/test/test_helper.rb
DELETED