gtfs-data_exchange 0.0.3 → 0.0.4
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/README.md +1 -1
- data/gtfs-data_exchange.gemspec +3 -3
- data/lib/gtfs/data_exchange/api.rb +5 -3
- data/lib/gtfs/data_exchange/version.rb +2 -2
- data/spec/gtfs/data_exchange/api_spec.rb +76 -32
- metadata +23 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5c8c207369e2006b67aaa5a4ad763b17be6a9cc
|
4
|
+
data.tar.gz: 94c8912e7e27bf859b66d317f0abe2f1d1c58e8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 548d27b395e952ea8ed8f385ff91306ff0f335b977ed30a481104d4dc42cd2c47548c8b234c1714cb9c569a6bdcfc8f05a968485ef458676b38cd8e029454140
|
7
|
+
data.tar.gz: 75c72df06f4350c2270b3f95474d430f4f757369d2c2d4f7296b4163b80aac607a24a3ffedce6e75b11ea633f890d30e79ea83fa52889c09df26d8fbd593409e
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ By default, this will return a Ruby `Hash` object.
|
|
46
46
|
|
47
47
|
## Contributing
|
48
48
|
|
49
|
-
1. Fork it ( https://github.com/
|
49
|
+
1. Fork it ( https://github.com/data-creative/gtfs-data_exchange/fork )
|
50
50
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
51
|
3. Test your changes (optional, but encouraged `rspec spec/`)
|
52
52
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
data/gtfs-data_exchange.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = GTFS::DataExchange::VERSION
|
9
9
|
spec.authors = ["MJ Rossetti (@s2t2)"]
|
10
10
|
spec.email = ["s2t2mail@gmail.com"]
|
11
|
-
spec.summary = %q{A ruby wrapper for the gtfs-data-exchange.com api
|
12
|
-
spec.description = %q{A ruby wrapper for the gtfs-data-exchange.com api
|
13
|
-
spec.homepage = "https://github.com/
|
11
|
+
spec.summary = %q{A ruby wrapper for the gtfs-data-exchange.com api.}
|
12
|
+
spec.description = %q{A ruby wrapper for the gtfs-data-exchange.com api. List all agencies, or find a specific agency by its data exchange identifier.}
|
13
|
+
spec.homepage = "https://github.com/data-creative/gtfs-data-exchange-api-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -29,7 +29,8 @@ module GTFS
|
|
29
29
|
when "json"
|
30
30
|
raise ResponseCodeError unless response["status_code"] == 200
|
31
31
|
raise ResponseDataError unless response["data"]
|
32
|
-
|
32
|
+
parsed_response_data = response["data"].map{|a| Hash[a.map{|k,v| [k.to_sym, (v == "" ? nil : v)]}]}
|
33
|
+
return parsed_response_data
|
33
34
|
when "csv"
|
34
35
|
raise ResponseCodeError unless response.code == 200
|
35
36
|
raise ResponseDataError unless response.body
|
@@ -48,12 +49,13 @@ module GTFS
|
|
48
49
|
|
49
50
|
request_url = "#{BASE_URL}/agency?agency=#{dataexchange_id}"
|
50
51
|
response = HTTParty.get(request_url)
|
51
|
-
|
52
52
|
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"
|
53
53
|
raise ResponseCodeError unless response["status_code"] == 200
|
54
54
|
raise ResponseDataError unless response["data"]
|
55
55
|
raise ResponseAgencyError unless response["data"]["agency"]
|
56
|
-
|
56
|
+
|
57
|
+
parsed_agency_data = Hash[response["data"]["agency"].map{|k,v| [k.to_sym, (v == "" ? nil : v)]}]
|
58
|
+
return parsed_agency_data
|
57
59
|
end
|
58
60
|
|
59
61
|
# Exception raised if the service does not recognize the requested *dataexchange_id*.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GTFS
|
2
2
|
module DataExchange
|
3
3
|
|
4
|
-
# The current gem version. Reference the releases list (https://github.com/
|
5
|
-
VERSION = "0.0.
|
4
|
+
# The current gem version. Reference the releases list (https://github.com/data-creative/gtfs-data-exchange-api-ruby/releases) for previous releases.
|
5
|
+
VERSION = "0.0.4"
|
6
6
|
end
|
7
7
|
end
|
@@ -1,45 +1,89 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
module GTFS
|
5
4
|
module DataExchange
|
6
5
|
describe API do
|
6
|
+
describe "#agencies endpoint" do
|
7
|
+
it 'lists all agencies' do
|
8
|
+
agencies_response = [
|
9
|
+
{
|
10
|
+
"date_last_updated"=>1354248333.0,
|
11
|
+
"feed_baseurl"=>"",
|
12
|
+
"name"=>"A. Reich GmbH Busbetrieb",
|
13
|
+
"area"=>"",
|
14
|
+
"url"=>"http://www.vbb.de",
|
15
|
+
"country"=>"",
|
16
|
+
"state"=>"",
|
17
|
+
"license_url"=>"",
|
18
|
+
"dataexchange_url"=>"http://www.gtfs-data-exchange.com/agency/a-reich-gmbh-busbetrieb/",
|
19
|
+
"date_added"=>1354248333.0,
|
20
|
+
"is_official"=>false,
|
21
|
+
"dataexchange_id"=>"a-reich-gmbh-busbetrieb"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"date_last_updated"=>1417658131.0,
|
25
|
+
"feed_baseurl"=>"http://data.cabq.gov/transit/gtfs/google_transit.zip",
|
26
|
+
"name"=>"ABQ Ride",
|
27
|
+
"area"=>"Albuquerque",
|
28
|
+
"url"=>"http://myabqride.com",
|
29
|
+
"country"=>"United States",
|
30
|
+
"state"=>"New Mexico",
|
31
|
+
"license_url"=>"",
|
32
|
+
"dataexchange_url"=>"http://www.gtfs-data-exchange.com/agency/abq-ride/",
|
33
|
+
"date_added"=>1340739867.0,
|
34
|
+
"is_official"=>true,
|
35
|
+
"dataexchange_id"=>"abq-ride"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
parsed_agencies_response = agencies_response.map{|a| Hash[a.map{|k,v| [k.to_sym, (v == "" ? nil : v)]}]}
|
39
|
+
expect(parsed_agencies_response).to be_kind_of(Array)
|
40
|
+
expect(parsed_agencies_response.first).to be_kind_of(Hash)
|
41
|
+
expect(parsed_agencies_response.first[:dataexchange_id]).to be_kind_of(String)
|
42
|
+
expect(parsed_agencies_response.first[:feed_baseurl]).to be(nil)
|
43
|
+
end
|
7
44
|
|
8
|
-
|
45
|
+
it 'lists all agencies in CSV format' do
|
46
|
+
agencies = GTFS::DataExchange::API.agencies(:format => "csv")
|
47
|
+
expect(agencies).to be_kind_of(String)
|
48
|
+
csv_result = CSV.parse(agencies, :headers => true)
|
49
|
+
expect(csv_result.headers).to include("dataexchange_id")
|
50
|
+
expect(csv_result.first).to be_kind_of(CSV::Row)
|
51
|
+
expect(csv_result.first.to_hash["dataexchange_id"]).to be_kind_of(String)
|
52
|
+
end
|
9
53
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
expect(agencies.first["dataexchange_id"]).to be_kind_of(String)
|
54
|
+
it 'explains why it is unable to return agencies data in an unsupported format' do
|
55
|
+
unsupported_format = "sql"
|
56
|
+
expect{ GTFS::DataExchange::API.agencies(:format => unsupported_format) }.to raise_error
|
57
|
+
end
|
15
58
|
end
|
16
59
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
60
|
+
describe '#agency endpoint' do
|
61
|
+
it 'finds a specific agency by its data exchange identifier' do
|
62
|
+
requested_identifier = "metro-north-railroad"
|
63
|
+
agency_response = {
|
64
|
+
"date_last_updated"=>1394241933.0,
|
65
|
+
"feed_baseurl"=>"http://www.mta.info/developers/",
|
66
|
+
"name"=>"Metro North Railroad",
|
67
|
+
"area"=>"",
|
68
|
+
"url"=>" http://www.mta.info/mnr/index.html",
|
69
|
+
"country"=>"United States",
|
70
|
+
"state"=>"New York",
|
71
|
+
"license_url"=>"",
|
72
|
+
"dataexchange_url"=>"http://www.gtfs-data-exchange.com/agency/metro-north-railroad/",
|
73
|
+
"date_added"=>1263414635.0,
|
74
|
+
"is_official"=>true,
|
75
|
+
"dataexchange_id"=>"metro-north-railroad"
|
76
|
+
}
|
77
|
+
parsed_agency_response = Hash[agency_response.map{|k,v| [k.to_sym, (v == "" ? nil : v)]}]
|
78
|
+
expect(parsed_agency_response).to be_kind_of(Hash)
|
79
|
+
expect(parsed_agency_response[:dataexchange_id]).to eql(requested_identifier)
|
80
|
+
expect(parsed_agency_response[:area]).to be(nil)
|
81
|
+
end
|
39
82
|
|
40
|
-
|
41
|
-
|
42
|
-
|
83
|
+
it 'explains why it is unable to find an unrecognized agency' do
|
84
|
+
unrecognized_identifier = "my-railroad"
|
85
|
+
expect{ GTFS::DataExchange::API.agency(:dataexchange_id => unrecognized_identifier) }.to raise_error
|
86
|
+
end
|
43
87
|
end
|
44
88
|
end
|
45
89
|
end
|
metadata
CHANGED
@@ -1,106 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtfs-data_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- MJ Rossetti (@s2t2)
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.7'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.7'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '10.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '10.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pry
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0.10'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0.10'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '3.1'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '3.1'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: httparty
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0.13'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0.13'
|
94
|
-
description: A ruby wrapper for the gtfs-data-exchange.com api
|
95
|
-
|
83
|
+
description: A ruby wrapper for the gtfs-data-exchange.com api. List all agencies,
|
84
|
+
or find a specific agency by its data exchange identifier.
|
96
85
|
email:
|
97
86
|
- s2t2mail@gmail.com
|
98
87
|
executables: []
|
99
88
|
extensions: []
|
100
89
|
extra_rdoc_files: []
|
101
90
|
files:
|
102
|
-
- .gitignore
|
103
|
-
- .rspec
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
104
93
|
- Gemfile
|
105
94
|
- LICENSE.txt
|
106
95
|
- README.md
|
@@ -112,32 +101,30 @@ files:
|
|
112
101
|
- lib/gtfs/data_exchange/version.rb
|
113
102
|
- spec/gtfs/data_exchange/api_spec.rb
|
114
103
|
- spec/spec_helper.rb
|
115
|
-
homepage: https://github.com/
|
104
|
+
homepage: https://github.com/data-creative/gtfs-data-exchange-api-ruby
|
116
105
|
licenses:
|
117
106
|
- MIT
|
107
|
+
metadata: {}
|
118
108
|
post_install_message:
|
119
109
|
rdoc_options: []
|
120
110
|
require_paths:
|
121
111
|
- lib
|
122
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
113
|
requirements:
|
125
|
-
- -
|
114
|
+
- - ">="
|
126
115
|
- !ruby/object:Gem::Version
|
127
116
|
version: '0'
|
128
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
118
|
requirements:
|
131
|
-
- -
|
119
|
+
- - ">="
|
132
120
|
- !ruby/object:Gem::Version
|
133
121
|
version: '0'
|
134
122
|
requirements: []
|
135
123
|
rubyforge_project:
|
136
|
-
rubygems_version:
|
124
|
+
rubygems_version: 2.2.2
|
137
125
|
signing_key:
|
138
|
-
specification_version:
|
139
|
-
summary: A ruby wrapper for the gtfs-data-exchange.com api
|
126
|
+
specification_version: 4
|
127
|
+
summary: A ruby wrapper for the gtfs-data-exchange.com api.
|
140
128
|
test_files:
|
141
129
|
- spec/gtfs/data_exchange/api_spec.rb
|
142
130
|
- spec/spec_helper.rb
|
143
|
-
has_rdoc:
|