gtfs-data_exchange 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gtfs-data_exchange.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 MJ Rossetti (@s2t2)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # GTFS::DataExchange
2
+
3
+ A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api). Exposes `agency` and `agencies` endpoints.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gtfs-data_exchange'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gtfs-data_exchange
20
+
21
+ ## Usage
22
+
23
+ ### Agencies
24
+
25
+ List all agencies.
26
+
27
+ ```` rb
28
+ agencies = GTFS::DataExchange::API.agencies
29
+ ````
30
+
31
+ Response data is returned in JSON format by default. To return data in CSV format instead, pass the `:format` option ...
32
+
33
+ ```` rb
34
+ agencies = GTFS::DataExchange::API.agencies(:format => "csv")
35
+ ````
36
+
37
+ ### Agency
38
+
39
+ Find an agency by its `dataexchange_id`.
40
+
41
+ ```` rb
42
+ agency = GTFS::DataExchange::API.agency(:dataexchange_id => "shore-line-east")
43
+ ````
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/databyday/gtfs-data_exchange/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gtfs/data_exchange/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gtfs-data_exchange"
8
+ spec.version = GTFS::DataExchange::VERSION
9
+ spec.authors = ["MJ Rossetti (@s2t2)"]
10
+ spec.email = ["s2t2mail@gmail.com"]
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{Exposes the `agencies` and `agency` endpoints.}
13
+ spec.homepage = "https://github.com/databyday/gtfs-data_exchange"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "pry", "~> 0.10"
24
+ spec.add_dependency "httparty", "~> 0.13"
25
+ end
@@ -0,0 +1,45 @@
1
+ module GTFS
2
+ module DataExchange
3
+ class API
4
+ URL = "http://www.gtfs-data-exchange.com/api"
5
+
6
+ def self.agencies(options = {})
7
+ format = options[:format] || "json"
8
+ raise RequestFormatError(format) unless ["json","csv"].include?(format)
9
+
10
+ request_url = "#{URL}/agencies?format=#{format}"
11
+ response = HTTParty.get(request_url)
12
+ case format
13
+ when "json"
14
+ raise ResponseCodeError unless response["status_code"] == 200
15
+ raise ResponseDataError unless response["data"]
16
+ return response["data"]
17
+ when "csv"
18
+ raise ResponseCodeError unless response.code == 200
19
+ raise ResponseDataError unless response.body
20
+ return response.body
21
+ end
22
+ end
23
+
24
+ def self.agency(options = {})
25
+ dataexchange_id = options[:dataexchange_id] || options[:data_exchange_id] || "shore-line-east"
26
+
27
+ request_url = "#{URL}/agency?agency=#{dataexchange_id}"
28
+ response = HTTParty.get(request_url)
29
+ raise RequestDataExchangeIdError(dataexchange_id) if response["status_code"] == 404 && response["status_txt"] == "AGENCY_NOT_FOUND"
30
+ raise ResponseCodeError unless response["status_code"] == 200
31
+ raise ResponseDataError unless response["data"]
32
+ raise ResponseAgencyError unless response["data"]["agency"]
33
+
34
+ return response["data"]["agency"]
35
+ end
36
+
37
+ class RequestDataExchangeIdError < ArgumentError ; end
38
+ class RequestFormatError < ArgumentError ; end
39
+
40
+ class ResponseAgencyError < StandardError ; end
41
+ class ResponseCodeError < StandardError ; end
42
+ class ResponseDataError < StandardError ; end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module GTFS
2
+ module DataExchange
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'httparty'
2
+
3
+ module GTFS
4
+ module DataExchange
5
+ end
6
+ end
7
+
8
+ require "gtfs/data_exchange/version"
9
+ require "gtfs/data_exchange/api"
data/lib/gtfs.rb ADDED
@@ -0,0 +1,4 @@
1
+ module GTFS
2
+ end
3
+
4
+ require 'gtfs/data_exchange'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gtfs-data_exchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - MJ Rossetti (@s2t2)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: httparty
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.13'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.13'
78
+ description: Exposes the `agencies` and `agency` endpoints.
79
+ email:
80
+ - s2t2mail@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - gtfs-data_exchange.gemspec
91
+ - lib/gtfs.rb
92
+ - lib/gtfs/data_exchange.rb
93
+ - lib/gtfs/data_exchange/api.rb
94
+ - lib/gtfs/data_exchange/version.rb
95
+ homepage: https://github.com/databyday/gtfs-data_exchange
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.23
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: A ruby wrapper for the [gtfs-data-exchange.com api](http://www.gtfs-data-exchange.com/api).
120
+ test_files: []