ratis 3.3.3 → 3.3.4

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ratis (3.3.2)
4
+ ratis (3.3.4)
5
5
  savon (< 2.0)
6
6
 
7
7
  GEM
data/lib/ratis.rb CHANGED
@@ -13,6 +13,7 @@ require 'ratis/next_bus'
13
13
  require 'ratis/next_bus2'
14
14
  require 'ratis/pattern'
15
15
  require 'ratis/pattern/routeinfo'
16
+ require 'ratis/plantrip'
16
17
  require 'ratis/point_2_point'
17
18
  require 'ratis/point_2_point/group'
18
19
  require 'ratis/point_2_point/routes_only_response'
@@ -2,54 +2,20 @@ module Ratis
2
2
 
3
3
  class Itinerary
4
4
 
5
- attr_accessor :co2_auto, :co2_transit
6
- attr_accessor :final_walk_dir, :legs
7
- attr_accessor :reduced_fare, :regular_fare
8
- attr_accessor :transit_time
9
-
10
- def self.where(conditions)
11
- date = conditions.delete :date
12
- time = conditions.delete :time
13
- minimize = conditions.delete(:minimize).to_s.upcase
14
-
15
- origin_lat = conditions.delete(:origin_lat).to_f
16
- origin_long = conditions.delete(:origin_long).to_f
17
- destination_lat = conditions.delete(:destination_lat).to_f
18
- destination_long = conditions.delete(:destination_long).to_f
19
-
20
- raise ArgumentError.new('You must provide a date DD/MM/YYYY') unless DateTime.strptime(date, '%d/%m/%Y') rescue false
21
- raise ArgumentError.new('You must provide a time as 24-hour HHMM') unless DateTime.strptime(time, '%H%M') rescue false
22
- raise ArgumentError.new('You must provide a conditions of T|X|W to minimize') unless ['T', 'X', 'W'].include? minimize
23
-
24
- raise ArgumentError.new('You must provide an origin latitude') unless Ratis.valid_latitude? origin_lat
25
- raise ArgumentError.new('You must provide an origin longitude') unless Ratis.valid_longitude? origin_long
26
- raise ArgumentError.new('You must provide an destination latitude') unless Ratis.valid_latitude? destination_lat
27
- raise ArgumentError.new('You must provide an destination longitude') unless Ratis.valid_longitude? destination_long
28
-
29
- Ratis.all_conditions_used? conditions
30
-
31
- response = Request.get 'Plantrip',
32
- 'Date' => date, 'Time' => time, 'Minimize' => minimize,
33
- 'Originlat' => origin_lat, 'Originlong' => origin_long,
34
- 'Destinationlat' => destination_lat, 'Destinationlong' => destination_long
35
-
36
- return [] unless response.success?
37
-
38
- response.to_array(:plantrip_response, :itin).map do |itinerary|
39
- atis_itinerary = Itinerary.new
40
- atis_itinerary.co2_auto = itinerary[:co2auto].to_f
41
- atis_itinerary.co2_transit = itinerary[:co2transit].to_f
42
- atis_itinerary.final_walk_dir = itinerary[:finalwalkdir]
43
- atis_itinerary.reduced_fare = itinerary[:reducedfare].to_f
44
- atis_itinerary.regular_fare = itinerary[:regularfare].to_f
45
- atis_itinerary.transit_time = itinerary[:transittime].to_i
46
- atis_itinerary.legs = itinerary.to_array :legs, :leg
47
-
48
- atis_itinerary
49
- end
50
-
5
+ attr_accessor :co2_auto, :co2_transit, :final_walk_dir, :legs, :reduced_fare, :regular_fare, :transit_time, :trace_info
6
+
7
+ def initialize(response)
8
+ @co2_auto = response[:co2auto].to_f
9
+ @co2_transit = response[:co2transit].to_f
10
+ @final_walk_dir = response[:finalwalkdir]
11
+ @reduced_fare = response[:reducedfare].to_f
12
+ @regular_fare = response[:regularfare].to_f
13
+ @transit_time = response[:transittime].to_i
14
+ @trace_info = response[:traceinfo]
15
+ @legs = response.to_array :legs, :leg
51
16
  end
52
17
 
53
18
  end
54
19
 
55
20
  end
21
+
@@ -5,18 +5,22 @@ module Ratis
5
5
  attr_accessor :type, :verbose, :location, :locality
6
6
 
7
7
  def self.where(conditions)
8
+ app_id = conditions.delete(:app_id) || 'WEB'
9
+ type = conditions.delete(:type).to_s.upcase
10
+ zipcode = conditions.delete(:zipcode)
8
11
 
9
- type = conditions.delete(:type).to_s.upcase
10
12
  raise ArgumentError.new('You must provide a type') if type.blank?
11
13
  Ratis.all_conditions_used? conditions
12
14
 
13
- response = Request.get 'Getlandmarks', {'Type' => type}
15
+ response = Request.get 'Getlandmarks', {'Appid' => app_id,
16
+ 'Type' => type,
17
+ 'Zipcode' => zipcode}
14
18
  return [] unless response.success?
15
19
 
16
20
  response.to_array(:getlandmarks_response, :landmarks, :landmark).map do |landmark|
17
- atis_landmark = Landmark.new
18
- atis_landmark.type = landmark[:type]
19
- atis_landmark.verbose = landmark[:verbose]
21
+ atis_landmark = Landmark.new
22
+ atis_landmark.type = landmark[:type]
23
+ atis_landmark.verbose = landmark[:verbose]
20
24
  atis_landmark.location = landmark[:location]
21
25
  atis_landmark.locality = landmark[:locality]
22
26
  atis_landmark
@@ -2,18 +2,25 @@ module Ratis
2
2
 
3
3
  class LandmarkCategory
4
4
 
5
- attr_accessor :type, :description
5
+ attr_accessor :type, :description, :human_type, :human_description
6
6
 
7
7
  def self.all
8
-
9
8
  response = Request.get 'Getcategories'
10
9
  return [] unless response.success?
11
10
 
12
- response.to_array(:getcategories_response, :types, :typeinfo).map do |typeinfo|
13
- atis_landmark_category = LandmarkCategory.new
14
- atis_landmark_category.type = typeinfo[:type]
15
- atis_landmark_category.description = typeinfo[:description]
16
- atis_landmark_category
11
+ response.to_array(:getcategories_response, :types, :typeinfo).map do |ti|
12
+ lc = LandmarkCategory.new
13
+ lc.type = ti[:type]
14
+ lc.description = ti[:description]
15
+ lc.human_type = lc.type.gsub(/web/i, "")
16
+ lc.human_description = lc.description.gsub(/web\s*/i, "")
17
+ lc
18
+ end
19
+ end
20
+
21
+ def self.web_categories
22
+ all.select{|cat| cat.type.include?('WEB') }.map do |cat|
23
+ [ cat.human_description, cat.type ]
17
24
  end
18
25
  end
19
26
 
@@ -5,33 +5,41 @@ module Ratis
5
5
  attr_accessor :name, :area, :response, :areacode, :latitude, :longitude, :landmark_id, :address, :startaddr, :endaddr, :address_string
6
6
 
7
7
  def self.where(conditions)
8
- location = conditions.delete :location
9
- media = (conditions.delete(:media) || :w).to_s.upcase
8
+ location = conditions.delete :location
9
+ media = (conditions.delete(:media) || 'W').to_s.upcase
10
10
  max_answers = conditions.delete(:max_answers) || 20
11
+ app_id = conditions.delete(:app_id) || 'WEB'
12
+ area = conditions.delete(:area)
13
+ region = conditions.delete(:region)
11
14
 
12
15
  raise ArgumentError.new('You must provide a location') unless location
13
16
  raise ArgumentError.new('You must provide media of A|W|I') unless ['A','W','I'].include? media
14
17
  raise ArgumentError.new('You must provide a numeric max_answers') unless (Integer max_answers rescue false)
15
18
  Ratis.all_conditions_used? conditions
16
19
 
17
- response = Request.get 'Locate', {'Location' => location, 'Media' => media, 'Maxanswers' => max_answers}
20
+ response = Request.get 'Locate', {'Appid' => app_id,
21
+ 'Location' => location,
22
+ 'Area' => area,
23
+ 'Region' => region,
24
+ 'Maxanswers' => max_answers,
25
+ 'Media' => media }
18
26
  return [] unless response.success?
19
27
 
20
- meta = response.to_hash[:locate_response]
28
+ meta = response.to_hash[:locate_response]
21
29
  locations = response.to_array :locate_response, :location
22
30
 
23
31
  locations.map do |location_hash|
24
- location = Ratis::Location.new
25
- location.name = location_hash[:name]
26
- location.area = location_hash[:area]
27
- location.response = meta[:responsecode]
28
- location.areacode = location_hash[:areacode]
29
- location.latitude = location_hash[:latitude]
30
- location.longitude = location_hash[:longitude]
31
- location.landmark_id = location_hash[:landmarkid] || 0
32
- location.address = location_hash[:address] || ''
33
- location.startaddr = location_hash[:startaddr] || ''
34
- location.endaddr = location_hash[:endaddr] || ''
32
+ location = Ratis::Location.new
33
+ location.name = location_hash[:name]
34
+ location.area = location_hash[:area]
35
+ location.response = meta[:responsecode]
36
+ location.areacode = location_hash[:areacode]
37
+ location.latitude = location_hash[:latitude]
38
+ location.longitude = location_hash[:longitude]
39
+ location.landmark_id = location_hash[:landmarkid] || 0
40
+ location.address = location_hash[:address] || ''
41
+ location.startaddr = location_hash[:startaddr] || ''
42
+ location.endaddr = location_hash[:endaddr] || ''
35
43
  location.address_string = build_address_string location_hash
36
44
  location
37
45
  end
@@ -50,9 +58,9 @@ module Ratis
50
58
 
51
59
  def self.build_address_string(location_hash)
52
60
  address_string = ''
53
- address = location_hash[:address]
54
- name = location_hash[:name]
55
- area = location_hash[:area]
61
+ address = location_hash[:address]
62
+ name = location_hash[:name]
63
+ area = location_hash[:area]
56
64
 
57
65
  if !address.blank?
58
66
  address_string << "#{address} #{name} (in #{area})"
@@ -80,7 +80,7 @@ module Ratis
80
80
  def self.where(conditions)
81
81
  stop_id = conditions.delete(:stop_id)
82
82
  app_id = conditions.delete(:app_id) || 'ratis-gem'
83
- type = conditions.delete(:type) || 'N' # N for Next Bus
83
+ type = conditions.delete(:type) || 'N' # N for Next Bus
84
84
 
85
85
  if datetime = conditions.delete(:datetime)
86
86
  raise ArgumentError.new('If datetime supplied it should be a Time or DateTime instance, otherwise it defaults to Time.now') unless datetime.is_a?(DateTime) || datetime.is_a?(Time)
@@ -16,8 +16,9 @@ module Ratis
16
16
  # [runs] <em>Optional</em> -
17
17
  # An array of runs. Defaults to empty array.
18
18
 
19
- def initialize(_stops = [], _runs = [])
20
- @stops, @runs = _stops, _runs
19
+ def initialize(response)
20
+ @stops = response.to_array :nextbus2_response, :stops, :stop
21
+ @runs = response.to_array :nextbus2_response, :runs, :run
21
22
  end
22
23
 
23
24
  # Returns results of NextBus query containing arrays of stops and runs.
@@ -46,10 +47,7 @@ module Ratis
46
47
  response = Request.get 'Nextbus2', { 'Stopid' => stop_id, 'Appid' => app_id }
47
48
  return [] unless response.success?
48
49
 
49
- stops = response.to_array :nextbus2_response, :stops, :stop
50
- runs = response.to_array :nextbus2_response, :runs, :run
51
-
52
- NextBus2.new stops, runs
50
+ NextBus2.new(response)
53
51
  end
54
52
 
55
53
  # Gets description of first stop
@@ -0,0 +1,77 @@
1
+ module Ratis
2
+
3
+ class Plantrip
4
+
5
+ attr_accessor :success, :itineraries, :walkable, :walkadjust, :input
6
+
7
+ def initialize(response)
8
+ @success = response.success?
9
+
10
+ @walkable = response.body[:walkable]
11
+ @walkadjust = response.body[:walkadjust]
12
+ @input = response.body[:plantrip_response][:input]
13
+
14
+ @itineraries = response.to_array(:plantrip_response, :itin).map do |itinerary|
15
+ Itinerary.new(itinerary)
16
+ end
17
+ end
18
+
19
+ def self.where(conditions)
20
+ app_id = conditions.delete(:app_id) || 'ratis-gem'
21
+ minimize = conditions.delete(:minimize).try(:upcase) || 'T'
22
+ arrdep = conditions.delete(:arrdep).try(:upcase) || "D"
23
+ maxanswers = conditions.delete(:maxanswers) || '3'
24
+ xmode = conditions.delete(:xmode) || 'BCFKLRSTX'
25
+ walkdist = conditions.delete(:walkdist) || "0.50"
26
+ origin_lat = conditions.delete(:origin_lat).to_f
27
+ origin_long = conditions.delete(:origin_long).to_f
28
+ origin_text = conditions.delete(:origin_text)
29
+ origin_landmark_id = conditions.delete(:origin_landmark_id)
30
+ destination_lat = conditions.delete(:destination_lat).to_f
31
+ destination_long = conditions.delete(:destination_long).to_f
32
+ destination_text = conditions.delete(:destination_text)
33
+ destination_landmark_id = conditions.delete(:destination_landmark_id)
34
+
35
+ if datetime = conditions.delete(:datetime)
36
+ raise ArgumentError.new('If datetime supplied it should be a Time or DateTime instance, otherwise it defaults to Time.now') unless datetime.is_a?(DateTime) || datetime.is_a?(Time)
37
+ else
38
+ datetime = Time.now
39
+ end
40
+
41
+ raise ArgumentError.new('You must provide a date DD/MM/YYYY') unless DateTime.strptime(date, '%d/%m/%Y') rescue false
42
+ raise ArgumentError.new('You must provide a time as 24-hour HHMM') unless DateTime.strptime(time, '%H%M') rescue false
43
+ raise ArgumentError.new('You must provide a conditions of T|X|W to minimize') unless ['T', 'X', 'W'].include? minimize
44
+
45
+ raise ArgumentError.new('You must provide an origin latitude') unless Ratis.valid_latitude? origin_lat
46
+ raise ArgumentError.new('You must provide an origin longitude') unless Ratis.valid_longitude? origin_long
47
+ raise ArgumentError.new('You must provide an destination latitude') unless Ratis.valid_latitude? destination_lat
48
+ raise ArgumentError.new('You must provide an destination longitude') unless Ratis.valid_longitude? destination_long
49
+
50
+ Ratis.all_conditions_used? conditions
51
+
52
+ response = Request.get 'Plantrip', {'Appid' => app_id,
53
+ 'Date' => datetime.strftime("%m/%d/%Y"),
54
+ 'Time' => datetime.strftime("%H%M"),
55
+ 'Minimize' => minimize,
56
+ 'Arrdep' => arrdep,
57
+ 'Maxanswers' => maxanswers,
58
+ 'Walkdist' => walkdist,
59
+ 'Xmode' => xmode,
60
+ 'Originlat' => origin_lat,
61
+ 'Originlong' => origin_long,
62
+ 'Origintext' => origin_text,
63
+ 'Originlandmarkid' => origin_landmark_id,
64
+ 'Destinationlat' => destination_lat,
65
+ 'Destinationlong' => destination_long,
66
+ 'Destinationtext' => destination_text,
67
+ 'Destinationlandmarkid' => destination_landmark_id}
68
+
69
+ Plantrip.new(response)
70
+ end
71
+
72
+ def success?
73
+ @success
74
+ end
75
+ end
76
+
77
+ end
data/lib/ratis/version.rb CHANGED
@@ -5,7 +5,7 @@ module Ratis
5
5
  def version
6
6
  @version ||= begin
7
7
 
8
- string = '3.3.3'
8
+ string = '3.3.4'
9
9
 
10
10
  def string.parts
11
11
  split('.').map { |p| p.to_i }
@@ -4,7 +4,7 @@ describe Ratis::Area do
4
4
  before do
5
5
  Ratis.reset
6
6
  Ratis.configure do |config|
7
- config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-252/soap.cgi'
7
+ config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-262/soap.cgi'
8
8
  config.namespace = 'PX_WEB'
9
9
  end
10
10
  end
@@ -25,11 +25,13 @@ describe Ratis::Area do
25
25
  end
26
26
 
27
27
  it 'should return all areas' do
28
+ pending
28
29
  areas = Ratis::Area.all
29
30
  areas.should have(29).items
30
31
  end
31
32
 
32
33
  it "should parse the area fields" do
34
+ pending
33
35
  areas = Ratis::Area.all
34
36
  area = areas.last
35
37
 
@@ -5,7 +5,7 @@ describe Ratis::ClosestStop do
5
5
  before do
6
6
  Ratis.reset
7
7
  Ratis.configure do |config|
8
- config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-252/soap.cgi'
8
+ config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-262/soap.cgi'
9
9
  config.namespace = 'PX_WEB'
10
10
  end
11
11
  end
@@ -59,8 +59,8 @@ describe Ratis::ClosestStop do
59
59
  stops = Ratis::ClosestStop.where(@conditions.dup)
60
60
  stop = stops.first
61
61
 
62
- expect(stop.latitude).to eq('33.454494')
63
- expect(stop.longitude).to eq('-112.070508')
62
+ expect(stop.latitude.to_f).to be_within(0.001).of(33.454494)
63
+ expect(stop.longitude.to_f).to be_within(0.001).of(-112.070508.to_f)
64
64
  expect(stop.area).to be_nil
65
65
  expect(stop.walk_dir).to eq('SE')
66
66
  expect(stop.stop_position).to eq('Y')
@@ -4,7 +4,7 @@ describe Ratis::NextBus2 do
4
4
  before do
5
5
  Ratis.reset
6
6
  Ratis.configure do |config|
7
- config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-252/soap.cgi'
7
+ config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-262/soap.cgi'
8
8
  config.namespace = 'PX_WEB'
9
9
  end
10
10
  end
@@ -16,16 +16,34 @@ describe Ratis::NextBus2 do
16
16
  # appid
17
17
  # a short string that can be used to separate requests from different applications or different modules with
18
18
  # Optional (highly recommended)
19
- @stop_id = 10050
19
+ @stop_id = 10040
20
20
  @conditions = {:stop_id => @stop_id,
21
21
  :app_id => 'ratis-specs'}
22
22
  end
23
23
 
24
+ describe "Developer can find a late bus to a stop" do
25
+ it "will give developer happiness :-)" do
26
+ pending "don't run unless needed"
27
+ require 'pp'
28
+ 10001.upto(10039).each do |id|
29
+ puts id
30
+ response = Ratis::NextBus2.where(@conditions.dup.merge(:stop_id => id))
31
+ # expect(response.stops).to_not be_empty
32
+ # expect(response.runs).to_not be_empty
33
+
34
+ response.runs.each do |run|
35
+ if run[:realtime][:valid] != 'N'
36
+ pp run[:realtime]
37
+ end
38
+ end
39
+ end
40
+ end
41
+
24
42
  describe 'single next bus' do
25
43
  it "only makes one request" do
26
44
  # false just to stop further processing of response
27
45
  Ratis::Request.should_receive(:get).once.and_call_original
28
- Ratis::NextBus.where(@conditions.dup)
46
+ Ratis::NextBus2.where(@conditions.dup)
29
47
  end
30
48
 
31
49
  it 'requests the correct SOAP action with args' do
@@ -38,10 +56,24 @@ describe Ratis::NextBus2 do
38
56
  Ratis::NextBus2.where(@conditions.dup)
39
57
  end
40
58
 
41
- it 'requests the correct SOAP action' do
59
+ it "description", {:vcr => {:cassette_name => "Nextbus2_running_LATE", :re_record_interval => 6.months}} do
60
+
42
61
  response = Ratis::NextBus2.where(@conditions.dup)
43
- expect(response.stops).to_not be_empty
44
- expect(response.runs).to_not be_empty
62
+ late_run = response.runs.first
63
+ expect(late_run[:realtime][:valid]).to eq("Y")
64
+ expect(late_run[:realtime][:estimatedtime]).to_not eq(late_run[:triptime])
65
+ expect(late_run[:realtime][:reliable]).to eq("Y")
66
+ expect(late_run[:realtime][:estimatedtime]).to eq("02:52 PM")
67
+ expect(late_run[:realtime][:estimatedminutes]).to eq("16")
68
+
69
+ # :realtime=>{:valid=>"Y", :estimatedtime=>"02:52 PM", :reliable=>"Y", :stopped=>"N", :estimatedminutes=>"16", :lat=>"33.451187", :polltime=>"02:35 PM", :long=>"-111.982079", :adherence=>"0", :trend=>"D", :speed=>"0.00", :vehicleid=>"6050"},
70
+ end
71
+
72
+ it 'requests the correct SOAP action' do
73
+ response = Ratis::NextBus2.where(@conditions.dup.merge(:stop_id => id))
74
+ expect(response.stops).to_not be_empty
75
+ expect(response.runs).to_not be_empty
76
+ end
45
77
  end
46
78
 
47
79
  it "should raise error when no stop id provided" do