journey_planner 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/journey.rb +18 -0
- data/lib/journey_planner/version.rb +3 -0
- data/lib/journey_planner.rb +27 -0
- data/lib/results.rb +66 -0
- data/lib/rubify_keys.rb +16 -0
- data/spec/client_spec.rb +15 -0
- data/spec/fixtures/tfl_jp_casettes/hello.yml +1234 -0
- data/spec/journey_spec.rb +33 -0
- data/spec/results_spec.rb +24 -0
- data/spec/spec_helper.rb +17 -0
- data/tfl_jp.gemspec +22 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0f7f3371e9706ca00177cc47807103d28419b28
|
4
|
+
data.tar.gz: ae47cf3fc692af55909a29b2c6f4f0ad59d9026d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e0856d2adb600449bef9f25febbb838c0ed9d3a8078b60573a733c30f5b2077c17ce8387a655109cc17c7ee22a164a8808d283d9e877d8ee4abedee5e8fcc19
|
7
|
+
data.tar.gz: e556715914fce4c00a15fef9e9158868db0f5351ff308652b7408f0216b64a4778b695b5b866f211518230308157097f8ff75bf9562168afa675aa8bc552dd8a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in tfl_jp.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'httparty'
|
7
|
+
gem 'recursive-open-struct'
|
8
|
+
gem 'active-support'
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'webmock'
|
12
|
+
gem 'vcr'
|
13
|
+
gem 'turn'
|
14
|
+
gem 'rake'
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 jpatel531
|
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,31 @@
|
|
1
|
+
# Unofficial TFL Journey Planner Gem
|
2
|
+
|
3
|
+
A Ruby-wrapper for the TFL Journey Planner API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'journey_planner'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install journey_planner
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/tfl_jp/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/journey.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module TFLJourneyPlanner
|
2
|
+
|
3
|
+
class Journey < RecursiveOpenStruct
|
4
|
+
def instructions
|
5
|
+
array = []
|
6
|
+
legs.each do |leg|
|
7
|
+
if leg.instruction.steps.any?
|
8
|
+
leg.instruction.steps.each {|step| array << step.description}
|
9
|
+
else
|
10
|
+
array << leg.instruction.summary + " / " + leg.instruction.detailed
|
11
|
+
end
|
12
|
+
end
|
13
|
+
return array
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "tfl_jp/version"
|
2
|
+
require "httparty"
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'recursive-open-struct'
|
6
|
+
require_relative 'results'
|
7
|
+
require_relative 'journey'
|
8
|
+
|
9
|
+
|
10
|
+
module TFLJourneyPlanner
|
11
|
+
|
12
|
+
class Client
|
13
|
+
|
14
|
+
include HTTParty
|
15
|
+
include TFLJourneyPlanner::Results
|
16
|
+
|
17
|
+
attr_reader :app_key, :app_id
|
18
|
+
|
19
|
+
def initialize(options)
|
20
|
+
@app_key = options[:app_key]
|
21
|
+
@app_id = options[:app_id]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
data/lib/results.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'rubify_keys'
|
2
|
+
|
3
|
+
module TFLJourneyPlanner
|
4
|
+
|
5
|
+
module Results
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
BASE_URI = 'http://api.tfl.gov.uk/Journey/JourneyResults/%7Bfrom%7D/to/%7Bto%7D/via/%7Bvia%7D'
|
10
|
+
|
11
|
+
format :json
|
12
|
+
|
13
|
+
|
14
|
+
def get_journeys(options)
|
15
|
+
from = options[:from].gsub(" ", "+")
|
16
|
+
to = options[:to].gsub(" ", "+")
|
17
|
+
via = options[:via]
|
18
|
+
national_search = options[:national_search] || false
|
19
|
+
time_is = options[:time_is] || "Departing"
|
20
|
+
journey_preference = options[:journey_preference]
|
21
|
+
mode = options[:mode]
|
22
|
+
from_name = options[:from_name]
|
23
|
+
to_name = options[:to_name]
|
24
|
+
via_name = options[:via_name]
|
25
|
+
max_transfer_minutes = options[:max_transfer_minutes]
|
26
|
+
max_walking_minutes = options[:max_walking_minutes]
|
27
|
+
cycle_preference = options[:cycle_preference]
|
28
|
+
adjustment = options[:adjustment]
|
29
|
+
alternative_cycle = options[:alternative_cycle] || false
|
30
|
+
alternative_walking = options[:alternative_walking] || true
|
31
|
+
apply_html_markup = options[:apply_html_markup] || false
|
32
|
+
|
33
|
+
results = self.class.get(BASE_URI, query:
|
34
|
+
{app_key: app_key,
|
35
|
+
app_id: app_id,
|
36
|
+
from: from,
|
37
|
+
to: to,
|
38
|
+
via: via,
|
39
|
+
nationalSearch: national_search,
|
40
|
+
timeIs: time_is,
|
41
|
+
journeyPreference: journey_preference,
|
42
|
+
mode: mode,
|
43
|
+
fromName: from_name,
|
44
|
+
toName: to_name,
|
45
|
+
viaName: via_name,
|
46
|
+
maxTransferMinutes: max_transfer_minutes,
|
47
|
+
maxWalkingMinutes: max_walking_minutes,
|
48
|
+
cyclePreference: cycle_preference,
|
49
|
+
adjustment: adjustment,
|
50
|
+
alternativeCycle: alternative_cycle,
|
51
|
+
alternativeWalking: alternative_walking,
|
52
|
+
applyHtmlMarkup: apply_html_markup}).rubyify_keys!
|
53
|
+
process_journeys_from results
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_journeys_from results
|
57
|
+
array = []
|
58
|
+
results["journeys"].each do |journey|
|
59
|
+
array << TFLJourneyPlanner::Journey.new(journey, recurse_over_arrays: true)
|
60
|
+
end
|
61
|
+
return array
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/rubify_keys.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support/core_ext/string'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
|
5
|
+
def rubyify_keys!
|
6
|
+
keys.each{|k|
|
7
|
+
v = delete(k)
|
8
|
+
new_key = k.to_s.underscore
|
9
|
+
self[new_key] = v
|
10
|
+
v.rubyify_keys! if v.is_a?(Hash)
|
11
|
+
v.each{|p| p.rubyify_keys! if p.is_a?(Hash)} if v.is_a?(Array)
|
12
|
+
}
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe TFLJourneyPlanner::Client do
|
4
|
+
|
5
|
+
it 'has to be initialized with an app id and app key' do
|
6
|
+
expect{TFLJourneyPlanner::Client.new}.to raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has an app key and app id' do
|
10
|
+
client = TFLJourneyPlanner::Client.new(app_id: ENV["TFL_ID"], app_key: ENV["TFL_KEY"])
|
11
|
+
expect(client.app_key).to eq ENV["TFL_KEY"]
|
12
|
+
expect(client.app_id).to eq ENV["TFL_ID"]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|