actransit_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +2 -0
- data/actransit_rails.gemspec +35 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/actransit_rails.rb +87 -0
- data/lib/actransit_rails/version.rb +3 -0
- data/tasks/rspec.rake +3 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad1f9e6df558a900e021aa1baf9ebc46922be315
|
4
|
+
data.tar.gz: 6321e8df8df27364c171dfe85c738d0ee162f735
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb3af51e723d196d3891751d0ce2e1e736d1638d618ceae353766353f530c0301acf4e7a1413148a3718ccb996bbaaa7db41d19a4290a10aaa93173e313f4399
|
7
|
+
data.tar.gz: 3f8f4731a44ca1b996556802d10e498eea3313fbd77012a99d8f40e0d7e6631695bcefbb4e3dc824599eb033a9555c676c6691cdde617b9310b10a73a8cc05f1
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sanjay Y Patel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# ActransitRails
|
2
|
+
|
3
|
+
A gem for accessing the ACTransit API in Rails.
|
4
|
+
|
5
|
+
Checkout the ACTransit [Documentation](http://api.actransit.org/transit/) for more info.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'actransit_rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install actransit_rails
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
1. Make sure you [register an application](http://api.actransit.org/transit/Account/Register) with ACTransit to get your access token.
|
26
|
+
|
27
|
+
2. I'd recommend using a gem like [figaro](https://github.com/laserlemon/figaro) to safely store your ACTransit access token as an environment variable.
|
28
|
+
|
29
|
+
3. In controller that will make requests to the ACTransit api, be sure to call configure with your token as an argument.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# If you're using figaro, it would look like
|
33
|
+
ACTransitRails.configure(ENV['ACTRANSIT_TOKEN'])
|
34
|
+
|
35
|
+
# You coud also just pass it as a string, though I don't recommend that
|
36
|
+
ACTransitRails.configure("myactransittoken")
|
37
|
+
```
|
38
|
+
|
39
|
+
4. Once configured, you can use the helper methods to make requests from the api. Responses will be formatted as either a hash or an array of hashes depending on what you request.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# returns array of hashes
|
43
|
+
ACTransitRails.get_all_routes
|
44
|
+
# => [{"RouteId":"1","Name":"1","Description":"Bayfair Bart- Dtn. Berkeley"},...]
|
45
|
+
|
46
|
+
|
47
|
+
# returns hash
|
48
|
+
ACTransitRails.get_route('E')
|
49
|
+
# => {"RouteId":"E","Name":"E","Description":"San Francisco - Claremont -Parkwood"}
|
50
|
+
|
51
|
+
# returns array of hashes
|
52
|
+
ACTransitRails.get_trips('E')
|
53
|
+
# => [{"TripId":4119214,"RouteName":"E","ScheduleType":0,"StartTime":"2000-01-01T06:05:00","Direction":"Eastbound"},...]
|
54
|
+
|
55
|
+
# returns array of strings
|
56
|
+
ACTransitRails.get_directions('E')
|
57
|
+
# => ["Eastbound","Westbound"]
|
58
|
+
|
59
|
+
# returns array of hashes
|
60
|
+
ACTransitRails.get_stops('E')
|
61
|
+
ACTransitRails.get_stops('E', 4119214)
|
62
|
+
# => [{"StopId":58070,"Name":"Claremont Av:Hudson St","Latitude":37.8431470,"Longitude":-122.2571661,"ScheduledTime":null},...]
|
63
|
+
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Make sure to setup a spec/support/secrets.rb file (see secrets_example.rb) with your token so that you can securely test.
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/actransit_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'actransit_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "actransit_rails"
|
8
|
+
spec.version = ACTransitRails::VERSION
|
9
|
+
spec.authors = ["Sanjay Y Patel"]
|
10
|
+
spec.email = ["sanjay.y.patel@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A gem for accessing the ACTransit API in Rails.}
|
13
|
+
spec.description = %q{Simplified access to the Bay Area's ACTransit API - details at http://api.actransit.org/transit/}
|
14
|
+
spec.homepage = "https://github.com/sanjayypatel/actransit_rails.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'json'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "actransit_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require "actransit_rails/version"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module ACTransitRails
|
5
|
+
|
6
|
+
attr_writer :actransit_token
|
7
|
+
|
8
|
+
def self.configure(actransit_token)
|
9
|
+
@actransit_token = actransit_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_all_routes
|
13
|
+
uri = URI.parse(
|
14
|
+
base_url +
|
15
|
+
"routes/" +
|
16
|
+
search_string +
|
17
|
+
my_token
|
18
|
+
)
|
19
|
+
return get_response(uri)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_route(route_name)
|
23
|
+
uri = URI.parse(
|
24
|
+
base_url +
|
25
|
+
"route/" +
|
26
|
+
"#{route_name}/" +
|
27
|
+
search_string +
|
28
|
+
my_token
|
29
|
+
)
|
30
|
+
return get_response(uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.get_trips(route_name)
|
34
|
+
uri = URI.parse(
|
35
|
+
base_url +
|
36
|
+
"route/" +
|
37
|
+
"#{route_name}/trips/" +
|
38
|
+
search_string +
|
39
|
+
my_token
|
40
|
+
)
|
41
|
+
return get_response(uri)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_directions(route_name)
|
45
|
+
uri = URI.parse(
|
46
|
+
base_url +
|
47
|
+
"route/" +
|
48
|
+
"#{route_name}/directions/" +
|
49
|
+
search_string +
|
50
|
+
my_token
|
51
|
+
)
|
52
|
+
return get_response(uri)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_stops(route_name, trip = nil)
|
56
|
+
trip ||= get_trips(route_name)[0]["TripId"]
|
57
|
+
uri = URI.parse(
|
58
|
+
base_url +
|
59
|
+
"route/" +
|
60
|
+
"#{route_name}/trip/" +
|
61
|
+
"#{trip}/stops/" +
|
62
|
+
search_string +
|
63
|
+
my_token
|
64
|
+
)
|
65
|
+
return get_response(uri)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def self.base_url
|
71
|
+
return "http://api.actransit.org/transit/"
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.search_string
|
75
|
+
"?"
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.my_token
|
79
|
+
return "token=" + @actransit_token
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.get_response(uri)
|
83
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
84
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
85
|
+
return JSON.parse response.body
|
86
|
+
end
|
87
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actransit_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sanjay Y Patel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Simplified access to the Bay Area's ACTransit API - details at http://api.actransit.org/transit/
|
70
|
+
email:
|
71
|
+
- sanjay.y.patel@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".DS_Store"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- actransit_rails.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/actransit_rails.rb
|
88
|
+
- lib/actransit_rails/version.rb
|
89
|
+
- tasks/rspec.rake
|
90
|
+
homepage: https://github.com/sanjayypatel/actransit_rails.git
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.6
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: A gem for accessing the ACTransit API in Rails.
|
114
|
+
test_files: []
|