transport-opendata 0.8.2 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e23c345fa314c42131c8df416d56daf3dba9e53b
4
- data.tar.gz: 9d27cceeac918eaffcb2ebd8da5d70f6f191db7c
3
+ metadata.gz: 477321930cf1cd7bb8a640345b83c9cd01ef910e
4
+ data.tar.gz: e0b0a35fcd22b4948a1b3d076e59f997252f3fb0
5
5
  SHA512:
6
- metadata.gz: 6f39b76d4a53fbbcce470fc92896fe4da70a65502778fcebee421229d65c22e0c13a46be9ea7b48ffcb70423c4708c660f7d1cdf3ed7d45d09cbf5920800a456
7
- data.tar.gz: 34a2fa0d4426cfe0d6eb1f665a9ce3a81d3524f69816d97facdecd3aa77fb80609ece124373b3849a14d21b3ab6b76c49196495d47433437e7f4c1b812cc783d
6
+ metadata.gz: bb3314474a91b5104a96fb44a43bd25dce790b277d81b9976e558d5e2392c39e4654997cad6dc45528838bf6a91e261866006d9337a790745a94f0d556950d87
7
+ data.tar.gz: b206b3794dcd8f6326ded9f6cfae6ea05334b0d1a61d2733e034b5998d31fb1ae692d28ecb9c73b5022c678f0d0dd098ce451486134a35d6dff4fa82094bd5c5
@@ -1,22 +1,23 @@
1
- #
2
- # Checkpoint
3
- #
4
-
5
- require_relative 'location'
6
- require_relative 'prognosis'
7
-
8
- module Transport
9
- class Checkpoint
10
- attr_reader :station, :arrival, :departure, :platform, :prognosis
11
-
12
- def initialize(checkpoint)
13
- return unless checkpoint
14
-
15
- @station = Location.new checkpoint['station']
16
- @arrival = DateTime.parse(checkpoint['arrival']) if checkpoint['arrival']
17
- @departure = DateTime.parse(checkpoint['departure']) if checkpoint['departure']
18
- @platform = checkpoint['platform']
19
- @prognosis = Prognosis.new checkpoint['prognosis']
20
- end
21
- end
22
- end
1
+ #
2
+ # Checkpoint
3
+ #
4
+
5
+ require_relative 'station'
6
+ require_relative 'prognosis'
7
+
8
+ module Transport
9
+ class Checkpoint
10
+ attr_reader :station, :arrival, :departure, :platform, :prognosis
11
+
12
+ def initialize(checkpoint)
13
+ return unless checkpoint
14
+
15
+ @station = Station.new checkpoint['station']
16
+ @arrival = DateTime.parse(checkpoint['arrival']) if checkpoint['arrival']
17
+ @departure = DateTime.parse(checkpoint['departure']) if checkpoint['departure']
18
+ @delay = checkpoint['delay'].to_i if checkpoint['delay']
19
+ @platform = checkpoint['platform']
20
+ @prognosis = Prognosis.new checkpoint['prognosis']
21
+ end
22
+ end
23
+ end
@@ -1,25 +1,25 @@
1
- #
2
- # Connection
3
- #
4
-
5
- require_relative 'checkpoint'
6
- require_relative 'service'
7
- require_relative 'section'
8
- require_relative 'duration'
9
-
10
- module Transport
11
- class Connection
12
- attr_reader :from, :to, :duration, :service, :products, :capacity1st, :capacity2nd, :sections
13
-
14
- def initialize(connection)
15
- @from = Checkpoint.new connection['from']
16
- @to = Checkpoint.new connection['to']
17
- @duration = Duration.new connection['duration']
18
- @service = Service.new connection['service']
19
- @products = connection['products']
20
- @capacity1st = connection['capacity1st']
21
- @capacity2nd = connection['capacity2nd']
22
- @sections = connection['sections'].map { |section| Section .new section }
23
- end
24
- end
1
+ #
2
+ # Connection
3
+ #
4
+
5
+ require_relative 'checkpoint'
6
+ require_relative 'service'
7
+ require_relative 'section'
8
+ require_relative 'duration'
9
+
10
+ module Transport
11
+ class Connection
12
+ attr_reader :from, :to, :duration, :service, :products, :capacity1st, :capacity2nd, :sections
13
+
14
+ def initialize(connection)
15
+ @from = Checkpoint.new connection['from']
16
+ @to = Checkpoint.new connection['to']
17
+ @duration = Duration.new connection['duration']
18
+ @service = Service.new connection['service']
19
+ @products = connection['products']
20
+ @capacity1st = connection['capacity1st']
21
+ @capacity2nd = connection['capacity2nd']
22
+ @sections = connection['sections'].map { |section| Section .new section }
23
+ end
24
+ end
25
25
  end
@@ -1,15 +1,15 @@
1
- #
2
- # Coordinate
3
- #
4
-
5
- module Transport
6
- class Coordinate
7
- attr_reader :type, :x, :y
8
-
9
- def initialize(coordinate)
10
- @type = coordinate['type'].to_sym
11
- @x = coordinate['x']
12
- @y = coordinate['y']
13
- end
14
- end
1
+ #
2
+ # Coordinate
3
+ #
4
+
5
+ module Transport
6
+ class Coordinate
7
+ attr_reader :type, :x, :y
8
+
9
+ def initialize(coordinate)
10
+ @type = coordinate['type'].to_sym
11
+ @x = coordinate['x']
12
+ @y = coordinate['y']
13
+ end
14
+ end
15
15
  end
@@ -1,24 +1,24 @@
1
- #
2
- # Duration
3
- #
4
-
5
- module Transport
6
- class Duration
7
- attr_reader :seconds, :minutes, :hours, :days
8
-
9
- def initialize(duration)
10
- @days, @hours, @minutes, @seconds = duration.split(/d|:/)
11
- @seconds = @seconds.to_i
12
- @minutes = @minutes.to_i
13
- @hours = @hours.to_i
14
- @days = @days.to_i
15
- end
16
-
17
- def to_s
18
- result = ""
19
- result += "#{@days}d" if @days > 0
20
- result += "#{@hours}h" if @hours > 0 || @days > 0
21
- result += "#{@minutes}m"
22
- end
23
- end
1
+ #
2
+ # Duration
3
+ #
4
+
5
+ module Transport
6
+ class Duration
7
+ attr_reader :seconds, :minutes, :hours, :days
8
+
9
+ def initialize(duration)
10
+ @days, @hours, @minutes, @seconds = duration.split(/d|:/)
11
+ @seconds = @seconds.to_i
12
+ @minutes = @minutes.to_i
13
+ @hours = @hours.to_i
14
+ @days = @days.to_i
15
+ end
16
+
17
+ def to_s
18
+ result = ""
19
+ result += "#{@days}d" if @days > 0
20
+ result += "#{@hours}h" if @hours > 0 || @days > 0
21
+ result += "#{@minutes}m"
22
+ end
23
+ end
24
24
  end
@@ -1,13 +1,13 @@
1
- #
2
- # Error
3
- #
4
-
5
- module Transport
6
- class Error
7
- attr_reader :message
8
-
9
- def initialize(error)
10
- @message = error['message']
11
- end
12
- end
1
+ #
2
+ # Error
3
+ #
4
+
5
+ module Transport
6
+ class Error
7
+ attr_reader :message
8
+
9
+ def initialize(error)
10
+ @message = error['message']
11
+ end
12
+ end
13
13
  end
@@ -1,26 +1,27 @@
1
- #
2
- # Journey
3
- #
4
-
5
- require_relative 'checkpoint'
6
-
7
- module Transport
8
- class Journey
9
- attr_reader :stop, :name, :category, :categoryCode, :number, :operator, :to, :passList, :capacity1st, :capacity2nd
10
-
11
- def initialize(journey)
12
- return unless journey
13
-
14
- @stop = Checkpoint.new journey['stop']
15
- @name = journey['name']
16
- @category = journey['category']
17
- @categoryCode = journey['categoryCode']
18
- @number = journey['number'].to_i
19
- @operator = journey['operator']
20
- @to = journey['to']
21
- @passList = journey['passList'].map { |checkpoint| Checkpoint.new checkpoint }
22
- @capacity1st = journey['capacity1st']
23
- @capacity2nd = journey['capacity2nd']
24
- end
25
- end
26
- end
1
+ #
2
+ # Journey
3
+ #
4
+
5
+ require_relative 'stop'
6
+
7
+ module Transport
8
+ class Journey
9
+ attr_reader :stop, :name, :category, :categoryCode, :number, :operator, :to, :passList, :capacity1st, :capacity2nd
10
+
11
+ def initialize(journey)
12
+ return unless journey
13
+
14
+ @stop = Stop.new journey['stop']
15
+ @name = journey['name']
16
+ @category = journey['category']
17
+ @subcategory = journey['subcategory']
18
+ @categoryCode = journey['categoryCode']
19
+ @number = journey['number'].to_i
20
+ @operator = journey['operator']
21
+ @to = journey['to']
22
+ @passList = journey['passList'].map { |checkpoint| Checkpoint.new checkpoint }
23
+ @capacity1st = journey['capacity1st']
24
+ @capacity2nd = journey['capacity2nd']
25
+ end
26
+ end
27
+ end
@@ -1,19 +1,19 @@
1
- #
2
- # Prognosis
3
- #
4
-
5
- module Transport
6
- class Prognosis
7
- attr_reader :platform, :departure, :arrival, :capacity1st, :capacity2nd
8
-
9
- def initialize(prognosis)
10
- return unless prognosis
11
-
12
- @platform = prognosis['platform']
13
- @departure = DateTime.parse prognosis['departure'] if prognosis['departure']
14
- @arrival = DateTime.parse prognosis['arrival'] if prognosis['arrival']
15
- @capacity1st = prognosis['capacity1st']
16
- @capacity2nd = prognosis['capacity2nd']
17
- end
18
- end
1
+ #
2
+ # Prognosis
3
+ #
4
+
5
+ module Transport
6
+ class Prognosis
7
+ attr_reader :platform, :departure, :arrival, :capacity1st, :capacity2nd
8
+
9
+ def initialize(prognosis)
10
+ return unless prognosis
11
+
12
+ @platform = prognosis['platform']
13
+ @departure = DateTime.parse prognosis['departure'] if prognosis['departure']
14
+ @arrival = DateTime.parse prognosis['arrival'] if prognosis['arrival']
15
+ @capacity1st = prognosis['capacity1st']
16
+ @capacity2nd = prognosis['capacity2nd']
17
+ end
18
+ end
19
19
  end
@@ -1,16 +1,16 @@
1
- #
2
- # Section
3
- #
4
-
5
- module Transport
6
- class Section
7
- attr_reader :journey, :walk, :departure, :arrival
8
-
9
- def initialize(section)
10
- @journey = Journey.new section['journey']
11
- @walk = section['walk']
12
- @departure = Checkpoint.new section['departure']
13
- @arrival = Checkpoint.new section['arrival']
14
- end
15
- end
1
+ #
2
+ # Section
3
+ #
4
+
5
+ module Transport
6
+ class Section
7
+ attr_reader :journey, :walk, :departure, :arrival
8
+
9
+ def initialize(section)
10
+ @journey = Journey.new section['journey']
11
+ @walk = section['walk']
12
+ @departure = Checkpoint.new section['departure']
13
+ @arrival = Checkpoint.new section['arrival']
14
+ end
15
+ end
16
16
  end
@@ -1,14 +1,14 @@
1
- #
2
- # Service
3
- #
4
-
5
- module Transport
6
- class Service
7
- attr_reader :regular, :irregular
8
-
9
- def initialize(service)
10
- @regular = service['regular']
11
- @irregular = service['irregular']
12
- end
13
- end
1
+ #
2
+ # Service
3
+ #
4
+
5
+ module Transport
6
+ class Service
7
+ attr_reader :regular, :irregular
8
+
9
+ def initialize(service)
10
+ @regular = service['regular']
11
+ @irregular = service['irregular']
12
+ end
13
+ end
14
14
  end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Station
3
+ #
4
+
5
+ require_relative 'coordinate'
6
+
7
+ module Transport
8
+ class Station
9
+ attr_reader :id, :type, :name, :score, :coordinate, :distance
10
+
11
+ def initialize(station)
12
+ @id = station['id']
13
+ @name = station['name']
14
+ @score = station['score']
15
+ @coordinate = Coordinate.new station['coordinate']
16
+ @distance = station['distance']
17
+ @type = station['type']
18
+ end
19
+ end
20
+ end
@@ -1,20 +1,21 @@
1
- #
2
- # Stop
3
- #
4
-
5
- module Transport
6
- class Stop
7
- attr_reader :station, :name, :category, :number, :operator, :to
8
-
9
- def initialize(stop)
10
- return unless stop
11
-
12
- @station = Location.new stop['station']
13
- @name = stop['name']
14
- @category = stop['category']
15
- @number = stop['number']
16
- @operator = stop['operator']
17
- @to = stop['to']
18
- end
19
- end
20
- end
1
+ #
2
+ # Stop
3
+ #
4
+
5
+ module Transport
6
+ class Stop
7
+ attr_reader :station, :arrival, :departure, :delay, :realtimeAvailability
8
+
9
+ def initialize(stop)
10
+ return unless stop
11
+
12
+ @station = Station.new stop['station']
13
+ @arrival = DateTime.parse stop['arrival'] if stop['arrival']
14
+ @departure = DateTime.parse stop['departure'] if stop['departure']
15
+ @delay = stop['delay'].to_i if stop['delay']
16
+ @platform = stop['platform'] if stop['platform']
17
+ @prognosis = Prognosis.new stop['prognosis']
18
+ @realtimeAvailability = stop['realtimeAvailability']
19
+ end
20
+ end
21
+ end
@@ -1,50 +1,55 @@
1
- #
2
- # Locations
3
- #
4
-
5
- require 'httparty'
6
- require_relative 'transport_factory'
7
-
8
- module Transport
9
- class Timetable
10
- include HTTParty
11
-
12
- attr_accessor :parse
13
-
14
- base_uri 'transport.opendata.ch'
15
-
16
- # default_params :output => 'json'
17
-
18
- def initialize
19
- @version = 'v1'
20
- @parse = true
21
- @options = { query: { } }
22
- end
23
-
24
- def search_station station_partial
25
- parse_filter(self.class.get(restful_url('locations'), @options.merge(query: { query: station_partial})))
26
- end
27
-
28
- def search_connection from, to
29
- parse_filter(self.class.get(restful_url('connections'), @options.merge(query: { from: from, to: to})))
30
- end
31
-
32
- def board_for station
33
- parse_filter(self.class.get(restful_url('stationboard'), @options.merge(query: { station: station, limit: 15})))
34
- end
35
-
36
- private
37
- def restful_url page
38
- "/#{@version}/#{page}"
39
- end
40
-
41
- def parse_filter unparsed_result
42
- if @parse
43
- TransportFactory::create(unparsed_result)
44
- else
45
- unparsed_result
46
- end
47
- end
48
-
49
- end
50
- end
1
+ #
2
+ # Locations
3
+ #
4
+
5
+ require 'httparty'
6
+ require_relative 'transport_factory'
7
+
8
+ module Transport
9
+ class Timetable
10
+ include HTTParty
11
+
12
+ attr_accessor :parse
13
+
14
+ base_uri 'transport.opendata.ch'
15
+
16
+ # default_params :output => 'json'
17
+
18
+ def initialize
19
+ @version = 'v1'
20
+ @parse = true
21
+ @options = { query: { } }
22
+ end
23
+
24
+ def search_station station_partial
25
+ request 'locations', query: { query: station_partial }
26
+ end
27
+
28
+ def search_connection from, to
29
+ request 'connections', query: { from: from, to: to}
30
+ end
31
+
32
+ def board_for station, limit=15
33
+ request 'stationboard', query: { station: station, limit: limit}
34
+ end
35
+
36
+
37
+ private
38
+ def restful_url page
39
+ "/#{@version}/#{page}"
40
+ end
41
+
42
+ def request resource, options
43
+ parse_filter(self.class.get(restful_url(resource), @options.merge(options)), resource)
44
+ end
45
+
46
+ def parse_filter unparsed_result, resource
47
+ if @parse
48
+ TransportFactory::create(unparsed_result, resource)
49
+ else
50
+ unparsed_result
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
- #
2
- # Transport Opendata
3
- #
4
-
1
+ #
2
+ # Transport Opendata
3
+ #
4
+
5
5
  require_relative 'timetable'
@@ -1,41 +1,36 @@
1
- #
2
- # Transport Factory
3
- #
4
-
5
- require 'httparty'
6
- require_relative 'location'
7
- require_relative 'connection'
8
- require_relative 'journey'
9
- require_relative 'error'
10
-
11
- module Transport
12
- class TransportFactory
13
-
14
- def self.create(json)
15
- json.each do |type, data|
16
- case type
17
- when 'stations'
18
- return data.map do |station|
19
- Location.new station
20
- end
21
- when 'connections'
22
- return data.map do |connection|
23
- Connection.new connection
24
- end
25
- when 'station'
26
- next
27
- when 'stationboard'
28
- return data.map do |journey|
29
- Journey.new journey
30
- end
31
- when 'errors'
32
- return data.map do |error|
33
- Error.new error
34
- end
35
- else
36
- raise ArgumentError.new('Unknown Type: ' + type)
37
- end
38
- end
39
- end
40
- end
41
- end
1
+ #
2
+ # Transport Factory
3
+ #
4
+
5
+ require 'httparty'
6
+ require_relative 'station'
7
+ require_relative 'connection'
8
+ require_relative 'journey'
9
+ require_relative 'error'
10
+
11
+ module Transport
12
+ class TransportFactory
13
+ def self.create(json, resource)
14
+ if json['errors']
15
+ return Error.new json
16
+ else
17
+ case resource
18
+ when 'locations'
19
+ return json['stations'].map do |station|
20
+ Station.new station
21
+ end
22
+ when 'connections'
23
+ return json[resource].map do |connection|
24
+ Connection.new connection
25
+ end
26
+ when 'stationboard'
27
+ return json[resource].map do |journey|
28
+ Journey.new journey
29
+ end
30
+ else
31
+ raise ArgumentError.new('Unknown Resource: ', resource)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transport-opendata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Bruderer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-03 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -36,10 +36,10 @@ files:
36
36
  - lib/duration.rb
37
37
  - lib/error.rb
38
38
  - lib/journey.rb
39
- - lib/location.rb
40
39
  - lib/prognosis.rb
41
40
  - lib/section.rb
42
41
  - lib/service.rb
42
+ - lib/station.rb
43
43
  - lib/stop.rb
44
44
  - lib/timetable.rb
45
45
  - lib/transport-opendata.rb
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.4.8
67
+ rubygems_version: 2.6.10
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Swiss Public Transport API
@@ -1,20 +0,0 @@
1
- #
2
- # Locations
3
- #
4
-
5
- require_relative 'coordinate'
6
-
7
- module Transport
8
- class Location
9
- attr_reader :id, :type, :name, :score, :coordinate, :distance
10
-
11
- def initialize(location)
12
- @id = location['id']
13
- @type = location['type']
14
- @name = location['name']
15
- @score = location['score']
16
- @coordinate = Coordinate.new location['coordinate']
17
- @distance = location['distance']
18
- end
19
- end
20
- end