samtrafiken_api 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 +6 -0
- data/.yardopts +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.md +19 -0
- data/README.md +42 -0
- data/Rakefile +18 -0
- data/lib/samtrafiken_api/api_base.rb +38 -0
- data/lib/samtrafiken_api/resrobot.rb +103 -0
- data/lib/samtrafiken_api/resrobot_stops.rb +51 -0
- data/lib/samtrafiken_api/stationinfo.rb +70 -0
- data/lib/samtrafiken_api/version.rb +3 -0
- data/lib/samtrafiken_api.rb +18 -0
- data/samtrafiken_api.gemspec +22 -0
- data/spec/resrobot_spec.rb +94 -0
- data/spec/resrobot_stops_spec.rb +38 -0
- data/spec/stationinfo_spec.rb +55 -0
- metadata +101 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3998173146a2f3467275c3ebbcb73e3f17783b95
|
|
4
|
+
data.tar.gz: 39a355725055977d5f1ac58554856fe0c8bfef6f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 821ef5ead0560e316a82caba5e97b6e810ec0cf41bd50fd1c19297106e7466af570efcd4e8162c8867b66e905ee3bf8a94cc1b7b047175d7ce64743d924f5253
|
|
7
|
+
data.tar.gz: 6b672ebfff6e5850779f78ca2843100022cbacdf6c937aa2985c60248308f62578cdccdff963e8e91a0a2505081b05de23da6cd382a58600e204cabce86fc380
|
data/.gitignore
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
samtrafiken_api (0.0.1)
|
|
5
|
+
httparty (~> 0.11)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
diff-lcs (1.2.4)
|
|
11
|
+
httparty (0.11.0)
|
|
12
|
+
multi_json (~> 1.0)
|
|
13
|
+
multi_xml (>= 0.5.2)
|
|
14
|
+
multi_json (1.7.6)
|
|
15
|
+
multi_xml (0.5.4)
|
|
16
|
+
rspec (2.13.0)
|
|
17
|
+
rspec-core (~> 2.13.0)
|
|
18
|
+
rspec-expectations (~> 2.13.0)
|
|
19
|
+
rspec-mocks (~> 2.13.0)
|
|
20
|
+
rspec-core (2.13.1)
|
|
21
|
+
rspec-expectations (2.13.0)
|
|
22
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
23
|
+
rspec-mocks (2.13.1)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (>= 1.0.0)
|
|
30
|
+
rspec (~> 2.6)
|
|
31
|
+
samtrafiken_api!
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2013-2014 Hannes Lilljequist
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Samtrafiken API
|
|
2
|
+
|
|
3
|
+
This gem is a thin wrapper around the
|
|
4
|
+
[public transportation web APIs](http://www.trafiklab.se/) provided by
|
|
5
|
+
Samtrafiken. Its classes and methods correspond to the different APIs and their
|
|
6
|
+
HTTP endpoints.
|
|
7
|
+
|
|
8
|
+
Please see the following pages to get an idea of what each API provides.
|
|
9
|
+
|
|
10
|
+
* [ResRobot Sök Resa](http://www.trafiklab.se/api/resrobot-sok-resa)
|
|
11
|
+
(`SamtrafikenAPI::Resrobot`)
|
|
12
|
+
* [ResRobot Stolptidtabeller](http://www.trafiklab.se/api/resrobot-stolptidtabeller)
|
|
13
|
+
(`SamtrafikenAPI::ResrobotStops`)
|
|
14
|
+
* [Samtrafiken Stationsinfo](http://www.trafiklab.se/api/samtrafiken-stationsinfo)
|
|
15
|
+
(`SamtrafikenAPI::Stationinfo`)
|
|
16
|
+
|
|
17
|
+
The methods return the raw json data provided by the APIs, parsed into Ruby
|
|
18
|
+
objects.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
You need to sign up with [Trafiklab](http://www.trafiklab.se/) and get API keys
|
|
23
|
+
for each of the APIs that you are going to use.
|
|
24
|
+
|
|
25
|
+
Please see the class documentation and the test suite for examples of how the
|
|
26
|
+
gem is used.
|
|
27
|
+
|
|
28
|
+
## Testing
|
|
29
|
+
|
|
30
|
+
Samtrafiken API uses rspec for testing. These environment variables need to be
|
|
31
|
+
defined in order to run the test suite.
|
|
32
|
+
|
|
33
|
+
* `RESROBOT_API_KEY` – a "Resrobot Sök Resa" API key. See
|
|
34
|
+
http://www.trafiklab.se/api/resrobot-sok-resa/dokumentation-resrobot-sok-resa-0
|
|
35
|
+
* `RESROBOT_STOPS_API_KEY` – a "Resrobot Stolptidtabeller" API key. See
|
|
36
|
+
http://www.trafiklab.se/api/resrobot-stolptidtabeller/dokumentation-stolptidtabeller
|
|
37
|
+
* `STATIONSINFO_API_KEY` – a "Samtrafiken Stationsinfo" API key. See
|
|
38
|
+
http://www.trafiklab.se/api/samtrafiken-stationsinfo/sammanfattande-dokumentation-stationsinfo
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
RESROBOT_API_KEY=MY-KEY RESROBOT_STOPS_API_KEY=MY-OTHER-KEY STATIONSINFO_API_KEY=MY-THIRD-KEY bundle exec rake test
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
|
|
5
|
+
Bundler::GemHelper.install_tasks
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
unless ENV['RESROBOT_API_KEY'].nil? || ENV['RESROBOT_STOPS_API_KEY'].nil? || ENV['STATIONSINFO_API_KEY'].nil?
|
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
10
|
+
desc "Run specs"
|
|
11
|
+
task :test => :spec
|
|
12
|
+
else
|
|
13
|
+
task :test do
|
|
14
|
+
puts "The API keys needed to run the tests are not defined."
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
task :default => :test
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module SamtrafikenAPI
|
|
2
|
+
|
|
3
|
+
# Base class for API implementations.
|
|
4
|
+
class APIBase
|
|
5
|
+
include HTTParty
|
|
6
|
+
|
|
7
|
+
# @!attribute response
|
|
8
|
+
# @return [HTTParty::Response] the HTTParty response object for the last
|
|
9
|
+
# request, which can be used for inspecting errors etc.
|
|
10
|
+
attr_accessor :response
|
|
11
|
+
|
|
12
|
+
# Initialize a new API object.
|
|
13
|
+
#
|
|
14
|
+
# @param api_key [String] The ResRobot Sök resa API key.
|
|
15
|
+
def initialize(api_key)
|
|
16
|
+
self.class.default_params({
|
|
17
|
+
apiVersion: '2.1',
|
|
18
|
+
key: api_key
|
|
19
|
+
})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
format :json
|
|
23
|
+
|
|
24
|
+
# Read a HTTParty response and return parsed data.
|
|
25
|
+
#
|
|
26
|
+
# @param response [HTTParty:Response] the HTTParty response.
|
|
27
|
+
# @return [Hash] a hash containing the returned data.
|
|
28
|
+
def read_response response
|
|
29
|
+
data = response.parsed_response.values[0]
|
|
30
|
+
if response.code == 200
|
|
31
|
+
data
|
|
32
|
+
else
|
|
33
|
+
raise data['errors']['error']['errordescription']
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module SamtrafikenAPI
|
|
2
|
+
|
|
3
|
+
# Samtrafiken ResRobot API.
|
|
4
|
+
#
|
|
5
|
+
# Documentation: http://www.trafiklab.se/api/resrobot-sok-resa
|
|
6
|
+
#
|
|
7
|
+
# @see
|
|
8
|
+
# See resrobot_spec.rb for details of how to use this class.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# @rr = SamtrafikenAPI::Resrobot.new('MY-API-KEY')
|
|
12
|
+
# @rr.set_mode(:realtime)
|
|
13
|
+
# query = {key: "value"}
|
|
14
|
+
# result = @rr.search query
|
|
15
|
+
# #=> {...}
|
|
16
|
+
class Resrobot < APIBase
|
|
17
|
+
#debug_output $stdout
|
|
18
|
+
|
|
19
|
+
def self.uris
|
|
20
|
+
{
|
|
21
|
+
timetable: 'https://api.trafiklab.se/samtrafiken/resrobot',
|
|
22
|
+
realtime: 'https://api.trafiklab.se/samtrafiken/resrobotsuper'
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
base_uri self.uris[:timetable]
|
|
27
|
+
|
|
28
|
+
# Set the API mode to use either real time or time table data.
|
|
29
|
+
#
|
|
30
|
+
# @param mode [Symbol] either `:timetable` or `:realtime`.
|
|
31
|
+
def set_mode mode
|
|
32
|
+
if self.class.uris.has_key? mode
|
|
33
|
+
self.class.base_uri self.class.uris[mode]
|
|
34
|
+
else
|
|
35
|
+
raise "Invalid API mode."
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Endpoint: Search
|
|
40
|
+
#
|
|
41
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/search
|
|
42
|
+
#
|
|
43
|
+
# @param query [Hash] query keys and values.
|
|
44
|
+
# @return [Hash] a hash containing the returned data.
|
|
45
|
+
def search query
|
|
46
|
+
@response = self.class.get('/Search.json', :query => query)
|
|
47
|
+
return read_response @response
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Endpoint: StationsInZone
|
|
51
|
+
#
|
|
52
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/stationsinzone
|
|
53
|
+
#
|
|
54
|
+
# @param query [Hash] query keys and values.
|
|
55
|
+
# @return [Hash] a hash containing the returned data.
|
|
56
|
+
def stations_in_zone query
|
|
57
|
+
@response = self.class.get('/StationsInZone.json', :query => query)
|
|
58
|
+
return read_response @response
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Endpoint: TimeTablePeriod
|
|
62
|
+
#
|
|
63
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/timetableperiod
|
|
64
|
+
#
|
|
65
|
+
# @return [Hash] a hash containing the returned data.
|
|
66
|
+
def time_table_period
|
|
67
|
+
@response = self.class.get('/TimeTablePeriod.json')
|
|
68
|
+
return read_response @response
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Endpoint: ProducerList
|
|
72
|
+
#
|
|
73
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/producerlist
|
|
74
|
+
#
|
|
75
|
+
# @return [Hash] a hash containing the returned data.
|
|
76
|
+
def producer_list
|
|
77
|
+
@response = self.class.get('/ProducerList.json')
|
|
78
|
+
return read_response @response
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Endpoint: TransportModeList
|
|
82
|
+
#
|
|
83
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/transportmodelist
|
|
84
|
+
#
|
|
85
|
+
# @return [Hash] a hash containing the returned data.
|
|
86
|
+
def transport_mode_list
|
|
87
|
+
@response = self.class.get('/TransportModeList.json')
|
|
88
|
+
return read_response @response
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Endpoint: FindLocation
|
|
92
|
+
#
|
|
93
|
+
# Documentation: http://www.trafiklab.se/api/resrobot/findlocation
|
|
94
|
+
#
|
|
95
|
+
# @param query [Hash] query keys and values.
|
|
96
|
+
# @return [Hash] a hash containing the returned data.
|
|
97
|
+
def find_location query
|
|
98
|
+
@response = self.class.get('/FindLocation.json', :query => query)
|
|
99
|
+
return read_response @response
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module SamtrafikenAPI
|
|
2
|
+
|
|
3
|
+
# Samtrafiken ResRobot Stolptidtabeller API.
|
|
4
|
+
#
|
|
5
|
+
# Documentation: http://www.trafiklab.se/api/resrobot-stolptidtabeller
|
|
6
|
+
#
|
|
7
|
+
# @see
|
|
8
|
+
# See resrobot_stops_spec.rb for details of how to use this class.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# @rr = SamtrafikenAPI::ResrobotStops.new('MY-API-KEY')
|
|
12
|
+
# @rr.set_mode(:realtime)
|
|
13
|
+
# query = {key: "value"}
|
|
14
|
+
# result = @rr.get_departures query
|
|
15
|
+
# #=> {...}
|
|
16
|
+
class ResrobotStops < APIBase
|
|
17
|
+
#debug_output $stdout
|
|
18
|
+
|
|
19
|
+
def self.uris
|
|
20
|
+
{
|
|
21
|
+
timetable: 'https://api.trafiklab.se/samtrafiken/resrobotstops',
|
|
22
|
+
realtime: 'https://api.trafiklab.se/samtrafiken/resrobotstopssuper'
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
base_uri self.uris[:timetable]
|
|
27
|
+
|
|
28
|
+
# Set the API mode to use either real time or time table data.
|
|
29
|
+
#
|
|
30
|
+
# @param mode [Symbol] either `:timetable` or `:realtime`.
|
|
31
|
+
def set_mode mode
|
|
32
|
+
if self.class.uris.has_key? mode
|
|
33
|
+
self.class.base_uri self.class.uris[mode]
|
|
34
|
+
else
|
|
35
|
+
raise "Invalid API mode."
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Endpoint: GetDepartures
|
|
41
|
+
# Documentation: http://www.trafiklab.se/api/resrobot-stolptidtabeller/getdepartures
|
|
42
|
+
#
|
|
43
|
+
# @param query [Hash] query keys and values.
|
|
44
|
+
# @return [Hash] a hash containing the returned data.
|
|
45
|
+
def get_departures query
|
|
46
|
+
@response = self.class.get('/GetDepartures.json', :query => query)
|
|
47
|
+
return read_response @response
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
|
|
3
|
+
module SamtrafikenAPI
|
|
4
|
+
|
|
5
|
+
# Samtrafiken Stationsinfo API.
|
|
6
|
+
#
|
|
7
|
+
# Documentation: http://www.trafiklab.se/api/samtrafiken-stationsinfo
|
|
8
|
+
#
|
|
9
|
+
# @see
|
|
10
|
+
# See stationsinfo_spec.rb for details of how to use this class.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# @si = SamtrafikenAPI::StationsInfo.new('MY-API-KEY')
|
|
14
|
+
# result = @si.stations
|
|
15
|
+
# #=> [...]
|
|
16
|
+
class Stationinfo < APIBase
|
|
17
|
+
#debug_output $stdout
|
|
18
|
+
|
|
19
|
+
base_uri 'https://api.trafiklab.se/samtrafiken/stationinfo'
|
|
20
|
+
|
|
21
|
+
# Endpoint: Stations
|
|
22
|
+
#
|
|
23
|
+
# Documentation: http://www.trafiklab.se/api/samtrafiken-stationsinfo/alla-stationer
|
|
24
|
+
#
|
|
25
|
+
# @param query [Hash] query keys and values.
|
|
26
|
+
# @return [Array] an array of all station objects.
|
|
27
|
+
def stations query = {}
|
|
28
|
+
@response = self.class.get('/stations.json', :query => query)
|
|
29
|
+
read_response(@response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Endpoint: Category
|
|
33
|
+
#
|
|
34
|
+
# Documentation: http://www.trafiklab.se/api/samtrafiken-stationsinfo/lista-stationer-baserat-pa-kategori
|
|
35
|
+
#
|
|
36
|
+
# @param id [Integer] the category ID.
|
|
37
|
+
# @param query [Hash] query keys and values.
|
|
38
|
+
# @return [Array] an array of all station objects.
|
|
39
|
+
def category id, query = {}
|
|
40
|
+
@response = self.class.get("/category/#{id}.json", :query => query)
|
|
41
|
+
read_response(@response)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Endpoint: Station
|
|
45
|
+
#
|
|
46
|
+
# Documentation: http://www.trafiklab.se/api/samtrafiken-stationsinfo/information-om-en-station
|
|
47
|
+
#
|
|
48
|
+
# @param id [Integer] the station ID.
|
|
49
|
+
# @return [Object] a station object.
|
|
50
|
+
def station id
|
|
51
|
+
@response = self.class.get("/stations/#{id}.json")
|
|
52
|
+
read_response(@response)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Endpoint: Image
|
|
56
|
+
#
|
|
57
|
+
# Documentation: http://www.trafiklab.se/api/samtrafiken-stationsinfo/bilder
|
|
58
|
+
#
|
|
59
|
+
# @todo: the images endpoint is currently broken and doesn't return valid
|
|
60
|
+
# image data. This method has not been successfully tested.
|
|
61
|
+
#
|
|
62
|
+
# @param id [Integer] the image ID.
|
|
63
|
+
# @return [String] image data.
|
|
64
|
+
def image id
|
|
65
|
+
query = URI.encode_www_form self.class.default_params
|
|
66
|
+
open("#{self.class.base_uri}/images/#{id}.json?#{query}") { |f| f.read }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'samtrafiken_api/api_base'
|
|
3
|
+
require 'samtrafiken_api/resrobot'
|
|
4
|
+
require 'samtrafiken_api/resrobot_stops'
|
|
5
|
+
require 'samtrafiken_api/stationinfo'
|
|
6
|
+
require 'json'
|
|
7
|
+
|
|
8
|
+
# Monkey patching HTTParty.
|
|
9
|
+
module HTTParty
|
|
10
|
+
# A custom Parser::json implementation that converts API data to UTF-8.
|
|
11
|
+
#
|
|
12
|
+
# See http://www.trafiklab.se/blogg/2013/aug/13e-september-uppgraderas-api-proxyn-alla-bor-testa-sina-applikationer
|
|
13
|
+
class Parser
|
|
14
|
+
def json
|
|
15
|
+
JSON.load(body.force_encoding("ISO-8859-1").encode("UTF-8"), nil)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path("../lib/samtrafiken_api/version", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = 'samtrafiken_api'
|
|
6
|
+
s.version = SamtrafikenAPI::VERSION
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.summary = "Samtrafiken web APIs"
|
|
9
|
+
s.description = "A ruby implementation of the Samtrafiken web APIs."
|
|
10
|
+
s.authors = ["Hannes Lilljequist"]
|
|
11
|
+
s.email = 'hannes@sthlmconnection.se'
|
|
12
|
+
s.homepage = 'http://rubygems.org/gems/samtrafiken_api'
|
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
14
|
+
|
|
15
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
|
16
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
|
17
|
+
|
|
18
|
+
s.add_runtime_dependency 'httparty', '~> 0.11'
|
|
19
|
+
|
|
20
|
+
s.files = `git ls-files`.split("\n")
|
|
21
|
+
s.require_path = 'lib'
|
|
22
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'samtrafiken_api'
|
|
2
|
+
|
|
3
|
+
describe SamtrafikenAPI::Resrobot do
|
|
4
|
+
before do
|
|
5
|
+
@rr = SamtrafikenAPI::Resrobot.new(ENV['RESROBOT_API_KEY'])
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "can set the API mode" do
|
|
9
|
+
expect {
|
|
10
|
+
@rr.set_mode(:realtime)
|
|
11
|
+
@rr.set_mode(:timetable)
|
|
12
|
+
}.to_not raise_error
|
|
13
|
+
expect {
|
|
14
|
+
@rr.set_mode(:bogus_mode)
|
|
15
|
+
}.to raise_error
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "can make a Search request" do
|
|
19
|
+
query = {
|
|
20
|
+
from: 'Vitabergsparken',
|
|
21
|
+
to: 'Luma park',
|
|
22
|
+
fromX: 18.086917,
|
|
23
|
+
fromY: 59.311896,
|
|
24
|
+
toX: 18.09596,
|
|
25
|
+
toY: 59.304503,
|
|
26
|
+
coordSys: 'WGS84',
|
|
27
|
+
}
|
|
28
|
+
expect {
|
|
29
|
+
result = @rr.search query
|
|
30
|
+
result.should be_a(Hash)
|
|
31
|
+
}.to_not raise_error
|
|
32
|
+
@rr.response.class.should == HTTParty::Response
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "raises error on invalid Search requests" do
|
|
36
|
+
expect {
|
|
37
|
+
@rr.search({})
|
|
38
|
+
}.to raise_error
|
|
39
|
+
@rr.response.class.should == HTTParty::Response
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
it "can make a StationsInZone request" do
|
|
44
|
+
query = {
|
|
45
|
+
centerX: 18.09596,
|
|
46
|
+
centerY: 59.304503,
|
|
47
|
+
radius: 100,
|
|
48
|
+
coordSys: 'WGS84',
|
|
49
|
+
}
|
|
50
|
+
expect {
|
|
51
|
+
result = @rr.stations_in_zone query
|
|
52
|
+
result.should be_a(Hash)
|
|
53
|
+
}.to_not raise_error
|
|
54
|
+
@rr.response.class.should == HTTParty::Response
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "can make a TimeTablePeriod request" do
|
|
58
|
+
expect {
|
|
59
|
+
result = @rr.time_table_period
|
|
60
|
+
result.should be_a(Hash)
|
|
61
|
+
}.to_not raise_error
|
|
62
|
+
@rr.response.class.should == HTTParty::Response
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "can make a ProducerList request" do
|
|
66
|
+
expect {
|
|
67
|
+
result = @rr.producer_list
|
|
68
|
+
result.should be_a(Hash)
|
|
69
|
+
}.to_not raise_error
|
|
70
|
+
@rr.response.class.should == HTTParty::Response
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "can make a TransportModeList request" do
|
|
74
|
+
expect {
|
|
75
|
+
result = @rr.transport_mode_list
|
|
76
|
+
result.should be_a(Hash)
|
|
77
|
+
}.to_not raise_error
|
|
78
|
+
@rr.response.class.should == HTTParty::Response
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "can make a FindLocation request" do
|
|
82
|
+
query = {
|
|
83
|
+
from: 'Sickla kanalgata 67, Stockholm',
|
|
84
|
+
to: 'Stockholm Centralstation',
|
|
85
|
+
coordSys: 'WGS84',
|
|
86
|
+
}
|
|
87
|
+
expect {
|
|
88
|
+
result = @rr.find_location query
|
|
89
|
+
result.should be_a(Hash)
|
|
90
|
+
}.to_not raise_error
|
|
91
|
+
@rr.response.class.should == HTTParty::Response
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'samtrafiken_api'
|
|
2
|
+
|
|
3
|
+
describe SamtrafikenAPI::ResrobotStops do
|
|
4
|
+
before do
|
|
5
|
+
@rr = SamtrafikenAPI::ResrobotStops.new(ENV['RESROBOT_STOPS_API_KEY'])
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "can set the API mode" do
|
|
9
|
+
expect {
|
|
10
|
+
@rr.set_mode(:realtime)
|
|
11
|
+
@rr.set_mode(:timetable)
|
|
12
|
+
}.to_not raise_error
|
|
13
|
+
expect {
|
|
14
|
+
@rr.set_mode(:bogus_mode)
|
|
15
|
+
}.to raise_error
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "can make a GetDepartures request" do
|
|
19
|
+
query = {
|
|
20
|
+
locationId: 7424929,
|
|
21
|
+
timeSpan: 30,
|
|
22
|
+
coordSys: 'WGS84',
|
|
23
|
+
}
|
|
24
|
+
expect {
|
|
25
|
+
result = @rr.get_departures query
|
|
26
|
+
result.should be_a(Hash)
|
|
27
|
+
}.to_not raise_error
|
|
28
|
+
@rr.response.class.should == HTTParty::Response
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "raises error on invalid GetDepartures requests" do
|
|
32
|
+
expect {
|
|
33
|
+
@rr.get_departures({})
|
|
34
|
+
}.to raise_error
|
|
35
|
+
@rr.response.class.should == HTTParty::Response
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'samtrafiken_api'
|
|
2
|
+
|
|
3
|
+
STATION_CATEGORY_BUS = 31
|
|
4
|
+
STATION_SUBCATEGORY_BUSSTOP = 61
|
|
5
|
+
STATION_ID_STOCKHOLM_CENTRAL = 7400001
|
|
6
|
+
STATION_ID_MISSING = 99999999999999
|
|
7
|
+
STATION_IMAGE_ID_STOCKHOLM_CENTRAL = 2605
|
|
8
|
+
|
|
9
|
+
describe SamtrafikenAPI::Stationinfo do
|
|
10
|
+
before do
|
|
11
|
+
@si = SamtrafikenAPI::Stationinfo.new(ENV['STATIONSINFO_API_KEY'])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "can make a List request" do
|
|
15
|
+
expect {
|
|
16
|
+
result = @si.stations
|
|
17
|
+
result.should be_a(Hash)
|
|
18
|
+
result = @si.stations sort: "name"
|
|
19
|
+
result.should be_a(Hash)
|
|
20
|
+
}.to_not raise_error
|
|
21
|
+
@si.response.class.should == HTTParty::Response
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "can make a Category request" do
|
|
25
|
+
expect {
|
|
26
|
+
result = @si.category STATION_CATEGORY_BUS, propid: STATION_SUBCATEGORY_BUSSTOP
|
|
27
|
+
result.should be_a(Hash)
|
|
28
|
+
}.to_not raise_error
|
|
29
|
+
@si.response.class.should == HTTParty::Response
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "can make a Station request" do
|
|
33
|
+
expect {
|
|
34
|
+
result = @si.station STATION_ID_STOCKHOLM_CENTRAL
|
|
35
|
+
result.should be_a(Hash)
|
|
36
|
+
}.to_not raise_error
|
|
37
|
+
@si.response.class.should == HTTParty::Response
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "raises error on Station requests with missing IDs" do
|
|
41
|
+
expect {
|
|
42
|
+
@si.station STATION_ID_MISSING
|
|
43
|
+
}.to raise_error
|
|
44
|
+
@si.response.class.should == HTTParty::Response
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "can make an Image request" do
|
|
48
|
+
expect {
|
|
49
|
+
@si.image STATION_IMAGE_ID_STOCKHOLM_CENTRAL
|
|
50
|
+
# @todo: the images endpoint is currently broken and doesn't return valid
|
|
51
|
+
# image data.
|
|
52
|
+
}.to_not raise_error
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: samtrafiken_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hannes Lilljequist
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-06 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.0.0
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.0.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.6'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.6'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: httparty
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.11'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.11'
|
|
55
|
+
description: A ruby implementation of the Samtrafiken web APIs.
|
|
56
|
+
email: hannes@sthlmconnection.se
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- .gitignore
|
|
62
|
+
- .yardopts
|
|
63
|
+
- Gemfile
|
|
64
|
+
- Gemfile.lock
|
|
65
|
+
- LICENSE.md
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/samtrafiken_api.rb
|
|
69
|
+
- lib/samtrafiken_api/api_base.rb
|
|
70
|
+
- lib/samtrafiken_api/resrobot.rb
|
|
71
|
+
- lib/samtrafiken_api/resrobot_stops.rb
|
|
72
|
+
- lib/samtrafiken_api/stationinfo.rb
|
|
73
|
+
- lib/samtrafiken_api/version.rb
|
|
74
|
+
- samtrafiken_api.gemspec
|
|
75
|
+
- spec/resrobot_spec.rb
|
|
76
|
+
- spec/resrobot_stops_spec.rb
|
|
77
|
+
- spec/stationinfo_spec.rb
|
|
78
|
+
homepage: http://rubygems.org/gems/samtrafiken_api
|
|
79
|
+
licenses: []
|
|
80
|
+
metadata: {}
|
|
81
|
+
post_install_message:
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: 1.3.6
|
|
95
|
+
requirements: []
|
|
96
|
+
rubyforge_project:
|
|
97
|
+
rubygems_version: 2.0.3
|
|
98
|
+
signing_key:
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: Samtrafiken web APIs
|
|
101
|
+
test_files: []
|