kvv-liveapi 0.0.1
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 +7 -0
- data/.gitignore +25 -0
- data/.ruby-version +1 -0
- data/Gemfile +35 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kvv-liveapi.gemspec +34 -0
- data/lib/kvv/liveapi.rb +72 -0
- data/lib/kvv/liveapi/version.rb +5 -0
- metadata +153 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fa8d1e2ba1e608f32e6eddc0a3bc47dc489ac8f1818a6071e5f217fdd5d37ab8
|
|
4
|
+
data.tar.gz: 61e669c130154bcb1aee0c7d96cb573b3c80261eba0a520627079b63794cd4ac
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 77169131ecf884d796b78953a760e60923ee49a4cc659fa303bdb691a0504fc780801c4899428564144bf8f8179f01f7035812eb2f278889674eea1cba561dbf
|
|
7
|
+
data.tar.gz: 15ce5b5371fc02412e9703756c04e67f437efb53173052bac8c18270bc8b11002a82ed3ab7d08d0255cb793520c42060ebfb5a01717437bfd307fa85c0823282
|
data/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Because this is a gem, ignore Gemfile.lock:
|
|
2
|
+
|
|
3
|
+
Gemfile.lock
|
|
4
|
+
|
|
5
|
+
# And because this is Ruby, ignore the following
|
|
6
|
+
# (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
|
|
7
|
+
|
|
8
|
+
*.gem
|
|
9
|
+
*.rbc
|
|
10
|
+
.bundle
|
|
11
|
+
.config
|
|
12
|
+
coverage
|
|
13
|
+
InstalledFiles
|
|
14
|
+
lib/bundler/man
|
|
15
|
+
pkg
|
|
16
|
+
rdoc
|
|
17
|
+
spec/reports
|
|
18
|
+
test/tmp
|
|
19
|
+
test/version_tmp
|
|
20
|
+
tmp
|
|
21
|
+
|
|
22
|
+
# YARD artifacts
|
|
23
|
+
.yardoc
|
|
24
|
+
_yardoc
|
|
25
|
+
doc/
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.5.0
|
data/Gemfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
git_source(:github) do |repo_name|
|
|
6
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
|
7
|
+
"https://github.com/#{repo_name}.git"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
group :development, :test do
|
|
11
|
+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
|
12
|
+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :development do
|
|
16
|
+
gem 'listen', '>= 3.0.5', '< 3.2'
|
|
17
|
+
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
|
18
|
+
gem 'spring'
|
|
19
|
+
gem 'spring-watcher-listen', '~> 2.0.0'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
group :test do
|
|
23
|
+
# gem 'minitest', '5.10.3'
|
|
24
|
+
# # gem 'minitest-rails'
|
|
25
|
+
# gem 'minitest-spec-context'
|
|
26
|
+
# gem 'minitest-matchers'
|
|
27
|
+
# gem 'minitest-reporters'
|
|
28
|
+
# gem 'webmock'
|
|
29
|
+
# gem 'vcr'
|
|
30
|
+
# gem "minitest-vcr"
|
|
31
|
+
# gem 'simplecov'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
|
35
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) Christian Buggle <christian@buggle.net>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all 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,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# KVV::Liveapi
|
|
2
|
+
|
|
3
|
+
KVV::Liveapi is a simple ruby gem to query stop data and timetables / departures as provided by the KVV Live Service (Karlsruhe Transport Agency).
|
|
4
|
+
|
|
5
|
+
The KVV services is unofficial and undocumented so I can make no claims of any kind for this adapter to work as intended now or at any time in the future.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'kvv-liveapi'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
And then execute:
|
|
17
|
+
|
|
18
|
+
$ bundle
|
|
19
|
+
|
|
20
|
+
Or install it yourself as:
|
|
21
|
+
|
|
22
|
+
$ gem install kvv-liveapi
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
The KVV::Liveapi provides these 5 methods to query KVV data.
|
|
27
|
+
|
|
28
|
+
* KVV::Liveapi.departures_bystop_name( name )
|
|
29
|
+
|
|
30
|
+
* KVV::Liveapi.departures_bystop( stop_id )
|
|
31
|
+
|
|
32
|
+
* KVV::Liveapi.departures_by_route( route: nil, stop_id: nil )
|
|
33
|
+
|
|
34
|
+
* KVV::Liveapi.stops_by_name name
|
|
35
|
+
|
|
36
|
+
* KVV::Liveapi.stops_by_latlon( lat: nil, lon: nil )
|
|
37
|
+
|
|
38
|
+
The method names are derived closely from the corresponding liveapi.kvv.de api endpoints to assert consistency.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
TODO: Explain details where not obvious
|
|
42
|
+
|
|
43
|
+
## Development
|
|
44
|
+
|
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
46
|
+
|
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
48
|
+
|
|
49
|
+
## Contributing
|
|
50
|
+
|
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/buggle/kvv-liveapi.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kvv/liveapi"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/kvv-liveapi.gemspec
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "kvv/liveapi/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "kvv-liveapi"
|
|
9
|
+
spec.version = KVV::Liveapi::VERSION
|
|
10
|
+
spec.authors = ["Christian Buggle"]
|
|
11
|
+
spec.email = ["christian@buggle.net"]
|
|
12
|
+
|
|
13
|
+
spec.homepage = "https://github.com//kvv-liveapi"
|
|
14
|
+
spec.summary = "KVV Live API (Karlsruhe Transport Agency)"
|
|
15
|
+
spec.description = "A simple adapter to query the KVV API (Karlsruher Verkehrsverbund - Karlsruhe Transport Agency) for live timetable data and stop information"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", '~> 1.16'
|
|
26
|
+
spec.add_development_dependency "rake", '~> 12.3'
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "minitest", '~> 5.11'
|
|
29
|
+
spec.add_development_dependency "minitest-vcr", '~> 1.4'
|
|
30
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
|
31
|
+
spec.add_development_dependency 'webmock', '~> 3.3'
|
|
32
|
+
spec.add_development_dependency "simplecov", '~> 0.15'
|
|
33
|
+
end
|
|
34
|
+
|
data/lib/kvv/liveapi.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module KVV
|
|
6
|
+
class Liveapi
|
|
7
|
+
API_KEY = '?key=377d840e54b59adbe53608ba1aad70e8'
|
|
8
|
+
API_BASE = 'https://live.kvv.de/webapp/'
|
|
9
|
+
|
|
10
|
+
URL_PATH_STOPS_BY_NAME = 'stops/byname/'
|
|
11
|
+
URL_PATH_DEPARTURES_BY_STOP = 'departures/bystop/'
|
|
12
|
+
URL_PATH_DEPARTURES_BY_LATLON = 'stops/bylatlon/'
|
|
13
|
+
URL_PATH_DEPARTURES_BY_ROUTE = 'departures/byroute/'
|
|
14
|
+
|
|
15
|
+
def self.departures_bystop_name name
|
|
16
|
+
self.departures_bystop guess_stop_id_by_name(name)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.departures_bystop stop_id
|
|
20
|
+
return {} unless stop_id
|
|
21
|
+
fetch_api_path [URL_PATH_DEPARTURES_BY_STOP, stop_id]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.departures_by_route route: nil, stop_id: nil
|
|
25
|
+
return {} unless route && stop_id
|
|
26
|
+
fetch_api_path [URL_PATH_DEPARTURES_BY_ROUTE, route, "/", stop_id]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.stops_by_name name
|
|
30
|
+
return [] if name.to_s.empty?
|
|
31
|
+
response = fetch_api_path [URL_PATH_STOPS_BY_NAME, name]
|
|
32
|
+
response["stops"] || {}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.stops_by_latlon lat: nil, lon: nil
|
|
36
|
+
return [] unless lat && lon
|
|
37
|
+
response = fetch_api_path [URL_PATH_DEPARTURES_BY_LATLON, lat, "/", lon]
|
|
38
|
+
response["stops"] || {}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def self.fetch_api_path *path
|
|
44
|
+
fetch [API_BASE, path, API_KEY].join
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.fetch url
|
|
48
|
+
uri = URI( url )
|
|
49
|
+
request = Net::HTTP::Get.new(uri)
|
|
50
|
+
|
|
51
|
+
req_options = {
|
|
52
|
+
use_ssl: uri.scheme == "https",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
56
|
+
http.request(request)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
case response.code
|
|
60
|
+
when "200"
|
|
61
|
+
JSON.parse(response.body)
|
|
62
|
+
else
|
|
63
|
+
{}
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.guess_stop_id_by_name name
|
|
68
|
+
first_stop = stops_by_name(name).first
|
|
69
|
+
first_stop["id"] unless first_stop.nil?
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kvv-liveapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Christian Buggle
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '12.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '12.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.11'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.11'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: minitest-vcr
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.4'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.4'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: minitest-reporters
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.1'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.1'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: webmock
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.3'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.3'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: simplecov
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.15'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.15'
|
|
111
|
+
description: A simple adapter to query the KVV API (Karlsruher Verkehrsverbund - Karlsruhe
|
|
112
|
+
Transport Agency) for live timetable data and stop information
|
|
113
|
+
email:
|
|
114
|
+
- christian@buggle.net
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".ruby-version"
|
|
121
|
+
- Gemfile
|
|
122
|
+
- LICENSE
|
|
123
|
+
- README.md
|
|
124
|
+
- Rakefile
|
|
125
|
+
- bin/console
|
|
126
|
+
- bin/setup
|
|
127
|
+
- kvv-liveapi.gemspec
|
|
128
|
+
- lib/kvv/liveapi.rb
|
|
129
|
+
- lib/kvv/liveapi/version.rb
|
|
130
|
+
homepage: https://github.com//kvv-liveapi
|
|
131
|
+
licenses: []
|
|
132
|
+
metadata: {}
|
|
133
|
+
post_install_message:
|
|
134
|
+
rdoc_options: []
|
|
135
|
+
require_paths:
|
|
136
|
+
- lib
|
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - ">="
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
requirements: []
|
|
148
|
+
rubyforge_project:
|
|
149
|
+
rubygems_version: 2.7.3
|
|
150
|
+
signing_key:
|
|
151
|
+
specification_version: 4
|
|
152
|
+
summary: KVV Live API (Karlsruhe Transport Agency)
|
|
153
|
+
test_files: []
|