london_transport 0.0.1 → 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/README.md +39 -0
- data/lib/london_transport/base.rb +39 -0
- data/lib/london_transport/bus.rb +10 -0
- data/lib/london_transport/train.rb +11 -0
- data/lib/london_transport/tube.rb +9 -0
- data/lib/london_transport/version.rb +3 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65927a591dda8b00be0debfb9216c221d4999009
|
4
|
+
data.tar.gz: ee05e0b6a95c602c0750203dab236f1e75448eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dcf1599316ab19241f9139dbedf24558f36a719bee8c4d2cc9997b58b484a369460c1732f3e45abfea7ddfe590f3b14ab81f1610f2c403fc566759789df42e9
|
7
|
+
data.tar.gz: c22f17cdc61ef84054643a4532eb5d13c05695e8291957ded16d9a5726f02a871360057695a26c2f369a651284be1d8b24bbc4c144b3197d1fe422707d81481c
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# London Transport
|
2
|
+
A TFL API consumer to turn the TFL API into useful, easy to parse data
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add `gem 'london_transport'` to your gem file `bundle install`
|
6
|
+
|
7
|
+
Set the TFL app key and id with:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
LondonTransport.app_key = 'your-app-key'
|
11
|
+
LondonTransport.app_id = 'your-app-id'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
Find the nearest tube stations from a long/lat value:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
transport = LondonTransport::Tube.new(longitude: -0.1440493, latitude: 51.5152117)
|
19
|
+
```
|
20
|
+
|
21
|
+
`transport.stations` will then return an array of the nearest 3 tube stations and their distances (in metres) to this point, within 500m
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
[
|
25
|
+
[0] {
|
26
|
+
"Oxford Circus Underground Station" => 147.70533261648208
|
27
|
+
},
|
28
|
+
[1] {
|
29
|
+
"Bond Street Underground Station" => 403.48258984823457
|
30
|
+
}
|
31
|
+
]
|
32
|
+
```
|
33
|
+
|
34
|
+
To set the size of the radius, just add radius to the initialisation attributes (radius is in metres):
|
35
|
+
`transport = LondonTransport::Tube.new(longitude: -0.1440493, latitude: 51.5152117, radius: 600)`
|
36
|
+
|
37
|
+
To return more than 3 stations, simply add the number you want as an argument on the stations method:
|
38
|
+
`transport.stations(20)`
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class LondonTransport::Base
|
2
|
+
|
3
|
+
API_ENDPOINT = "https://api.tfl.gov.uk/StopPoint"
|
4
|
+
STOP_TYPES = []
|
5
|
+
MODES = []
|
6
|
+
|
7
|
+
def initialize(longitude:, latitude:, radius: 500)
|
8
|
+
@longitude = longitude
|
9
|
+
@latitude = latitude
|
10
|
+
@radius = radius
|
11
|
+
end
|
12
|
+
|
13
|
+
def stations(limit = 3)
|
14
|
+
distances = []
|
15
|
+
nearest['stopPoints'][0..limit - 1].each do |station|
|
16
|
+
distances << { station['commonName'] => station['distance'] }
|
17
|
+
end
|
18
|
+
|
19
|
+
distances
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def api_endpoint
|
24
|
+
URI("#{API_ENDPOINT}?lat=#{@latitude}&lon=#{@longitude}&stopTypes=#{stop_types}&radius=#{@radius}&useStopPointHierarchy=True&returnLines=True&modes=#{modes}&app_id=#{LondonTransport.app_id}&app_key=#{LondonTransport.app_key}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop_types
|
28
|
+
@stop_types ||= self.class::STOP_TYPES.join(',')
|
29
|
+
end
|
30
|
+
|
31
|
+
def modes
|
32
|
+
@modes ||= self.class::MODES.join(',')
|
33
|
+
end
|
34
|
+
|
35
|
+
def nearest
|
36
|
+
Oj.load(Net::HTTP.get(api_endpoint))
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: london_transport
|
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
|
- Edwin Wills
|
@@ -72,7 +72,13 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- README.md
|
75
76
|
- lib/london_transport.rb
|
77
|
+
- lib/london_transport/base.rb
|
78
|
+
- lib/london_transport/bus.rb
|
79
|
+
- lib/london_transport/train.rb
|
80
|
+
- lib/london_transport/tube.rb
|
81
|
+
- lib/london_transport/version.rb
|
76
82
|
homepage: http://rubygems.org/gems/london_transport
|
77
83
|
licenses:
|
78
84
|
- MIT
|