Project

sncf

0.0
No commit activity in last 3 years
No release in over 3 years
Open source ruby api client for SNCF Open Data API. Documentation available here: https://github.com/Libertrip/sncf
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
~> 4.0
~> 0.10
~> 10.0
~> 3.3

Runtime

~> 0.8.12
~> 2.12
 Project Readme

SNCF Open Data API Ruby wrapper

Gem Version

Ruby gem to use easily the SNCF Open Data API with Ruby.

Current SNCF Open Data API version: 1.0

API Documentation is available here

You don't already have an API KEY ? Register here!

Installation

Add this line to your application's Gemfile:

gem 'sncf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sncf

Usage

Fetch train stations

require 'sncf'

# Create your Sncf::ApiClient with your API_KEY
client = Sncf::ApiClient.new('MY_API_KEY')

client.api_key
=> 'MY_API_KEY'

# Will returns a parsed model
response = client.fetch_stations('Lille Europe')
=> [#<Sncf::Models::Station:0x007fee0cf051c0
  @administrative_regions=
   [#<Sncf::Models::AdministrativeRegion:0x007fee0cf05490
     @coord={"lat"=>"50.630508", "lon"=>"3.070641"},
     @id="admin:58404extern",
     @insee="59350",
     @label="Lille (59000-59800)",
     @level=8,
     @name="Lille",
     @zip_code="59000;59800">],
  @coord={"lat"=>"50.638861", "lon"=>"3.075774"},
  @id="stop_area:OCE:SA:87223263",
  @label="gare de Lille Europe (Lille)",
  @name="gare de Lille Europe",
  @quality=80,
  @timezone="Europe/Paris">]

Fetch journeys by stations name

require 'sncf'

# Create your Sncf::ApiClient with your API_KEY
client = Sncf::ApiClient.new('MY_API_KEY')

# Without options
response_without_options = client.fetch_journeys_by_stations('Paris Nord', 'Lille Europe', Time.now)
=> #<Sncf::ApiResponse:0x007f8b0592abe8
  @body        = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
  @content     = { ... }, # Here is the api response
  @pagination  = nil,
  @response    = #<HTTP::Response/1.1 200 OK ...>,
  @start_page  = 0>

# With options
response_with_options = client.fetch_journeys_by_stations('Paris Nord', 'Lille Europe', Time.now, { datetime_represents: 'arrival' })
=> #<Sncf::ApiResponse:0x007f8b0592abe8
  @body        = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
  @content     = { ... }, # Here is the api response
  @pagination  = nil,
  @response    = #<HTTP::Response/1.1 200 OK ...>,
  @start_page  = 0>

Available options are available here: https://data.sncf.com/api/documentation#title.1.6.4.1

Custom API fetch

require 'sncf'

# Create your Sncf::ApiClient with your API_KEY
client = Sncf::ApiClient.new('MY_API_KEY')

client.api_key
=> 'MY_API_KEY'

response = client.fetch('coverage')
=> #<Sncf::ApiResponse:0x007f8b0592abe8
  @body        = #<HTTP::Response::Body:3fc582c9818c @streaming=true>,
  @content     = { ... }, # Here is the api response
  @pagination  = nil,
  @response    = #<HTTP::Response/1.1 200 OK ...>,
  @start_page  = 0>

Available fetch parameters and API actions are here https://data.sncf.com/api/documentation#title.1.2.3

Contributing

  1. Fork it ( https://github.com/Libertrip/sncf/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request