Module: TFLJourneyPlanner::Results

Includes:
HTTParty
Included in:
Client
Defined in:
lib/results.rb

Constant Summary collapse

BASE_URI =
'http://api.tfl.gov.uk/Journey/JourneyResults/%7Bfrom%7D/to/%7Bto%7D/via/%7Bvia%7D'

Instance Method Summary collapse

Instance Method Details

#disambiguate(results) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/results.rb', line 61

def disambiguate results
	options = []
	find_common_names = lambda { |option| options << option["place"]["common_name"] }
	results["to_location_disambiguation"]["disambiguation_options"].each(&find_common_names) if results["to_location_disambiguation"]["disambiguation_options"]
	results["from_location_disambiguation"]["disambiguation_options"].each(&find_common_names) if results["from_location_disambiguation"]["disambiguation_options"]
	puts "Did you mean?\n\n"
	options.each {|o| puts o + "\n"}
	false
end

#get_journeys(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/results.rb', line 14

def get_journeys(options)
	from = options[:from].gsub(" ", "+")
	to = options[:to].gsub(" ", "+")
	via = options[:via]
	national_search = options[:national_search] || false
	time  = options[:time]
	date = options[:date]
	time_is = options[:time_is] || "Departing"
	journey_preference = options[:journey_preference]
	mode = options[:mode]
	from_name = options[:from_name]
	to_name = options[:to_name]
	via_name = options[:via_name]
	max_transfer_minutes = options[:max_transfer_minutes]
	max_walking_minutes = options[:max_walking_minutes]
	cycle_preference = options[:cycle_preference]
	adjustment = options[:adjustment]
	alternative_cycle = options[:alternative_cycle] || false
	alternative_walking = options[:alternative_walking] || true
	apply_html_markup = options[:apply_html_markup] || false

	results = self.class.get(BASE_URI, query: 
		{app_key: app_key, 
		app_id: app_id, 
		from: from, 
		to: to, 
		via: via, 
		nationalSearch: national_search,
		time: time,
		date: date,
		timeIs: time_is,
		journeyPreference: journey_preference,
		mode: mode,
		fromName: from_name,
		toName: to_name,
		viaName: via_name,
		maxTransferMinutes: max_transfer_minutes,
		maxWalkingMinutes: max_walking_minutes,
		cyclePreference: cycle_preference,
		adjustment: adjustment,
		alternativeCycle: alternative_cycle, 
		alternativeWalking: alternative_walking, 
		applyHtmlMarkup: apply_html_markup}).rubyify_keys!

	results["$type"].include?("DisambiguationResult") ? (disambiguate results) : (process_journeys_from results)
end

#process_journeys_from(results) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/results.rb', line 71

def process_journeys_from results
	array = []
	results["journeys"].each do |journey|
		array << TFLJourneyPlanner::Journey.new(journey, recurse_over_arrays: true)
	end
	return array
end