gtfs-data_exchange 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/gtfs-data_exchange.gemspec +2 -2
- data/lib/gtfs/data_exchange/api.rb +41 -9
- data/lib/gtfs/data_exchange/version.rb +3 -1
- data/lib/gtfs/data_exchange.rb +0 -2
- metadata +6 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# GTFS::DataExchange
|
2
2
|
|
3
|
-
A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api).
|
3
|
+
A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api). List all agencies, or find a specific agency by its `dataexchange_id`.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -28,7 +28,7 @@ List all agencies.
|
|
28
28
|
agencies = GTFS::DataExchange::API.agencies
|
29
29
|
````
|
30
30
|
|
31
|
-
|
31
|
+
By default, this will return an `Array` of Ruby `Hash` objects. Pass the 'csv' format option to return a CSV `String` instead.
|
32
32
|
|
33
33
|
```` rb
|
34
34
|
agencies = GTFS::DataExchange::API.agencies(:format => "csv")
|
@@ -42,6 +42,8 @@ Find an agency by its `dataexchange_id`.
|
|
42
42
|
agency = GTFS::DataExchange::API.agency(:dataexchange_id => "shore-line-east")
|
43
43
|
````
|
44
44
|
|
45
|
+
By default, this will return a Ruby `Hash` object.
|
46
|
+
|
45
47
|
## Contributing
|
46
48
|
|
47
49
|
1. Fork it ( https://github.com/databyday/gtfs-data_exchange/fork )
|
data/gtfs-data_exchange.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["MJ Rossetti (@s2t2)"]
|
10
10
|
spec.email = ["s2t2mail@gmail.com"]
|
11
11
|
spec.summary = %q{A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api).}
|
12
|
-
spec.description = %q{
|
13
|
-
spec.homepage = "https://github.com/databyday/gtfs-
|
12
|
+
spec.description = %q{A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api). List all agencies, or find a specific agency by its `dataexchange_id`.}
|
13
|
+
spec.homepage = "https://github.com/databyday/gtfs-data-exchange-api-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -1,14 +1,32 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
# Top-level namespace referencing the [General Transit Feed Specification](https://developers.google.com/transit/gtfs/).
|
1
4
|
module GTFS
|
5
|
+
|
6
|
+
# Namespace referencing the [data exchange](http://www.gtfs-data-exchange.com/),
|
7
|
+
# a third-party site "designed to help developers and transit agencies efficiently share and retrieve GTFS data."
|
2
8
|
module DataExchange
|
9
|
+
|
10
|
+
# Contains all data exchange api methods and exceptions.
|
3
11
|
class API
|
4
|
-
URL = "http://www.gtfs-data-exchange.com/api"
|
5
12
|
|
13
|
+
# The base url for api endpoints.
|
14
|
+
# This page also acts as the primary source for api reference documentation.
|
15
|
+
BASE_URL = "http://www.gtfs-data-exchange.com/api"
|
16
|
+
|
17
|
+
# List all agencies.
|
18
|
+
# @param [Hash] options the request options.
|
19
|
+
# @option options [String] :format ('json') the requested data format.
|
20
|
+
# @raise [UnsupportedRequestFormat] if the request format is not supported by the service.
|
21
|
+
# @raise [ResponseCodeError, ResponseDataError] for unexpected responses.
|
22
|
+
# @return [Array, String] the agencies data in the requested format.
|
6
23
|
def self.agencies(options = {})
|
7
24
|
format = options[:format] || "json"
|
8
|
-
raise
|
25
|
+
raise UnsupportedRequestFormat, "The requested data format, '#{format}', is not supported by the service. Try 'csv' or 'json' instead." unless ["json","csv"].include?(format)
|
9
26
|
|
10
|
-
request_url = "#{
|
27
|
+
request_url = "#{BASE_URL}/agencies?format=#{format}"
|
11
28
|
response = HTTParty.get(request_url)
|
29
|
+
|
12
30
|
case format
|
13
31
|
when "json"
|
14
32
|
raise ResponseCodeError unless response["status_code"] == 200
|
@@ -21,25 +39,39 @@ module GTFS
|
|
21
39
|
end
|
22
40
|
end
|
23
41
|
|
42
|
+
# Find an agency by its `dataexchange_id`.
|
43
|
+
# @param [Hash] options the request options.
|
44
|
+
# @option options [String] :dataexchange_id ('shore-line-east') the requested data format.
|
45
|
+
# @raise [UnrecognizedDataExchangeId] if the requested agency identifier is unrecognized by the service.
|
46
|
+
# @raise [ResponseCodeError, ResponseDataError, ResponseAgencyError] for unexpected responses.
|
47
|
+
# @return [Hash] the agency data.
|
24
48
|
def self.agency(options = {})
|
25
49
|
dataexchange_id = options[:dataexchange_id] || options[:data_exchange_id] || "shore-line-east"
|
26
50
|
|
27
|
-
request_url = "#{
|
51
|
+
request_url = "#{BASE_URL}/agency?agency=#{dataexchange_id}"
|
28
52
|
response = HTTParty.get(request_url)
|
29
|
-
|
53
|
+
|
54
|
+
raise UnrecognizedDataExchangeId, "The requested dataexchange_id, '#{dataexchange_id}', was not recognized by the service." if response["status_code"] == 404 && response["status_txt"] == "AGENCY_NOT_FOUND"
|
30
55
|
raise ResponseCodeError unless response["status_code"] == 200
|
31
56
|
raise ResponseDataError unless response["data"]
|
32
57
|
raise ResponseAgencyError unless response["data"]["agency"]
|
33
|
-
|
34
58
|
return response["data"]["agency"]
|
35
59
|
end
|
36
60
|
|
37
|
-
|
38
|
-
class
|
61
|
+
# Exception raised if the service does not recognize the requested *dataexchange_id*.
|
62
|
+
class UnrecognizedDataExchangeId < ArgumentError ; end
|
39
63
|
|
40
|
-
|
64
|
+
# Exception raised if the service does not support the requested data format.
|
65
|
+
class UnsupportedRequestFormat < ArgumentError ; end
|
66
|
+
|
67
|
+
# Exception raised if the service returns an unexpected response code.
|
41
68
|
class ResponseCodeError < StandardError ; end
|
69
|
+
|
70
|
+
# Exception raised if the service returns unexpected or missing response data.
|
42
71
|
class ResponseDataError < StandardError ; end
|
72
|
+
|
73
|
+
# Exception raised if the service returns unexpected or missing agency data.
|
74
|
+
class ResponseAgencyError < StandardError ; end
|
43
75
|
end
|
44
76
|
end
|
45
77
|
end
|
data/lib/gtfs/data_exchange.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtfs-data_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,7 +75,8 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0.13'
|
78
|
-
description:
|
78
|
+
description: A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api).
|
79
|
+
List all agencies, or find a specific agency by its `dataexchange_id`.
|
79
80
|
email:
|
80
81
|
- s2t2mail@gmail.com
|
81
82
|
executables: []
|
@@ -92,7 +93,7 @@ files:
|
|
92
93
|
- lib/gtfs/data_exchange.rb
|
93
94
|
- lib/gtfs/data_exchange/api.rb
|
94
95
|
- lib/gtfs/data_exchange/version.rb
|
95
|
-
homepage: https://github.com/databyday/gtfs-
|
96
|
+
homepage: https://github.com/databyday/gtfs-data-exchange-api-ruby
|
96
97
|
licenses:
|
97
98
|
- MIT
|
98
99
|
post_install_message:
|
@@ -118,3 +119,4 @@ signing_key:
|
|
118
119
|
specification_version: 3
|
119
120
|
summary: A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api).
|
120
121
|
test_files: []
|
122
|
+
has_rdoc:
|