transprt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/example.rb +5 -0
- data/lib/transprt.rb +62 -0
- data/transprt.gemspec +21 -0
- metadata +84 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Ghn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/example.rb
ADDED
data/lib/transprt.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class Transprt
|
6
|
+
|
7
|
+
@domain = 'http://transport.opendata.ch'
|
8
|
+
@version = 'v1'
|
9
|
+
|
10
|
+
#
|
11
|
+
# => find locations
|
12
|
+
#
|
13
|
+
def self.locations(parameters)
|
14
|
+
|
15
|
+
allowed_parameters = ['query', 'x', 'y', 'type']
|
16
|
+
|
17
|
+
query = self.create_query(parameters, allowed_parameters)
|
18
|
+
|
19
|
+
locations = JSON.parse(RestClient.get self.create_url('locations') + query)
|
20
|
+
|
21
|
+
locations['stations']
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# => find connections
|
26
|
+
#
|
27
|
+
def self.connections(parameters)
|
28
|
+
allowed_parameters = ['from', 'to', 'via', 'date', 'time', 'isArrivalTime', 'transportations', 'limit', 'page',
|
29
|
+
'direct', 'sleeper', 'couchette', 'bike']
|
30
|
+
|
31
|
+
query = self.create_query(parameters, allowed_parameters)
|
32
|
+
|
33
|
+
locations = JSON.parse(RestClient.get self.create_url('connections') + query)
|
34
|
+
|
35
|
+
locations['connections']
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# => find station boards
|
40
|
+
#
|
41
|
+
def self.stationboard(parameters)
|
42
|
+
allowed_parameters = ['station', 'id', 'limit', 'transportations', 'datetime']
|
43
|
+
|
44
|
+
query = self.create_query(parameters, allowed_parameters)
|
45
|
+
|
46
|
+
locations = JSON.parse(RestClient.get self.create_url('stationboard') + query)
|
47
|
+
|
48
|
+
locations['stationboard']
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.create_url(base)
|
54
|
+
[@domain, @version, base].join('/') + '?'
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.create_query(parameters, allowed_parameters)
|
58
|
+
query = parameters.map{|k,v|
|
59
|
+
"#{k}=#{v}" if allowed_parameters.include? k.to_s
|
60
|
+
}.join('&')
|
61
|
+
end
|
62
|
+
end
|
data/transprt.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "transprt"
|
6
|
+
gem.version = '0.1.0'
|
7
|
+
gem.authors = ["ghn"]
|
8
|
+
gem.email = ["ghugon@gmail.com"]
|
9
|
+
gem.description = %q{Use the public transport Swiss API (open data).}
|
10
|
+
gem.summary = "Swiss public transport."
|
11
|
+
gem.homepage = 'https://github.com/ghn/transprt'
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rest_client'
|
20
|
+
gem.add_development_dependency 'json'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transprt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ghn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest_client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Use the public transport Swiss API (open data).
|
47
|
+
email:
|
48
|
+
- ghugon@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- example.rb
|
57
|
+
- lib/transprt.rb
|
58
|
+
- transprt.gemspec
|
59
|
+
homepage: https://github.com/ghn/transprt
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.23
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Swiss public transport.
|
84
|
+
test_files: []
|