trafikanten-travel 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,5 @@
1
+ * 0.2.3
2
+ Found some more indicators that a route was not available
1
3
  * 0.2.0
2
4
  Route.new takes Station objects, not strings
3
5
  Route has a find class method for searching for routes
data/Gemfile CHANGED
@@ -3,3 +3,11 @@ source 'http://gemcutter.org'
3
3
 
4
4
  gem 'nokogiri', '1.4.1'
5
5
  gem 'geoutm', '0.0.4'
6
+
7
+ group :test do
8
+ gem 'rspec', '1.3.0'
9
+ end
10
+
11
+ group :development do
12
+ gem 'jeweler'
13
+ end
data/README.rdoc CHANGED
@@ -17,12 +17,13 @@ route:
17
17
  === Finding stations
18
18
  You query trafikanten.no by the name of the station and you receive an array of hits with information about each
19
19
 
20
+ require 'trafikanten_travel'
20
21
  stations = Station.find_by_name 'Sthanshaugen'
21
22
 
22
23
  The station objects will have attributes for name, id, type, lat and lng. lat and lng might not be available, and are then set to nil.
23
24
 
24
25
  === Finding a route between stations
25
- Once you have the stations, you use their IDs to create a Route object:
26
+ Once you have the stations, you use them to search for a Route:
26
27
 
27
28
  from = stations[0]
28
29
  to = stations[1]
@@ -31,13 +32,13 @@ Once you have the stations, you use their IDs to create a Route object:
31
32
  # or specify a time
32
33
  route = Route.find(from, to, a_time_object)
33
34
 
34
- This will query trafikanten.no for the first available route based on Time.now
35
- or the passed in time and parse the route it found, if any. The Route object
36
- will have a duration attribtue for the duration of the trip in minutes, and a
37
- steps array with a Step object for each leg of the journey. Each Step tells
38
- you its type (walk, wait, tram, subway, boat, train, bus), duration in
39
- minutes, and arrival and departure station names along with times for these.
40
- All these are attributes on the Step object.
35
+ This will query trafikanten.no for the first available route between the
36
+ stations based on Time.now or the passed in time and parse the route it found,
37
+ if any. The Route object will have a duration attribute for the duration of
38
+ the trip in minutes, and a steps array with a Step object for each leg of the
39
+ journey. Each Step object tells you its type (walk, wait, tram, subway, boat,
40
+ train, bus), duration in minutes, and arrival and departure station names
41
+ along with times for these. All these are attributes on the Step object.
41
42
 
42
43
  == TODO
43
44
  * Also include 'area' stations, which are not actual stations but regions
@@ -46,20 +47,18 @@ All these are attributes on the Step object.
46
47
  * Let the depart and arrive stations in Step be actual Station objects
47
48
 
48
49
  == Note on Patches/Pull Requests
49
-
50
+
50
51
  * Fork the project.
52
+ * Add tests in spec/
51
53
  * Make your feature addition or bug fix.
52
- * Add tests for it in spec/
53
- * Commit, do not mess with Rakefile or VERSION.
54
- (if you want to have your own version, that is fine but
55
- bump version in a commit by itself I can ignore when I pull)
54
+ * Commit, do not mess with Rakefile or VERSION. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56
55
  * Send me a pull request. Bonus points for topic branches.
57
56
 
58
57
  == Running tests
59
58
 
60
59
  rake
61
60
 
62
- If you get errors about missing gems - just install them.
61
+ If you get errors about missing gems - `bundle install` should get you sorted.
63
62
 
64
63
  == Copyright
65
64
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -8,6 +8,7 @@ module TrafikantenTravel
8
8
  include TrafikantenTravel::Utils
9
9
  attr_accessor :duration, :steps
10
10
  BASE_URL = 'http://m.trafikanten.no/BetRes.asp?'
11
+ NOTFOUND = /Ingen forbindelse funnet eller ingen stoppesteder funnet|Ingen turer ankommer ankomststed|Ingen turer utgår fra avgangsted/u
11
12
 
12
13
  # Searches and returns a Route object for the found trip
13
14
  def self.find(from, to, time = TrafikantenTravel::Utils.time_class.now)
@@ -23,20 +24,17 @@ module TrafikantenTravel
23
24
  @steps = []
24
25
  end
25
26
 
26
- # Parse the received HTML. First try some error-checking.
27
+ # Parse the received HTML. First try some simple error-checking.
27
28
  def parse
28
29
  doc = TrafikantenTravel::Utils.fetch(BASE_URL + query_string)
29
30
 
30
- if doc =~ /Ingen forbindelse funnet eller ingen stoppesteder funnet/
31
+ case doc
32
+ when NOTFOUND
31
33
  return {}
32
- end
33
-
34
- if doc =~ /Trafikanten - Feilmelding/
34
+ when /Trafikanten - Feilmelding/
35
35
  doc =~ /<p>(.+)<\/p>/
36
36
  raise Error.new($1)
37
- end
38
-
39
- if doc =~ /Microsoft VBScript runtime/
37
+ when /Microsoft VBScript runtime/
40
38
  raise BadRequest
41
39
  end
42
40
 
@@ -52,21 +52,21 @@ describe TrafikantenTravel::Route do
52
52
  context 'url generation' do
53
53
  # Test the whole thing
54
54
  it 'generates exactly this' do
55
- route = TrafikantenTravel::Route.find(@from, @to )
55
+ route = TrafikantenTravel::Route.new(@from, @to)
56
56
  query = route.send(:query_string)
57
57
  query.should == "fra=1000013064%3A&DepType=2&date=#{Time.now.strftime("%d.%m.%Y")}&til=02350113%3A&arrType=1&Transport=2,%207,%205,%208,%201,%206,%204&MaxRadius=700&type=1&tid=#{Time.now.strftime("%H.%M")}"
58
58
  end
59
59
 
60
60
  # Test the parts in isolation
61
61
  it 'takles stations and their types' do
62
- route = TrafikantenTravel::Route.find(@from, @to )
62
+ route = TrafikantenTravel::Route.new(@from, @to)
63
63
  query = route.send(:query_string)
64
64
  query.should =~ /fra=1000013064%3A&DepType=2/
65
65
  query.should =~ /til=02350113%3A&arrType=1/
66
66
  end
67
67
 
68
68
  it 'defaults to Time.now' do
69
- route = TrafikantenTravel::Route.find(@from, @to )
69
+ route = TrafikantenTravel::Route.new(@from, @to)
70
70
  query = route.send(:query_string)
71
71
  query.should =~ /date=#{Time.now.strftime("%d.%m.%Y")}/
72
72
  query.should =~ /tid=#{Time.now.strftime("%H.%M")}/
@@ -103,14 +103,20 @@ describe TrafikantenTravel::Route do
103
103
  <link rel="stylesheet" href="m.css" type="text/css" />
104
104
  <title>Trafikanten - Feilmelding</title>
105
105
  <body>
106
- <p>Ingen forbindelse funnet eller ingen stoppesteder funnet</p>
106
+ <p>%s</p>
107
107
  </body>
108
108
  </html>
109
109
  eos
110
110
 
111
- TrafikantenTravel::Utils.stub(:fetch).and_return(missing)
112
- route = TrafikantenTravel::Route.find(@from, @to)
113
- route.steps.should == []
111
+ [
112
+ 'Ingen turer ankommer ankomststed',
113
+ 'Ingen forbindelse funnet eller ingen stoppesteder funnet',
114
+ 'Ingen turer utgår fra avgangsted'
115
+ ].each do |notfound|
116
+ TrafikantenTravel::Utils.stub(:fetch).and_return(missing % notfound)
117
+ route = TrafikantenTravel::Route.find(@from, @to)
118
+ route.steps.should == []
119
+ end
114
120
  end
115
121
 
116
122
  it 'it parses errors and raises them locally' do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{trafikanten-travel}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rune Botten"]
12
- s.date = %q{2010-05-25}
12
+ s.date = %q{2010-05-30}
13
13
  s.description = %q{Query the travel planner at trafikanten.no with Ruby}
14
14
  s.email = %q{rbotten@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trafikanten-travel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rune Botten
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-25 00:00:00 +02:00
18
+ date: 2010-05-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency