london_transport 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 758b678ef66589263b8018b8428f8fe63b9ebd31
4
- data.tar.gz: 999355165b3879bbec74d62e4079c88adfbeba10
3
+ metadata.gz: 65927a591dda8b00be0debfb9216c221d4999009
4
+ data.tar.gz: ee05e0b6a95c602c0750203dab236f1e75448eed
5
5
  SHA512:
6
- metadata.gz: e5b4683598d905c5b5680f4db58b9b56c77ae511e52906d963a2a19b680d1161c3d804ec01766b0d0b824ab068088ef32ffa8939af5290e0f2f17a94c85f1396
7
- data.tar.gz: 883de11c265ac84cb2375c7007d098dec6ef836f99bec0e3cb04c2adf8dc3b898edcafbeb04e7e89db1eb4072603b2fdc5c060dd1ebbeb7c26419643d0d8b39f
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
@@ -0,0 +1,10 @@
1
+ class LondonTransport::Bus < LondonTransport::Base
2
+ STOP_TYPES = [
3
+ "NaptanPublicBusCoachTram",
4
+ "NaptanBusCoachStation"
5
+ ]
6
+
7
+ MODES = [
8
+ 'bus'
9
+ ]
10
+ end
@@ -0,0 +1,11 @@
1
+ class LondonTransport::Train < LondonTransport::Base
2
+ STOP_TYPES = [
3
+ "NaptanRailStation"
4
+ ]
5
+
6
+ MODES = [
7
+ 'overground',
8
+ 'national-rail',
9
+ 'tflrail'
10
+ ]
11
+ end
@@ -0,0 +1,9 @@
1
+ class LondonTransport::Tube < LondonTransport::Base
2
+ STOP_TYPES = [
3
+ "NaptanMetroStation"
4
+ ]
5
+
6
+ MODES = [
7
+ 'tube'
8
+ ]
9
+ end
@@ -0,0 +1,3 @@
1
+ module LondonTransport
2
+ VERSION = '0.0.3'
3
+ 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.1
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