transprt 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e86599721dde251b05f75970758afedf23e77241
4
- data.tar.gz: aa84df82854d28b6482dc5c24835d948d0893a24
3
+ metadata.gz: 37769de876d6c551e33027f937f972c6a7b8c3bd
4
+ data.tar.gz: 0ea98dc958a2df6b632b2af56cb24d569fa0e97e
5
5
  SHA512:
6
- metadata.gz: 598f262abe3ff3386e62aa31c085e3dcc11f5c54011b431314ea1ef58d6e763d038ed155d087e2e806cb00ff3b82e505e1ebf6fa23a1bc70858998730983ec11
7
- data.tar.gz: 4f87d14122932451578676de4e289dfd2427ad140bc848a90457e526e4e6fbe17668f1070d08002fec5e3701bc819b53cc4343fc057a53f2d38e1d5dc2850995
6
+ metadata.gz: 9e6f58ee195a1124a6ce8a8e8014ed7be496217da5beb6fc571122d610960d65d575ed92eb5472fe784c732d99f7830991ae0a2133342804bc6c5a11349e72dd
7
+ data.tar.gz: 9677cca5e16aa134cd8fb547e7a992a79d628bc8c1ca68844a664d9805934bddab2d2f26502720904affa11c4abf670949ede1faa6ae29a5933172986e787918
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  .DS_Store
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bramipsum.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ transprt (0.2.1)
5
+ json (>= 1.8.0)
6
+ rest-client (>= 1.6.7, < 2.1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.4.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ domain_name (0.5.20160615)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ hashdiff (0.3.0)
17
+ http-cookie (1.0.2)
18
+ domain_name (~> 0.5)
19
+ json (2.0.1)
20
+ mime-types (3.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2016.0521)
23
+ minitest (5.8.4)
24
+ netrc (0.11.0)
25
+ rest-client (2.0.0)
26
+ http-cookie (>= 1.0.2, < 2.0)
27
+ mime-types (>= 1.16, < 4.0)
28
+ netrc (~> 0.8)
29
+ safe_yaml (1.0.4)
30
+ unf (0.1.4)
31
+ unf_ext
32
+ unf_ext (0.0.7.2)
33
+ webmock (2.1.0)
34
+ addressable (>= 2.3.6)
35
+ crack (>= 0.3.2)
36
+ hashdiff
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ minitest (~> 5.8.4)
43
+ transprt!
44
+ webmock (~> 2.1.0)
45
+
46
+ BUNDLED WITH
47
+ 1.12.5
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/transprt.png)](http://badge.fury.io/rb/transprt)
4
4
  [![Dependency Status](https://gemnasium.com/ghn/transprt.png)](https://gemnasium.com/ghn/transprt)
5
5
 
6
- Use the Swiss public transport API (open data). http://transport.opendata.ch
6
+ Ruby client for the Swiss public transport API at http://transport.opendata.ch
7
7
 
8
8
  ##Installation
9
9
 
@@ -16,22 +16,32 @@ ruby example.rb
16
16
 
17
17
  ##Usage
18
18
 
19
+ To talk to the API, get a client:
20
+
21
+ ```ruby
22
+ require 'transprt'
23
+ client = Transprt::Client.new
24
+ ```
25
+
26
+ See below how to use this client.
27
+
28
+ Hint: You may specify a mirror of the API other than http://transport.opendata.ch using the first argument of the constructor.
29
+
30
+
19
31
  ###Locations
20
32
  http://transport.opendata.ch/#locations
21
33
 
22
34
  ```ruby
23
- require 'transprt'
24
- Transprt.locations :query => 'Geneva'
35
+ client.locations query: 'Geneva'
25
36
  # => [{"id"=>"008501008", "name"=>"Genève", "score"=>"101", "coordinate"=>{"type"=>"WGS84", "x"=>6.142455, "y"=>46.210199}, "distance"=>nil}]
26
37
  ```
27
38
 
28
- ###Connexions
39
+ ###Connections
29
40
 
30
41
  http://transport.opendata.ch/#connections
31
42
 
32
43
  ```ruby
33
- require 'transprt'
34
- Transprt.connexions :from => 'Lausanne', :to => 'Geneva'
44
+ client.connections from: 'Lausanne', to: 'Geneva'
35
45
  ```
36
46
 
37
47
  ###Station board
@@ -40,7 +50,15 @@ http://transport.opendata.ch/#stationboard
40
50
 
41
51
  ```ruby
42
52
  # Display station board
43
- Transprt.stationboard :station => 'Lausanne'
53
+ client.stationboard station: 'Lausanne'
54
+ ```
55
+
56
+ ## Development
57
+
58
+ Running the tests
59
+
60
+ ```bash
61
+ rake test
44
62
  ```
45
63
 
46
64
  ##Licence
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.pattern = "test/*_test.rb"
6
+ end
data/example.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'lib/transprt')
2
2
 
3
- puts Transprt.locations :query => 'genf'
4
- puts Transprt.connections :from => 'Lausanne', :to => 'Geneve'
5
- puts Transprt.locations :station => 'Aarau'
3
+ client = Transprt::Client.new
4
+ puts client.locations query: 'genf'
5
+ puts client.connections from: 'Lausanne', to: 'Geneve'
6
+ puts client.locations station: 'Aarau'
data/lib/transprt.rb CHANGED
@@ -2,61 +2,77 @@ require 'rubygems'
2
2
  require 'rest_client'
3
3
  require 'json'
4
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('&')
5
+ module Transprt
6
+ class Client
7
+ DEFAULT_DOMAIN = 'http://transport.opendata.ch'
8
+ VERSION = 'v1'
9
+
10
+ def initialize(domain=DEFAULT_DOMAIN, version=VERSION)
11
+ @domain = domain
12
+ @version = version
13
+ end
14
+
15
+ #
16
+ # => find locations
17
+ #
18
+ def locations(parameters)
19
+ allowed_parameters = ['query', 'x', 'y', 'type']
20
+
21
+ query = create_query(parameters, allowed_parameters)
22
+ locations = perform('locations', query)
23
+
24
+ locations['stations']
25
+ end
26
+
27
+ #
28
+ # => find connections
29
+ #
30
+ def connections(parameters)
31
+ allowed_parameters = ['from', 'to', 'via', 'date', 'time', 'isArrivalTime', 'transportations', 'limit', 'page',
32
+ 'direct', 'sleeper', 'couchette', 'bike']
33
+
34
+ query = create_query(parameters, allowed_parameters)
35
+ locations = perform('connections', query)
36
+
37
+ locations['connections']
38
+ end
39
+
40
+ #
41
+ # => find station boards
42
+ #
43
+ def stationboard(parameters)
44
+ allowed_parameters = ['station', 'id', 'limit', 'transportations', 'datetime']
45
+
46
+ query = create_query(parameters, allowed_parameters)
47
+ locations = perform('stationboard', query)
48
+
49
+ locations['stationboard']
50
+ end
51
+
52
+ private
53
+ attr_reader :domain, :version
54
+
55
+ def perform(endpoint, query)
56
+ url = "#{create_url(endpoint)}#{query}"
57
+ response = RestClient.get(url)
58
+
59
+ # Uncomment the line below to dump the response in order to generate
60
+ # a file to use as response stub in tests.
61
+ # File.write('/tmp/response.json', response)
62
+
63
+ JSON.parse(response)
64
+ end
65
+
66
+ def create_url(endpoint)
67
+ [domain, version, endpoint].join('/') + '?'
68
+ end
69
+
70
+ def create_query(parameters, allowed_parameters)
71
+ parameters.map do |k,v|
72
+ next unless allowed_parameters.include?(k.to_s)
73
+
74
+ "#{k}=#{URI.escape(v)}"
75
+ end.join('&')
76
+ end
61
77
  end
62
78
  end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+ require 'pp'
3
+
4
+ class ClientTest < Minitest::Test
5
+
6
+ def setup
7
+ WebMock.reset!
8
+
9
+ @client = Transprt::Client.new
10
+ end
11
+
12
+ def test_locations
13
+ stub_response('client_test_test_locations.json')
14
+
15
+ locations = @client.locations query: 'genf'
16
+
17
+ assert locations.length == 1
18
+
19
+ first_location = locations.first
20
+
21
+ assert first_location['id'] == "008501008"
22
+ assert first_location['name'] == "Genève"
23
+ end
24
+
25
+ def test_connections
26
+ stub_response('client_test_test_connections.json')
27
+
28
+ connections = @client.connections from: 'Lausanne', to: 'Geneve'
29
+
30
+ first_connection = connections.first
31
+
32
+ assert first_connection['from']['station']['name'] == 'Lausanne'
33
+ assert first_connection['to']['station']['name'] == 'Genève'
34
+ end
35
+
36
+ def test_stationboard
37
+ skip 'feel free to add a test for Client#stationboard'
38
+ end
39
+
40
+ def test_escaping
41
+ # This makes sure the umlaut below gets escaped, if not we'll see an URI::InvalidURIError
42
+ stub_request(:get, /.*/).to_return(status: 200, body: {'connections': nil}.to_json)
43
+
44
+ connections = @client.connections from: 'Lausanne', to: 'Zürich'
45
+ end
46
+
47
+ def stub_response(name, url=/.*/, method=:get)
48
+ # Uncomment lines below should you feel the urge to test against the live API
49
+ # as the stubbing isn't very thorough as of now. (e.g. URLs requested aren't checked)
50
+ # WebMock.allow_net_connect!
51
+ # return
52
+
53
+ dirname = File.dirname(__FILE__)
54
+
55
+ content = File.read("#{dirname}/responses/#{name}")
56
+
57
+ stub_request(method, url).to_return(status: 200, body: content)
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+ {"connections":[{"from":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:42:00+0200","departureTimestamp":1468590120,"delay":null,"platform":"5","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"to":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:18:00+0200","arrivalTimestamp":1468592280,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}},"duration":"00d00:36:00","transfers":0,"service":{"regular":"daily","irregular":null},"products":["IC"],"capacity1st":1,"capacity2nd":2,"sections":[{"journey":{"name":"IC 720","category":"IC","subcategory":null,"categoryCode":1,"number":"720","operator":"SBB","to":"Gen\u00e8ve-A\u00e9roport","passList":[{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":"2016-07-15T15:40:00+0200","arrivalTimestamp":1468590000,"departure":"2016-07-15T15:42:00+0200","departureTimestamp":1468590120,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:18:00+0200","arrivalTimestamp":1468592280,"departure":"2016-07-15T16:20:00+0200","departureTimestamp":1468592400,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}],"capacity1st":1,"capacity2nd":2},"walk":null,"departure":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:42:00+0200","departureTimestamp":1468590120,"delay":null,"platform":"5","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"arrival":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:18:00+0200","arrivalTimestamp":1468592280,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}}]},{"from":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:45:00+0200","departureTimestamp":1468590300,"delay":null,"platform":"7","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"to":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:21:00+0200","arrivalTimestamp":1468592460,"departure":null,"departureTimestamp":null,"delay":null,"platform":"4","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}},"duration":"00d00:36:00","transfers":0,"service":{"regular":"daily","irregular":"not 5. Nov"},"products":["EC"],"capacity1st":1,"capacity2nd":2,"sections":[{"journey":{"name":"EC 34","category":"EC","subcategory":null,"categoryCode":1,"number":"34","operator":"SBB","to":"Gen\u00e8ve","passList":[{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":"2016-07-15T15:42:00+0200","arrivalTimestamp":1468590120,"departure":"2016-07-15T15:45:00+0200","departureTimestamp":1468590300,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:21:00+0200","arrivalTimestamp":1468592460,"departure":null,"departureTimestamp":null,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}],"capacity1st":1,"capacity2nd":2},"walk":null,"departure":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:45:00+0200","departureTimestamp":1468590300,"delay":null,"platform":"7","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"arrival":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:21:00+0200","arrivalTimestamp":1468592460,"departure":null,"departureTimestamp":null,"delay":null,"platform":"4","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}}]},{"from":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:48:00+0200","departureTimestamp":1468590480,"delay":null,"platform":"8","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":1},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"to":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:30:00+0200","arrivalTimestamp":1468593000,"departure":null,"departureTimestamp":null,"delay":null,"platform":"3","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}},"duration":"00d00:42:00","transfers":0,"service":{"regular":"daily","irregular":null},"products":["IR"],"capacity1st":1,"capacity2nd":1,"sections":[{"journey":{"name":"IR 1722","category":"IR","subcategory":null,"categoryCode":2,"number":"1722","operator":"SBB","to":"Gen\u00e8ve-A\u00e9roport","passList":[{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":"2016-07-15T15:39:00+0200","arrivalTimestamp":1468589940,"departure":"2016-07-15T15:48:00+0200","departureTimestamp":1468590480,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":1},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},{"station":{"id":"8501037","name":"Morges","score":null,"coordinate":{"type":"WGS84","x":46.511096,"y":6.49396},"distance":null},"arrival":"2016-07-15T15:58:00+0200","arrivalTimestamp":1468591080,"departure":"2016-07-15T15:59:00+0200","departureTimestamp":1468591140,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":1},"realtimeAvailability":"RT_BHF","location":{"id":"8501037","name":"Morges","score":null,"coordinate":{"type":"WGS84","x":46.511096,"y":6.49396},"distance":null}},{"station":{"id":"8501030","name":"Nyon","score":null,"coordinate":{"type":"WGS84","x":46.384411,"y":6.23597},"distance":null},"arrival":"2016-07-15T16:14:00+0200","arrivalTimestamp":1468592040,"departure":"2016-07-15T16:15:00+0200","departureTimestamp":1468592100,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":1},"realtimeAvailability":"RT_BHF","location":{"id":"8501030","name":"Nyon","score":null,"coordinate":{"type":"WGS84","x":46.384411,"y":6.23597},"distance":null}},{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:30:00+0200","arrivalTimestamp":1468593000,"departure":"2016-07-15T16:32:00+0200","departureTimestamp":1468593120,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}],"capacity1st":1,"capacity2nd":1},"walk":null,"departure":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:48:00+0200","departureTimestamp":1468590480,"delay":null,"platform":"8","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":1},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"arrival":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:30:00+0200","arrivalTimestamp":1468593000,"departure":null,"departureTimestamp":null,"delay":null,"platform":"3","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}}]},{"from":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:51:00+0200","departureTimestamp":1468590660,"delay":null,"platform":"9","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"to":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:41:00+0200","arrivalTimestamp":1468593660,"departure":null,"departureTimestamp":null,"delay":null,"platform":"3","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}},"duration":"00d00:50:00","transfers":0,"service":{"regular":"daily","irregular":null},"products":["RE"],"capacity1st":1,"capacity2nd":2,"sections":[{"journey":{"name":"RE 3222","category":"RE","subcategory":null,"categoryCode":3,"number":"3222","operator":"SBB","to":"Gen\u00e8ve","passList":[{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:51:00+0200","departureTimestamp":1468590660,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},{"station":{"id":"8501118","name":"Renens VD","score":null,"coordinate":{"type":"WGS84","x":46.53703,"y":6.578935},"distance":null},"arrival":"2016-07-15T15:56:00+0200","arrivalTimestamp":1468590960,"departure":"2016-07-15T15:57:00+0200","departureTimestamp":1468591020,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501118","name":"Renens VD","score":null,"coordinate":{"type":"WGS84","x":46.53703,"y":6.578935},"distance":null}},{"station":{"id":"8501037","name":"Morges","score":null,"coordinate":{"type":"WGS84","x":46.511096,"y":6.49396},"distance":null},"arrival":"2016-07-15T16:03:00+0200","arrivalTimestamp":1468591380,"departure":"2016-07-15T16:04:00+0200","departureTimestamp":1468591440,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501037","name":"Morges","score":null,"coordinate":{"type":"WGS84","x":46.511096,"y":6.49396},"distance":null}},{"station":{"id":"8501035","name":"Allaman","score":null,"coordinate":{"type":"WGS84","x":46.475741,"y":6.399699},"distance":null},"arrival":"2016-07-15T16:10:00+0200","arrivalTimestamp":1468591800,"departure":"2016-07-15T16:11:00+0200","departureTimestamp":1468591860,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501035","name":"Allaman","score":null,"coordinate":{"type":"WGS84","x":46.475741,"y":6.399699},"distance":null}},{"station":{"id":"8501033","name":"Rolle","score":null,"coordinate":{"type":"WGS84","x":46.462734,"y":6.336406},"distance":null},"arrival":"2016-07-15T16:14:00+0200","arrivalTimestamp":1468592040,"departure":"2016-07-15T16:15:00+0200","departureTimestamp":1468592100,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501033","name":"Rolle","score":null,"coordinate":{"type":"WGS84","x":46.462734,"y":6.336406},"distance":null}},{"station":{"id":"8501031","name":"Gland","score":null,"coordinate":{"type":"WGS84","x":46.419972,"y":6.26914},"distance":null},"arrival":"2016-07-15T16:19:00+0200","arrivalTimestamp":1468592340,"departure":"2016-07-15T16:20:00+0200","departureTimestamp":1468592400,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501031","name":"Gland","score":null,"coordinate":{"type":"WGS84","x":46.419972,"y":6.26914},"distance":null}},{"station":{"id":"8501030","name":"Nyon","score":null,"coordinate":{"type":"WGS84","x":46.384411,"y":6.23597},"distance":null},"arrival":"2016-07-15T16:24:00+0200","arrivalTimestamp":1468592640,"departure":"2016-07-15T16:25:00+0200","departureTimestamp":1468592700,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501030","name":"Nyon","score":null,"coordinate":{"type":"WGS84","x":46.384411,"y":6.23597},"distance":null}},{"station":{"id":"8501023","name":"Coppet","score":null,"coordinate":{"type":"WGS84","x":46.317378,"y":6.187833},"distance":null},"arrival":"2016-07-15T16:30:00+0200","arrivalTimestamp":1468593000,"departure":"2016-07-15T16:31:00+0200","departureTimestamp":1468593060,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501023","name":"Coppet","score":null,"coordinate":{"type":"WGS84","x":46.317378,"y":6.187833},"distance":null}},{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:41:00+0200","arrivalTimestamp":1468593660,"departure":null,"departureTimestamp":null,"delay":null,"platform":"","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}],"capacity1st":1,"capacity2nd":2},"walk":null,"departure":{"station":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2016-07-15T15:51:00+0200","departureTimestamp":1468590660,"delay":null,"platform":"9","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":1,"capacity2nd":2},"realtimeAvailability":"RT_BHF","location":{"id":"8501120","name":"Lausanne","score":null,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}},"arrival":{"station":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"arrival":"2016-07-15T16:41:00+0200","arrivalTimestamp":1468593660,"departure":null,"departureTimestamp":null,"delay":null,"platform":"3","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":"RT_BHF","location":{"id":"8501008","name":"Gen\u00e8ve","score":null,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}}}]}],"from":{"id":"008501120","name":"Lausanne","score":101,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null},"to":{"id":"008501008","name":"Gen\u00e8ve","score":101,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null},"stations":{"from":[{"id":"008501120","name":"Lausanne","score":101,"coordinate":{"type":"WGS84","x":46.516777,"y":6.629095},"distance":null}],"to":[{"id":"008501008","name":"Gen\u00e8ve","score":101,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}]}}
@@ -0,0 +1 @@
1
+ {"stations":[{"id":"008501008","name":"Gen\u00e8ve","score":101,"coordinate":{"type":"WGS84","x":46.2102,"y":6.142455},"distance":null}]}
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/test'
3
+ require 'minitest/pride'
4
+
5
+ require 'webmock/minitest'
6
+
7
+ require 'transprt'
8
+
data/transprt.gemspec CHANGED
@@ -3,11 +3,11 @@ lib = File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "transprt"
6
- gem.version = '0.1.3'
6
+ gem.version = '0.2.1'
7
7
  gem.authors = ["ghn"]
8
8
  gem.email = ["ghugon@gmail.com"]
9
- gem.description = %q{Use the Swiss public transport API (open data).}
10
- gem.summary = "Swiss public transport."
9
+ gem.description = %q{Ruby client for the Swiss public transport API}
10
+ gem.summary = "Swiss public transport API"
11
11
  gem.homepage = 'https://github.com/ghn/transprt'
12
12
  gem.license = "MIT"
13
13
 
@@ -16,6 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
18
 
19
- gem.add_dependency('rest-client', '~> 1.6.7')
20
- gem.add_dependency('json', '~> 1.8.0')
19
+ gem.add_dependency('rest-client', '>=1.6.7', '<2.1.0')
20
+ gem.add_dependency('json', '>= 1.8.0')
21
+ gem.add_development_dependency('minitest', '~> 5.8.4')
22
+ gem.add_development_dependency('webmock', '~> 2.1.0')
21
23
  end
24
+
metadata CHANGED
@@ -1,55 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transprt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ghn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-29 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.6.7
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.6.7
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: json
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ~>
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: 1.8.0
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ~>
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: 1.8.0
41
- description: Use the Swiss public transport API (open data).
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 5.8.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 5.8.4
61
+ - !ruby/object:Gem::Dependency
62
+ name: webmock
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 2.1.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 2.1.0
75
+ description: Ruby client for the Swiss public transport API
42
76
  email:
43
77
  - ghugon@gmail.com
44
78
  executables: []
45
79
  extensions: []
46
80
  extra_rdoc_files: []
47
81
  files:
48
- - .gitignore
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - Gemfile.lock
49
85
  - LICENSE
50
86
  - README.md
87
+ - Rakefile
51
88
  - example.rb
52
89
  - lib/transprt.rb
90
+ - test/client_test.rb
91
+ - test/responses/client_test_test_connections.json
92
+ - test/responses/client_test_test_locations.json
93
+ - test/test_helper.rb
53
94
  - transprt.gemspec
54
95
  homepage: https://github.com/ghn/transprt
55
96
  licenses:
@@ -61,18 +102,22 @@ require_paths:
61
102
  - lib
62
103
  required_ruby_version: !ruby/object:Gem::Requirement
63
104
  requirements:
64
- - - '>='
105
+ - - ">="
65
106
  - !ruby/object:Gem::Version
66
107
  version: '0'
67
108
  required_rubygems_version: !ruby/object:Gem::Requirement
68
109
  requirements:
69
- - - '>='
110
+ - - ">="
70
111
  - !ruby/object:Gem::Version
71
112
  version: '0'
72
113
  requirements: []
73
114
  rubyforge_project:
74
- rubygems_version: 2.1.11
115
+ rubygems_version: 2.4.5.1
75
116
  signing_key:
76
117
  specification_version: 4
77
- summary: Swiss public transport.
78
- test_files: []
118
+ summary: Swiss public transport API
119
+ test_files:
120
+ - test/client_test.rb
121
+ - test/responses/client_test_test_connections.json
122
+ - test/responses/client_test_test_locations.json
123
+ - test/test_helper.rb