sncf 0.2.3 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +68 -6
- data/lib/sncf/api_client.rb +27 -0
- data/lib/sncf/api_response.rb +1 -1
- data/lib/sncf/parsers/stations.rb +23 -21
- data/lib/sncf/version.rb +1 -1
- data/sncf.gemspec +3 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294f2a61e3f1f7d2200b9f6e79ebadb1876bb9c2
|
4
|
+
data.tar.gz: e04537454ac8128eb48211a2ee00f37ff9e6ace6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b88782092964e5fce6ebb443c12c30b2f64dfeea34b8c52ec9bba5d3da68a681ccca2cb6d75755cbdc0f4792224be44adf4abb60f220f8b9f3b39a3fd388a8
|
7
|
+
data.tar.gz: fec8027ab3d967f30de57bdbd5ca543ae807af1fe6fd0eea499282d4fdcb57733e9415db493fa3c9d3f2a6dbfac7d4012c5fdbef776f8a95c51139421d8079e5
|
data/README.md
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
# SNCF Open Data API Ruby wrapper
|
2
2
|
|
3
|
-
# This gem in currently in beta, it may contains bugs, do not use in production.
|
4
|
-
|
5
|
-
# 1.0.0 release is due to Fri, 03 Jul 2015
|
6
|
-
|
7
3
|
[](http://badge.fury.io/rb/sncf)
|
8
4
|
|
9
5
|
Ruby gem to use easily the SNCF Open Data API with Ruby.
|
10
6
|
|
7
|
+
Current SNCF Open Data API version: `1.0`
|
8
|
+
|
11
9
|
API Documentation is available [here](https://data.sncf.com/api)
|
12
10
|
|
13
11
|
You don't already have an API KEY ? [Register here!](https://data.sncf.com/api/register)
|
@@ -30,6 +28,70 @@ Or install it yourself as:
|
|
30
28
|
|
31
29
|
## Usage
|
32
30
|
|
31
|
+
## Fetch train stations
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'sncf'
|
35
|
+
|
36
|
+
# Create your Sncf::ApiClient with your API_KEY
|
37
|
+
client = Sncf::ApiClient.new('MY_API_KEY')
|
38
|
+
|
39
|
+
client.api_key
|
40
|
+
=> 'MY_API_KEY'
|
41
|
+
|
42
|
+
# Will returns a parsed model
|
43
|
+
response = client.fetch_stations('Lille Europe')
|
44
|
+
=> [#<Sncf::Models::Station:0x007fee0cf051c0
|
45
|
+
@administrative_regions=
|
46
|
+
[#<Sncf::Models::AdministrativeRegion:0x007fee0cf05490
|
47
|
+
@coord={"lat"=>"50.630508", "lon"=>"3.070641"},
|
48
|
+
@id="admin:58404extern",
|
49
|
+
@insee="59350",
|
50
|
+
@label="Lille (59000-59800)",
|
51
|
+
@level=8,
|
52
|
+
@name="Lille",
|
53
|
+
@zip_code="59000;59800">],
|
54
|
+
@coord={"lat"=>"50.638861", "lon"=>"3.075774"},
|
55
|
+
@id="stop_area:OCE:SA:87223263",
|
56
|
+
@label="gare de Lille Europe (Lille)",
|
57
|
+
@name="gare de Lille Europe",
|
58
|
+
@quality=80,
|
59
|
+
@timezone="Europe/Paris">]
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
## Fetch journeys by stations name
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require 'sncf'
|
67
|
+
|
68
|
+
# Create your Sncf::ApiClient with your API_KEY
|
69
|
+
client = Sncf::ApiClient.new('MY_API_KEY')
|
70
|
+
|
71
|
+
# Without options
|
72
|
+
response_without_options = client.fetch_journeys_by_stations('Paris Nord', 'Lille Europe', Time.now)
|
73
|
+
=> #<Sncf::ApiResponse:0x007f8b0592abe8
|
74
|
+
@body = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
|
75
|
+
@content = { ... }, # Here is the api response
|
76
|
+
@pagination = nil,
|
77
|
+
@response = #<HTTP::Response/1.1 200 OK ...>,
|
78
|
+
@start_page = 0>
|
79
|
+
|
80
|
+
# With options
|
81
|
+
response_with_options = client.fetch_journeys_by_stations('Paris Nord', 'Lille Europe', Time.now, { datetime_represents: 'arrival' })
|
82
|
+
=> #<Sncf::ApiResponse:0x007f8b0592abe8
|
83
|
+
@body = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
|
84
|
+
@content = { ... }, # Here is the api response
|
85
|
+
@pagination = nil,
|
86
|
+
@response = #<HTTP::Response/1.1 200 OK ...>,
|
87
|
+
@start_page = 0>
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
Available options are available here: [https://data.sncf.com/api/documentation#title.1.6.4.1](https://data.sncf.com/api/documentation#title.1.6.4.1)
|
92
|
+
|
93
|
+
## Custom API fetch
|
94
|
+
|
33
95
|
```ruby
|
34
96
|
require 'sncf'
|
35
97
|
|
@@ -39,7 +101,7 @@ client = Sncf::ApiClient.new('MY_API_KEY')
|
|
39
101
|
client.api_key
|
40
102
|
=> 'MY_API_KEY'
|
41
103
|
|
42
|
-
response =
|
104
|
+
response = client.fetch('coverage')
|
43
105
|
=> #<Sncf::ApiResponse:0x007f8b0592abe8
|
44
106
|
@body = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
|
45
107
|
@content = { ... }, # Here is the api response
|
@@ -53,7 +115,7 @@ Available `fetch` parameters and API actions are here [https://data.sncf.com/api
|
|
53
115
|
|
54
116
|
## Contributing
|
55
117
|
|
56
|
-
1. Fork it ( https://github.com/
|
118
|
+
1. Fork it ( https://github.com/Libertrip/sncf/fork )
|
57
119
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
120
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
121
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/sncf/api_client.rb
CHANGED
@@ -52,6 +52,33 @@ module Sncf
|
|
52
52
|
Sncf::Parsers::Stations.new(stations_response).get_stations_list
|
53
53
|
end
|
54
54
|
|
55
|
+
def fetch_journeys_by_stations(from, to, time, options = {})
|
56
|
+
raise ArgumentError, "The `from` argument should be a string, example: 'Paris Nord'." if from.to_s == ''
|
57
|
+
raise ArgumentError, "The `to` argument should be a string, example: 'Paris Nord'." if to.to_s == ''
|
58
|
+
raise ArgumentError, "The `time` argument should be Time or DateTime." unless time.is_a?(Time) || time.is_a?(DateTime)
|
59
|
+
|
60
|
+
from_station = fetch_stations(from).first
|
61
|
+
to_station = fetch_stations(to).first
|
62
|
+
|
63
|
+
case
|
64
|
+
when from_station.nil?
|
65
|
+
raise ArgumentError, "The '#{from}' station doesn't exist."
|
66
|
+
when to_station.nil?
|
67
|
+
raise ArgumentError, "The '#{to}' station doesn't exist."
|
68
|
+
else
|
69
|
+
fetch_journeys_by_station_ids from_station.id, to_station.id, time, options
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def fetch_journeys_by_station_ids(from_station_id, to_station_id, time, options)
|
74
|
+
fetch_options = {
|
75
|
+
from: from_station_id,
|
76
|
+
to: to_station_id,
|
77
|
+
datetime: time.to_datetime.strftime('%Y%m%dT%H%M%S')
|
78
|
+
}.merge(options)
|
79
|
+
fetch('coverage/sncf/journeys', fetch_options)
|
80
|
+
end
|
81
|
+
|
55
82
|
protected
|
56
83
|
|
57
84
|
def construct_formated_url(path, additional_params)
|
data/lib/sncf/api_response.rb
CHANGED
@@ -4,29 +4,31 @@ module Sncf
|
|
4
4
|
def get_stations_list
|
5
5
|
stations, administrative_regions = [], []
|
6
6
|
|
7
|
-
@api_response.content['places'].
|
8
|
-
|
9
|
-
place['
|
10
|
-
administrative_regions
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
unless @api_response.content['places'].nil?
|
8
|
+
@api_response.content['places'].each do |place|
|
9
|
+
if place['embedded_type'] == 'stop_area'
|
10
|
+
place['stop_area']['administrative_regions'].each do |administrative_region|
|
11
|
+
administrative_regions << create_model('AdministrativeRegion', {
|
12
|
+
id: administrative_region['id'],
|
13
|
+
insee: administrative_region['insee'],
|
14
|
+
level: administrative_region['level'],
|
15
|
+
coord: administrative_region['coord'],
|
16
|
+
name: administrative_region['name'],
|
17
|
+
label: administrative_region['label'],
|
18
|
+
zip_code: administrative_region['zip_code']
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
stations << create_model('Station', {
|
23
|
+
id: place['id'],
|
24
|
+
coord: place['stop_area']['coord'],
|
25
|
+
quality: place['quality'],
|
26
|
+
name: place['stop_area']['name'],
|
27
|
+
label: place['stop_area']['label'],
|
28
|
+
timezone: place['stop_area']['timezone'],
|
29
|
+
administrative_regions: administrative_regions
|
18
30
|
})
|
19
31
|
end
|
20
|
-
|
21
|
-
stations << create_model('Station', {
|
22
|
-
id: place['id'],
|
23
|
-
coord: place['stop_area']['coord'],
|
24
|
-
quality: place['quality'],
|
25
|
-
name: place['stop_area']['name'],
|
26
|
-
label: place['stop_area']['label'],
|
27
|
-
timezone: place['stop_area']['timezone'],
|
28
|
-
administrative_regions: administrative_regions
|
29
|
-
})
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
data/lib/sncf/version.rb
CHANGED
data/sncf.gemspec
CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Rémi Delhaye"]
|
10
10
|
spec.email = ["remi@libertrip.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{SNCF
|
13
|
-
spec.description = %q{SNCF
|
14
|
-
spec.homepage = "https://github.com/
|
12
|
+
spec.summary = %q{Open source ruby api client for SNCF Open Data API}
|
13
|
+
spec.description = %q{Open source ruby api client for SNCF Open Data API. Documentation available here: https://github.com/Libertrip/sncf }
|
14
|
+
spec.homepage = "https://github.com/Libertrip/sncf"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sncf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Delhaye
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -136,7 +136,8 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.1'
|
139
|
-
description: 'SNCF
|
139
|
+
description: 'Open source ruby api client for SNCF Open Data API. Documentation available
|
140
|
+
here: https://github.com/Libertrip/sncf '
|
140
141
|
email:
|
141
142
|
- remi@libertrip.com
|
142
143
|
executables: []
|
@@ -160,7 +161,7 @@ files:
|
|
160
161
|
- lib/sncf/parsers/stations.rb
|
161
162
|
- lib/sncf/version.rb
|
162
163
|
- sncf.gemspec
|
163
|
-
homepage: https://github.com/
|
164
|
+
homepage: https://github.com/Libertrip/sncf
|
164
165
|
licenses:
|
165
166
|
- MIT
|
166
167
|
metadata: {}
|
@@ -183,5 +184,5 @@ rubyforge_project:
|
|
183
184
|
rubygems_version: 2.4.6
|
184
185
|
signing_key:
|
185
186
|
specification_version: 4
|
186
|
-
summary: SNCF
|
187
|
+
summary: Open source ruby api client for SNCF Open Data API
|
187
188
|
test_files: []
|