idbus_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +19 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/MIT-LICENSE +21 -0
- data/README.md +102 -0
- data/Rakefile +25 -0
- data/idbus_api.gemspec +35 -0
- data/lib/idbus_api.rb +49 -0
- data/lib/idbus_api/base.rb +0 -0
- data/lib/idbus_api/client.rb +29 -0
- data/lib/idbus_api/default.rb +65 -0
- data/lib/idbus_api/endpoint/fares.rb +31 -0
- data/lib/idbus_api/endpoint/stops.rb +18 -0
- data/lib/idbus_api/errors.rb +3 -0
- data/lib/idbus_api/stops.rb +4 -0
- data/lib/idbus_api/version.rb +3 -0
- data/spec/cassettes/IdbusApi_Client/_get/handles_query_params.json +1 -0
- data/spec/cassettes/IdbusApi_Client/_last_response/caches_the_last_agent_response.json +1 -0
- data/spec/cassettes/IdbusApi_Endpoint_Fares/Not_authenticated/_fares/raises_an_unauthorized_execption.json +1 -0
- data/spec/cassettes/IdbusApi_Endpoint_Fares/authenticated/_fares_for_a_specific_route/returns_a_list_of_fares.json +1 -0
- data/spec/cassettes/IdbusApi_Endpoint_Stops/Not_authenticated/_stops/raises_an_unauthorized_execption.json +1 -0
- data/spec/cassettes/IdbusApi_Endpoint_Stops/authenticated/_stops/returns_a_list_of_stops.json +1 -0
- data/spec/cassettes/root.json +1 -0
- data/spec/idbus_api/client_spec.rb +214 -0
- data/spec/idbus_api/endpoint/fares_spec.rb +43 -0
- data/spec/idbus_api/endpoint/stops_spec.rb +35 -0
- data/spec/idbus_api_spec.rb +40 -0
- data/spec/spec_helper.rb +68 -0
- data/tasks/rspec.rake +21 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8d04adf19e8cd56f2bdc02564303cada23a6364
|
4
|
+
data.tar.gz: 5ad55361ad7fef7920202e4d1547d8cc521f3836
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ced582baf89e79f8dfea0c21450f689335eb0b9570ee34820bea2bae79fa73ea8d0515f69b10b1a361085c254224688f9dd8363d81d22ff5a60d7e1dbd492d4a
|
7
|
+
data.tar.gz: 50731a514b3636e56f326f47c47fa16268abeb130c875dee86d6d6d1619f10b4d4109b91d9c8b0915fe1eb12715257326b77f8f7d6af0cf87bb8ec8c68cebdab
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-06-01 12:18:38 +0200 using RuboCop version 0.22.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: CountComments.
|
10
|
+
ClassLength:
|
11
|
+
Max: 142
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
CyclomaticComplexity:
|
15
|
+
Max: 8
|
16
|
+
|
17
|
+
# Offense count: 5
|
18
|
+
Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# Offense count: 53
|
22
|
+
LineLength:
|
23
|
+
Max: 704
|
24
|
+
|
25
|
+
# Offense count: 2
|
26
|
+
# Configuration parameters: CountComments.
|
27
|
+
MethodLength:
|
28
|
+
Max: 19
|
29
|
+
|
30
|
+
# Offense count: 2
|
31
|
+
MultilineBlockChain:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
# Offense count: 5
|
35
|
+
RescueModifier:
|
36
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2015 Paul Bonaud
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# iDBUS API wrapper
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/paulRbr/idbus_api.svg)](https://travis-ci.org/paulRbr/idbus_api) [![Coverage Status](https://coveralls.io/repos/paulRbr/idbus_api/badge.svg)](https://coveralls.io/r/paulRbr/idbus_api)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This gem wraps the new iDBUS API v1 available at https://api.idbus.com
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
You can use this gem in your project by specifying it in your `Gemfile`:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem "idbus_api"
|
15
|
+
```
|
16
|
+
|
17
|
+
or simply install it via the CLI:
|
18
|
+
|
19
|
+
```
|
20
|
+
gem install idbus_api
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
All the API methods are available as module methods or as client instance methods.
|
26
|
+
|
27
|
+
### Configure the client
|
28
|
+
|
29
|
+
```
|
30
|
+
IdbusApi.configure do |c|
|
31
|
+
c.access_token = "my_secret_token"
|
32
|
+
c.connection_options = {
|
33
|
+
ssl: { verify: false }
|
34
|
+
} # Hash of Faraday ConnectionOptions. See http://www.rubydoc.info/github/lostisland/faraday/Faraday/Connection#initialize-instance_method
|
35
|
+
c.user_agent = "My App"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fetch all stops
|
39
|
+
IdbusApi.stops
|
40
|
+
```
|
41
|
+
|
42
|
+
or
|
43
|
+
|
44
|
+
```
|
45
|
+
client = IdbusApi::Client.new(
|
46
|
+
access_token: "my_secret_token",
|
47
|
+
user_agent: "My App"
|
48
|
+
)
|
49
|
+
|
50
|
+
# Fetch fares
|
51
|
+
client.fares(date: "2015-07-07")
|
52
|
+
```
|
53
|
+
|
54
|
+
### Fetching resources
|
55
|
+
|
56
|
+
All resources are `Resource` objects. This object provides both dot notation and `[]` access for the api response fields.
|
57
|
+
|
58
|
+
#### Stops
|
59
|
+
|
60
|
+
```
|
61
|
+
# Fetch stops from /v1/stops endpoint
|
62
|
+
stops = IdbusApi.stops
|
63
|
+
|
64
|
+
stops.first.short_name == "Paris CDG (aéroport)"
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Fares
|
68
|
+
|
69
|
+
Fares can be fetched with optional parameters. Full list of available parameters is available on the api documentation https://api.idbus.com/.
|
70
|
+
|
71
|
+
```
|
72
|
+
# Fetch fares for specific origin station and specific date
|
73
|
+
fares = IdbusApi.fares(origin_id: 3, date: "2015-08-15")
|
74
|
+
|
75
|
+
fares.first.price_cents
|
76
|
+
=> 1500
|
77
|
+
|
78
|
+
fares.first.to_hash
|
79
|
+
=> {
|
80
|
+
:id => 13864,
|
81
|
+
:updated_at => 2015-06-11 07:55:22 UTC,
|
82
|
+
:origin_id => 3,
|
83
|
+
:destination_id => 13,
|
84
|
+
:departure => "2015-08-15T08:40:00.000+02:00",
|
85
|
+
:arrival => "2015-08-15T12:55:00.000+02:00",
|
86
|
+
:price_cents => 1500,
|
87
|
+
:price_currency => "EUR",
|
88
|
+
:book_path => "/v1/fares/13864/book",
|
89
|
+
:available => true,
|
90
|
+
:legs => [{:origin_id=>3, :destination_id=>13, :departure=>"2015-08-15T08:40:00.000+02:00", :arrival=>"2015-08-15T12:55:00.000+02:00", :bus_number=>"3912"}]
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
## Disclaimer
|
95
|
+
|
96
|
+
Neither I, nor any developer who contributed to this project, accept any kind of liability for your use of this library.
|
97
|
+
|
98
|
+
_This gem is not endorsed or affiliated with any company, api.idbus.com, nor iDBUS, nor SNCF._
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
Code licensed under [MIT-LICENSE](https://github.com/paulrbr/idbus_api/blob/master/MIT-LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task default: :spec
|
8
|
+
|
9
|
+
require 'idbus_api/version'
|
10
|
+
require 'rdoc/task'
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.main = 'README.rdoc'
|
13
|
+
rdoc.rdoc_dir = 'rdoc'
|
14
|
+
rdoc.title = "IdbusApi #{IdbusApi::VERSION} documentation"
|
15
|
+
rdoc.rdoc_files.include('README*')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
rdoc.options << '--webcvs=http://github.com/paulrbr/idbus_api/tree/master/'
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'gokdok'
|
21
|
+
Gokdok::Dokker.new do |gd|
|
22
|
+
gd.repo_url = 'git@github.com:paulrbr/idbus_api.git'
|
23
|
+
gd.doc_home = 'rdoc'
|
24
|
+
gd.remote_path = '.'
|
25
|
+
end
|
data/idbus_api.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'idbus_api/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'idbus_api'
|
6
|
+
s.licenses = ['MIT']
|
7
|
+
s.version = IdbusApi::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Paul Bonaud']
|
10
|
+
s.email = ['paul+gh@bonaud.fr']
|
11
|
+
s.homepage = 'http://github.com/paulrbr/idbus_api'
|
12
|
+
s.summary = %q(Easily access the API of iDBUS.)
|
13
|
+
s.description = %q(Easily use Ruby or the command line to find information from the iDBUS API.)
|
14
|
+
|
15
|
+
s.rubyforge_project = 'idbus_api'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_dependency 'api'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.add_development_dependency 'rspec'
|
26
|
+
s.add_development_dependency 'webmock'
|
27
|
+
s.add_development_dependency 'vcr'
|
28
|
+
s.add_development_dependency 'multi_json'
|
29
|
+
s.add_development_dependency 'gokdok'
|
30
|
+
s.add_development_dependency 'guard'
|
31
|
+
s.add_development_dependency 'guard-rspec'
|
32
|
+
s.add_development_dependency 'rdoc'
|
33
|
+
s.add_development_dependency 'fakeweb'
|
34
|
+
s.add_development_dependency 'coveralls'
|
35
|
+
end
|
data/lib/idbus_api.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require 'api'
|
8
|
+
|
9
|
+
require 'idbus_api/default'
|
10
|
+
require 'idbus_api/client'
|
11
|
+
#require 'idbus_api/base'
|
12
|
+
#require 'idbus_api/stop'
|
13
|
+
#require 'idbus_api/fare'
|
14
|
+
require 'idbus_api/version'
|
15
|
+
|
16
|
+
|
17
|
+
# Ruby toolkit for the iDBUS API
|
18
|
+
module IdbusApi
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
include Api::Configurable
|
23
|
+
|
24
|
+
# API client based on configured options {Configurable}
|
25
|
+
#
|
26
|
+
# @return [IdbusApi::Client] API wrapper
|
27
|
+
def client
|
28
|
+
return @client if defined?(@client) && @client.same_options?(options)
|
29
|
+
@client = IdbusApi::Client.new(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def respond_to_missing?(method_name, include_private = false)
|
35
|
+
client.respond_to?(method_name, include_private)
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(method_name, *args, &block)
|
39
|
+
if client.respond_to?(method_name)
|
40
|
+
return client.send(method_name, *args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
IdbusApi.reset!
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'api/authentication'
|
2
|
+
require 'api/configurable'
|
3
|
+
require 'api/connection'
|
4
|
+
|
5
|
+
require 'idbus_api/errors'
|
6
|
+
require 'idbus_api/endpoint/stops'
|
7
|
+
require 'idbus_api/endpoint/fares'
|
8
|
+
|
9
|
+
module IdbusApi
|
10
|
+
|
11
|
+
# Client for the iDBUS API
|
12
|
+
#
|
13
|
+
# @see https://api.idbus.com
|
14
|
+
class Client < Api::Client
|
15
|
+
|
16
|
+
# Include API gem modules
|
17
|
+
include Api::Authentication
|
18
|
+
include Api::Configurable
|
19
|
+
include Api::Connection
|
20
|
+
|
21
|
+
# Describe API endpoints
|
22
|
+
include IdbusApi::Endpoint::Stops
|
23
|
+
include IdbusApi::Endpoint::Fares
|
24
|
+
|
25
|
+
# Header keys that can be passed in options hash to {#get}
|
26
|
+
CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "api/default_options"
|
2
|
+
|
3
|
+
module IdbusApi
|
4
|
+
|
5
|
+
# Default configuration options for {Client}
|
6
|
+
module Default
|
7
|
+
|
8
|
+
# Default API endpoint
|
9
|
+
API_ENDPOINT = "https://api.idbus.com".freeze
|
10
|
+
|
11
|
+
# Default API version
|
12
|
+
API_VERSION = "v1".freeze
|
13
|
+
|
14
|
+
# Default User Agent header string
|
15
|
+
USER_AGENT = "Idbus API Ruby Gem #{IdbusApi::VERSION}".freeze
|
16
|
+
|
17
|
+
class << self
|
18
|
+
|
19
|
+
include Api::DefaultOptions
|
20
|
+
|
21
|
+
# Default access token from ENV
|
22
|
+
# @return [String]
|
23
|
+
def access_token
|
24
|
+
ENV['IDBUS_ACCESS_TOKEN']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Default access token prefix
|
28
|
+
# @return [String]
|
29
|
+
def access_token_prefix
|
30
|
+
"Token"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Default API endpoint from ENV or {API_ENDPOINT}
|
34
|
+
# @return [String]
|
35
|
+
def api_endpoint
|
36
|
+
ENV['IDBUS_API_ENDPOINT'] || API_ENDPOINT
|
37
|
+
end
|
38
|
+
|
39
|
+
# Default API version from ENV or {API_VERSION}
|
40
|
+
# @return [String]
|
41
|
+
def api_version
|
42
|
+
ENV['IDBUS_API_VERSION'] || API_VERSION
|
43
|
+
end
|
44
|
+
|
45
|
+
# Default options for Faraday::Connection
|
46
|
+
# @return [Hash]
|
47
|
+
def connection_options
|
48
|
+
{
|
49
|
+
:headers => {
|
50
|
+
:user_agent => user_agent
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Default User-Agent header string from ENV or {USER_AGENT}
|
56
|
+
# @return [String]
|
57
|
+
# Default User-Agent header string from ENV or {USER_AGENT}
|
58
|
+
# @return [String]
|
59
|
+
def user_agent
|
60
|
+
ENV['IDBUS_USER_AGENT'] || USER_AGENT
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module IdbusApi
|
2
|
+
|
3
|
+
module Endpoint
|
4
|
+
|
5
|
+
# Methods of the Fares API
|
6
|
+
module Fares
|
7
|
+
|
8
|
+
# Make a call to the GET /fares endpoint
|
9
|
+
#
|
10
|
+
# @param parameters [Hash] optional parameters to pass to the request
|
11
|
+
# @return [Array<Sawyer::Resource>]
|
12
|
+
def fares(parameters = {})
|
13
|
+
allowed_parameters = %i(
|
14
|
+
origin_id
|
15
|
+
destination_id
|
16
|
+
date
|
17
|
+
start_date
|
18
|
+
end_date
|
19
|
+
currencies
|
20
|
+
updated_after
|
21
|
+
)
|
22
|
+
|
23
|
+
wrong_parameters = parameters.keys - allowed_parameters
|
24
|
+
fail IdbusApi::WrongParameters, wrong_parameters unless wrong_parameters.empty?
|
25
|
+
|
26
|
+
paginate("/fares", parameters).fares
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|