gares 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Guardfile +6 -0
- data/README.md +22 -22
- data/lib/gares/base.rb +8 -8
- data/lib/gares/sales.rb +1 -1
- data/lib/gares/search.rb +15 -12
- data/lib/gares/services.rb +1 -1
- data/lib/gares/station.rb +5 -0
- data/lib/gares/station_list.rb +12 -0
- data/lib/gares/version.rb +1 -1
- data/lib/gares.rb +2 -2
- data/spec/gares/gare_spec.rb +5 -6
- data/spec/gares/sales_spec.rb +1 -1
- data/spec/gares/search_spec.rb +21 -8
- metadata +5 -4
- data/lib/gares/gare.rb +0 -5
- data/lib/gares/gare_list.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 371e96298472d334dcfbce42c20bc6a67813139a
|
4
|
+
data.tar.gz: 3dc98f7e626ed7d6092b912a8e3441047bffb0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a404991c7555b8c65ccfa57987f8e553b03f18c284be6a73536ab0ab3213e8060e32faafe29b2d4b8492c340d0ec8586ffe7cbf0b678ba8f71efe1485b69aa
|
7
|
+
data.tar.gz: a19cc680b00bc2244cf8670e0c60e60c91a92e75a0bade68004abc8adfc6f3c9e90a58000cc25700b0186629cbf0de49969162831c34a5caff3b9c48e40bccb9
|
data/.gitignore
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# Gares
|
1
|
+
# Gares - A gem to interact with French train Stations
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/paulRbr/gares.svg)](https://travis-ci.org/paulRbr/gares) [![Gem Version](https://badge.fury.io/rb/gares.svg)](http://badge.fury.io/rb/gares) [![Coverage Status](https://coveralls.io/repos/paulRbr/gares/badge.svg)](https://coveralls.io/r/paulRbr/gares)
|
4
4
|
|
5
5
|
## Description
|
6
6
|
|
7
|
-
The Gares gem allows you to
|
7
|
+
The Gares gem allows you to easily access publicly available data from gares-en-mouvement.com.
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
11
11
|
Gares currently features the following:
|
12
12
|
|
13
|
-
* Search for a
|
14
|
-
* Retrieve
|
13
|
+
* Search for a station
|
14
|
+
* Retrieve station information
|
15
15
|
|
16
16
|
## Examples
|
17
17
|
|
18
|
-
###
|
18
|
+
### Station:
|
19
19
|
|
20
|
-
g = Gares::
|
20
|
+
g = Gares::Station.new("frlpd")
|
21
21
|
|
22
22
|
g.name
|
23
23
|
#=> "Lyon Part Dieu"
|
@@ -38,41 +38,41 @@ Gares currently features the following:
|
|
38
38
|
|
39
39
|
g = Gares::Search.new("Aix")
|
40
40
|
|
41
|
-
g.
|
41
|
+
g.stations.size
|
42
42
|
#=> 7
|
43
43
|
|
44
44
|
# or
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
stations = Gares::Station.search("lyon")
|
47
|
+
station = stations.last
|
48
48
|
|
49
|
-
|
49
|
+
station.name
|
50
50
|
#=> "Paris Gare de Lyon"
|
51
51
|
|
52
52
|
## Installation
|
53
53
|
|
54
54
|
gem install gares
|
55
55
|
|
56
|
-
Or
|
56
|
+
Or if you want to use it in a project add this to your `Gemfile`:
|
57
57
|
|
58
|
-
gem gares
|
58
|
+
gem "gares"
|
59
59
|
|
60
60
|
## Running Tests
|
61
61
|
|
62
|
-
As this gem uses content from gare-en-mouvement.com, the test suite uses a set of
|
63
|
-
pre-defined
|
64
|
-
copies of gares-en-mouvement
|
62
|
+
As this gem uses external content from gare-en-mouvement.com and sncf.com, the test suite uses a set of
|
63
|
+
pre-defined fixture files in `spec/fixtures`. These fixtures are
|
64
|
+
copies of gares-en-mouvement.com and sncf.com pages used in tests.
|
65
65
|
|
66
66
|
Run bundle install to install all dependencies, including fakeweb, which
|
67
|
-
will serve the fixture files instead of doing actual requests to gares-en-mouvement.com.
|
67
|
+
will serve the fixture files instead of doing actual requests to gares-en-mouvement.com or sncf.com.
|
68
68
|
|
69
69
|
$ bundle install
|
70
70
|
|
71
71
|
Next, simple run `rake` to run the entire test suite.
|
72
72
|
|
73
|
-
### Running against
|
73
|
+
### Running against real data
|
74
74
|
|
75
|
-
It's possible to run the test suite directly against gares-en-mouvement.com. This has
|
75
|
+
It's possible to run the test suite directly against gares-en-mouvement.com or sncf.com. This has
|
76
76
|
two disadvantages:
|
77
77
|
|
78
78
|
1. Tests will be slow
|
@@ -80,7 +80,7 @@ two disadvantages:
|
|
80
80
|
|
81
81
|
$ LIVE_TEST=true rake
|
82
82
|
|
83
|
-
If you want to run against actual
|
83
|
+
If you want to run against actual data, it's better to just update
|
84
84
|
the fixture files once with up-to-date content:
|
85
85
|
|
86
86
|
$ rake fixtures:refresh
|
@@ -92,12 +92,12 @@ When you run the test suite now, it will use the updated fixture files.
|
|
92
92
|
Neither I, nor any developer who contributed to this project, accept any kind of
|
93
93
|
liability for your use of this library.
|
94
94
|
|
95
|
-
gares-en-mouvement does not permit use of its data by third parties without their consent.
|
95
|
+
gares-en-mouvement.com and sncf.com certainly does not permit use of its data by third parties without their consent.
|
96
96
|
|
97
97
|
Using this library for anything other than limited personal use may result
|
98
|
-
in an IP ban to the gares-en-mouvement website.
|
98
|
+
in an IP ban to the gares-en-mouvement.com or sncf.com website.
|
99
99
|
|
100
|
-
_This gem is not endorsed or affiliated with gares-en-mouvement.com,
|
100
|
+
_This gem is not endorsed or affiliated with gares-en-mouvement.com, nor SNCF, Inc._
|
101
101
|
|
102
102
|
## License
|
103
103
|
|
data/lib/gares/base.rb
CHANGED
@@ -6,13 +6,13 @@ module Gares
|
|
6
6
|
GPS_COORD = 'Coordonnées GPS : '
|
7
7
|
NAME = 'En direct de '
|
8
8
|
|
9
|
-
# Initialize a new
|
9
|
+
# Initialize a new Station object with it's gare-en-mouvemnt id (as a String)
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# station = Gares::Station.new("frabt")
|
12
12
|
#
|
13
|
-
# Gares::
|
14
|
-
# will be performed when a new object is created.
|
15
|
-
# accessor that needs the remote data
|
13
|
+
# Gares::Station objects are lazy loaded, meaning that no HTTP request
|
14
|
+
# will be performed when a new object is created. An HTTP request is made (once)
|
15
|
+
# Only when you use an accessor that needs the remote data.
|
16
16
|
#
|
17
17
|
def initialize(slug, name = nil)
|
18
18
|
@slug = slug
|
@@ -76,7 +76,7 @@ module Gares
|
|
76
76
|
|
77
77
|
# Returns a new Nokogiri document for parsing.
|
78
78
|
def document
|
79
|
-
@document ||= Nokogiri::HTML(Gares::
|
79
|
+
@document ||= Nokogiri::HTML(Gares::Station.find_by_slug(@slug))
|
80
80
|
end
|
81
81
|
|
82
82
|
# Use HTTParty to fetch the raw HTML for this gare.
|
@@ -86,7 +86,7 @@ module Gares
|
|
86
86
|
|
87
87
|
# Convenience method for search
|
88
88
|
def self.search(query)
|
89
|
-
Gares::Search.new(query).
|
89
|
+
Gares::Search.new(query).stations
|
90
90
|
end
|
91
|
-
end #
|
91
|
+
end # Base
|
92
92
|
end # Gares
|
data/lib/gares/sales.rb
CHANGED
data/lib/gares/search.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
module Gares
|
2
|
-
# Search Gares-en-mouvement for a
|
3
|
-
class Search <
|
2
|
+
# Search Gares-en-mouvement for a station name
|
3
|
+
class Search < StationList
|
4
4
|
attr_reader :query
|
5
5
|
|
6
|
+
# This is a file containing minimal information (name and slug) of all stations of gares-en-mouvement.com
|
6
7
|
GARES_LIST_URL = "https://www.kimonolabs.com/api/7jys32dy?apikey=lsOO4tNm78cH9JxqWg9gAk9l4nYaou9j&kimmodify=1"
|
7
8
|
|
8
|
-
# Initialize a new
|
9
|
+
# Initialize a new Station search with the specified query
|
9
10
|
#
|
10
11
|
# search = Gares::Search.new("Aix")
|
11
12
|
#
|
12
|
-
# Gares::Search is lazy
|
13
|
-
# attribute, no query is made
|
13
|
+
# Gares::Search is lazy loaded, meaning that unless you access the +stations+
|
14
|
+
# attribute, no remomte query is made.
|
14
15
|
#
|
15
16
|
def initialize(query)
|
16
17
|
@query = query
|
17
18
|
end
|
18
19
|
|
19
|
-
# Returns an array of Gares::
|
20
|
+
# Returns an array of Gares::Station objects in order to easily search result yielded.
|
20
21
|
# If the +query+ was an exact match, a single element array will be returned.
|
21
|
-
def
|
22
|
-
@
|
22
|
+
def stations
|
23
|
+
@stations ||= (exact_match? ? parse_station : parse_stations)
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -29,16 +30,18 @@ module Gares
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def result
|
32
|
-
@result ||= document.results.collection1.map(&:station).select
|
33
|
+
@result ||= document.results.collection1.map(&:station).select do |station|
|
34
|
+
station.name.to_ascii =~ /#{@query.split(" ").join(".*")}/i
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
def self.query
|
36
39
|
open(GARES_LIST_URL)
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
|
41
|
-
[Gares::
|
42
|
+
def parse_station
|
43
|
+
station = result.first
|
44
|
+
[Gares::Station.new(station.slug, station.name)]
|
42
45
|
end
|
43
46
|
|
44
47
|
def exact_match?
|
data/lib/gares/services.rb
CHANGED
data/lib/gares/version.rb
CHANGED
data/lib/gares.rb
CHANGED
data/spec/gares/gare_spec.rb
CHANGED
@@ -6,14 +6,13 @@ require 'spec_helper'
|
|
6
6
|
#
|
7
7
|
# http://www.gares-en-mouvement.com/fr/frlpd/votre-gare/
|
8
8
|
#
|
9
|
-
|
10
|
-
describe Gares::Gare do
|
9
|
+
describe Gares::Station do
|
11
10
|
|
12
11
|
describe 'valid gare' do
|
13
12
|
|
14
13
|
before(:each) do
|
15
14
|
# Get gare de Lyon Part-Dieu
|
16
|
-
@gare = Gares::
|
15
|
+
@gare = Gares::Station.new('frlpd')
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'should find the name' do
|
@@ -53,7 +52,7 @@ describe Gares::Gare do
|
|
53
52
|
context 'a gare without wifi nor defibrillator' do
|
54
53
|
before(:each) do
|
55
54
|
# Get gare de Agde
|
56
|
-
@gare = Gares::
|
55
|
+
@gare = Gares::Station.new('frxag')
|
57
56
|
end
|
58
57
|
|
59
58
|
it { expect(@gare.wifi?).to be(false) }
|
@@ -63,7 +62,7 @@ describe Gares::Gare do
|
|
63
62
|
context 'a gare with no sales services' do
|
64
63
|
before(:each) do
|
65
64
|
# Get gare de Agde
|
66
|
-
@gare = Gares::
|
65
|
+
@gare = Gares::Station.new('frxag')
|
67
66
|
end
|
68
67
|
|
69
68
|
it { expect(@gare.has_borne?).to be(false) }
|
@@ -73,7 +72,7 @@ describe Gares::Gare do
|
|
73
72
|
describe 'with name that has utf-8 characters' do
|
74
73
|
# Belleville sur Sâone
|
75
74
|
before(:each) do
|
76
|
-
@gare = Gares::
|
75
|
+
@gare = Gares::Station.search('Saone').first
|
77
76
|
end
|
78
77
|
|
79
78
|
it 'should give the proper name' do
|
data/spec/gares/sales_spec.rb
CHANGED
data/spec/gares/search_spec.rb
CHANGED
@@ -11,32 +11,45 @@ describe Gares::Search do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should find 5 results' do
|
14
|
-
expect(@search.
|
14
|
+
expect(@search.stations.size).to eql(7)
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'should return Gares::
|
18
|
-
expect(@search.
|
17
|
+
it 'should return Gares::Station objects only' do
|
18
|
+
expect(@search.stations).to all(be_an(Gares::Station))
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should not return gares with no name' do
|
22
|
-
@search.
|
22
|
+
@search.stations.each { |gare| expect(gare.name).to_not be_blank }
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should return only the name of the result' do
|
26
|
-
expect(@search.
|
26
|
+
expect(@search.stations.first.name).to eql('Aix en Provence')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'with an exact match' do
|
31
31
|
it 'should not raise an exception' do
|
32
32
|
expect do
|
33
|
-
@search = Gares::Search.new('Paris Austerlitz').
|
33
|
+
@search = Gares::Search.new('Paris Austerlitz').stations
|
34
34
|
end.not_to raise_error
|
35
35
|
end
|
36
36
|
|
37
|
-
it 'should return the
|
37
|
+
it 'should return the gare slug correctly' do
|
38
38
|
@search = Gares::Search.new('Paris Austerlitz')
|
39
|
-
expect(@search.
|
39
|
+
expect(@search.stations.first.slug).to eql('frpaz')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a fuzzy match' do
|
44
|
+
it 'should not raise an exception' do
|
45
|
+
expect do
|
46
|
+
@search = Gares::Search.new('CULMONT CHALINDREY').stations
|
47
|
+
end.not_to raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return the gare slug correctly' do
|
51
|
+
@search = Gares::Search.new('CULMONT CHALINDREY')
|
52
|
+
expect(@search.stations.first.slug).to eql('frccy')
|
40
53
|
end
|
41
54
|
end
|
42
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Bonaud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -177,17 +177,18 @@ files:
|
|
177
177
|
- ".rubocop_todo.yml"
|
178
178
|
- ".travis.yml"
|
179
179
|
- Gemfile
|
180
|
+
- Guardfile
|
180
181
|
- MIT-LICENSE
|
181
182
|
- README.md
|
182
183
|
- Rakefile
|
183
184
|
- gares.gemspec
|
184
185
|
- lib/gares.rb
|
185
186
|
- lib/gares/base.rb
|
186
|
-
- lib/gares/gare.rb
|
187
|
-
- lib/gares/gare_list.rb
|
188
187
|
- lib/gares/sales.rb
|
189
188
|
- lib/gares/search.rb
|
190
189
|
- lib/gares/services.rb
|
190
|
+
- lib/gares/station.rb
|
191
|
+
- lib/gares/station_list.rb
|
191
192
|
- lib/gares/string_extensions.rb
|
192
193
|
- lib/gares/version.rb
|
193
194
|
- spec/fixtures/frabt
|
data/lib/gares/gare.rb
DELETED