connexionz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.gemtest +0 -0
- data/.gitignore +41 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.yardopts +3 -0
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.md +77 -0
- data/Rakefile +18 -0
- data/connexionz.gemspec +34 -0
- data/lib/connexionz.rb +22 -0
- data/lib/connexionz/client.rb +86 -0
- data/lib/connexionz/client/connection.rb +23 -0
- data/lib/connexionz/client/request.rb +18 -0
- data/lib/connexionz/configuration.rb +44 -0
- data/lib/connexionz/version.rb +3 -0
- data/spec/connexionz/client_spec.rb +56 -0
- data/spec/connexionz_spec.rb +20 -0
- data/spec/fixtures/platform.xml +2281 -0
- data/spec/helper.rb +6 -0
- metadata +241 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'autotest/bundler'
|
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Copyright (c) 2011, Connexionz
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
8
|
+
* Neither the name of Code for America nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Connexionz API
|
2
|
+
|
3
|
+
Ruby wrapper for the Connexionz API
|
4
|
+
|
5
|
+
Installation
|
6
|
+
------------
|
7
|
+
gem install connexionz
|
8
|
+
|
9
|
+
Documentation
|
10
|
+
-------------
|
11
|
+
[http://rdoc.info/gems/connexionz](http://rdoc.info/gems/connexionz)
|
12
|
+
|
13
|
+
Continuous Integration
|
14
|
+
----------------------
|
15
|
+
[![Build Status](http://travis-ci.org/ryanatwork/connexionz.png)](http://travis-ci.org/ryanatwork/connexionz)
|
16
|
+
|
17
|
+
Usage Examples
|
18
|
+
--------------
|
19
|
+
require 'connexionz'
|
20
|
+
|
21
|
+
@client = Connexionz::Client.new({:endpoint => "http://businfo.santa-clarita.com/"})
|
22
|
+
@client.platform # Returns all the platforms
|
23
|
+
a = @client.route_position_et({:platformno => "16890"})
|
24
|
+
a = route_position_et.platform.name # Returns "McBean Pky & Valencia Blvd"
|
25
|
+
|
26
|
+
Contributing
|
27
|
+
------------
|
28
|
+
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
|
29
|
+
|
30
|
+
Here are some ways *you* can contribute:
|
31
|
+
|
32
|
+
* by using alpha, beta, and prerelease versions
|
33
|
+
* by reporting bugs
|
34
|
+
* by suggesting new features
|
35
|
+
* by writing or editing documentation
|
36
|
+
* by writing specifications
|
37
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
38
|
+
* by refactoring code
|
39
|
+
* by resolving [issues](https://github.com/ryanatwork/connexionz/issues)
|
40
|
+
* by reviewing patches
|
41
|
+
|
42
|
+
|
43
|
+
Submitting an Issue
|
44
|
+
-------------------
|
45
|
+
We use the [GitHub issue tracker](https://github.com/ryanatwork/connexionz/issues)
|
46
|
+
to track bugs and features. Before submitting a bug report or feature request,
|
47
|
+
check to make sure it hasn't already been submitted. You can indicate support
|
48
|
+
for an existing issuse by voting it up. When submitting a bug report, please
|
49
|
+
include a [Gist](https://gist.github.com/) that includes a stack trace and any
|
50
|
+
details that may be necessary to reproduce the bug, including your gem version,
|
51
|
+
Ruby version, and operating system. Ideally, a bug report should include a pull
|
52
|
+
request with failing specs.
|
53
|
+
|
54
|
+
Submitting a Pull Request
|
55
|
+
-------------------------
|
56
|
+
1. Fork the project.
|
57
|
+
2. Create a topic branch.
|
58
|
+
3. Implement your feature or bug fix.
|
59
|
+
4. Add documentation for your feature or bug fix.
|
60
|
+
5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
|
61
|
+
6. Add specs for your feature or bug fix.
|
62
|
+
7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
|
63
|
+
8. Commit and push your changes.
|
64
|
+
9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
65
|
+
|
66
|
+
Credits
|
67
|
+
-------
|
68
|
+
[Connexionz](http://www.connexionz.co.nz/)
|
69
|
+
|
70
|
+
Inspiration
|
71
|
+
-----------
|
72
|
+
Connexionz was heavily inspired by the [https://github.com/codeforamerica/gem_template](Code for America Gem Template)
|
73
|
+
|
74
|
+
Copyright
|
75
|
+
---------
|
76
|
+
Copyright (c) 2011 Ryan Resella
|
77
|
+
See [LICENSE](https://github.com/ryanatwork/connexionz/blob/master/LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
task :test => :spec
|
11
|
+
|
12
|
+
require 'yard'
|
13
|
+
namespace :doc do
|
14
|
+
YARD::Rake::YardocTask.new do |task|
|
15
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
16
|
+
task.options = ['--markup', 'markdown']
|
17
|
+
end
|
18
|
+
end
|
data/connexionz.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/connexionz/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'connexionz'
|
6
|
+
gem.version = Connexionz::VERSION
|
7
|
+
gem.author = "Ryan Resella"
|
8
|
+
gem.email = 'ryan@codeforamerica.org'
|
9
|
+
gem.homepage = 'https://github.com/ryanatwork/connexionz/'
|
10
|
+
gem.summary = gem.description
|
11
|
+
gem.description = %q{A Ruby wrapper for the Connexionz bus api}
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_development_dependency 'ZenTest', '~> 4.5'
|
19
|
+
gem.add_development_dependency 'maruku', '~> 0.6'
|
20
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
22
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
23
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
24
|
+
gem.add_development_dependency 'webmock', '~> 1.6'
|
25
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
26
|
+
|
27
|
+
gem.add_runtime_dependency 'faraday', '~> 0.6.1'
|
28
|
+
gem.add_runtime_dependency 'faraday_middleware', '~> 0.6.3'
|
29
|
+
gem.add_runtime_dependency 'hashie', '~> 1.0.0'
|
30
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.0.2'
|
31
|
+
gem.add_runtime_dependency 'multi_xml', '~> 0.2.2'
|
32
|
+
gem.add_runtime_dependency 'patron', '~> 0.4.11'
|
33
|
+
gem.add_runtime_dependency 'rash', '~> 0.3.0'
|
34
|
+
end
|
data/lib/connexionz.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'connexionz/configuration'
|
2
|
+
require 'connexionz/client'
|
3
|
+
|
4
|
+
module Connexionz
|
5
|
+
extend Configuration
|
6
|
+
# Alias for Connexionz::Client.new
|
7
|
+
#
|
8
|
+
# @return [Connexionz::Client]
|
9
|
+
def self.client(options={})
|
10
|
+
Connexionz::Client.new(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Delegate to Connexionz::Client
|
14
|
+
def self.method_missing(method, *args, &block)
|
15
|
+
return super unless new.respond_to?(method)
|
16
|
+
client.send(method, *args, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.respond_to?(method, include_private=false)
|
20
|
+
client.respond_to?(method, include_private) || super(method, include_private)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'connexionz/client/connection'
|
2
|
+
require 'connexionz/client/request'
|
3
|
+
|
4
|
+
module Connexionz
|
5
|
+
class Client
|
6
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
options = Connexionz.options.merge(options)
|
10
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
11
|
+
send("#{key}=", options[key])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
include Connexionz::Client::Connection
|
16
|
+
include Connexionz::Client::Request
|
17
|
+
|
18
|
+
# Returns all platform locations (WGS84), Id’s & names.
|
19
|
+
#
|
20
|
+
# @param options [Hash] A customizable set of options.
|
21
|
+
# @return {Hash}
|
22
|
+
# @example
|
23
|
+
# Connexionz.platform
|
24
|
+
def platform(options={})
|
25
|
+
get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=Platform.xml", options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns details platform groups where a number of platforms are grouped together under a common name. Use PlatformTag to link to the platform locations in the above.
|
29
|
+
#
|
30
|
+
# @param options [Hash] A customizable set of options.
|
31
|
+
# @return {Hash}
|
32
|
+
# @example
|
33
|
+
# Connexionz.platform_group
|
34
|
+
def platform_group(options={})
|
35
|
+
get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=PlatformGroup.xml", options)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Route patterns, details all the route patterns (described in the MapInfo MIB/MIF CDATA entities) in the system & the associated platforms. Use PlatformTag to link to the platform locations.
|
39
|
+
#
|
40
|
+
# @param options [Hash] A customizable set of options.
|
41
|
+
# @return {Hash}
|
42
|
+
# @example
|
43
|
+
# Connexionz.route_pattern
|
44
|
+
#def route_pattern(options={})
|
45
|
+
# get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=RoutePattern.rxml", options)
|
46
|
+
#end
|
47
|
+
|
48
|
+
# Provide ETA predictions for an individual platform or platform group.Use PlatformTag (internal key to a platform) or PlatformNo (number physically attached to a bus stop which may change from time to time) arguments.
|
49
|
+
#
|
50
|
+
# @param options [Hash] A customizable set of options.
|
51
|
+
# @param options PlatformNo [String] The number posted on the bus stop
|
52
|
+
# @param options PlatformTag [String] The ID of the bus stop
|
53
|
+
# @return {Hash}
|
54
|
+
# @example
|
55
|
+
# Connexionz.route_position_et
|
56
|
+
# Connexionz.route_position_et({:PlatformNo =>"19812"})
|
57
|
+
# Connexionz.route_position_et({:PlatformTag =>"428"})
|
58
|
+
def route_position_et(options={})
|
59
|
+
get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=RoutePositionET.xml", options)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the master list of schedules
|
63
|
+
#
|
64
|
+
# @param options [Hash] A customizable set of options.
|
65
|
+
# @return {Hash}
|
66
|
+
# @example
|
67
|
+
# Connexionz.schedule_master
|
68
|
+
def schedule_master(options={})
|
69
|
+
get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=ScheduleMaster.xml", options)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the schedule detail for the route.
|
73
|
+
#
|
74
|
+
# @param servicename [String] Weekday, Saturday, Sunday
|
75
|
+
# @param options [Hash] A customizable set of options.
|
76
|
+
# @param options id [String] The ID of the route number
|
77
|
+
# @return {Hash}
|
78
|
+
# @example
|
79
|
+
# Connexionz.schedule_detail("Weekday")
|
80
|
+
# Connexionz.schedule_detail("Weekday", {:id =>"1"})
|
81
|
+
def schedule_detail(servicename, options={})
|
82
|
+
get("rtt/public/utility/file.aspx?contenttype=SQLXML&Name=ScheduleDetail.xml&ServiceName=#{servicename}", options)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module Connexionz
|
4
|
+
class Client
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
|
8
|
+
def connection(raw=false)
|
9
|
+
options = {
|
10
|
+
:url => endpoint
|
11
|
+
}
|
12
|
+
|
13
|
+
Faraday.new(options) do |connection|
|
14
|
+
connection.use Faraday::Request::UrlEncoded
|
15
|
+
connection.use Faraday::Response::RaiseError
|
16
|
+
connection.use Faraday::Response::Rashify
|
17
|
+
connection.use Faraday::Response::ParseXml
|
18
|
+
connection.adapter (adapter)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Connexionz
|
2
|
+
class Client
|
3
|
+
module Request
|
4
|
+
def get(path, options={})
|
5
|
+
request(:get, path, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def request(method, path, options)
|
11
|
+
response = connection.send(method) do |request|
|
12
|
+
request.url(path, options)
|
13
|
+
end
|
14
|
+
response.body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'connexionz/version'
|
3
|
+
|
4
|
+
module Connexionz
|
5
|
+
module Configuration
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:adapter,
|
8
|
+
:endpoint,
|
9
|
+
:format,
|
10
|
+
:proxy,
|
11
|
+
:user_agent].freeze
|
12
|
+
|
13
|
+
VALID_FORMATS = [
|
14
|
+
:xml].freeze
|
15
|
+
|
16
|
+
DEFAULT_ADAPTER = :patron #Faraday.default_adapter
|
17
|
+
DEFAULT_ENDPOINT = nil
|
18
|
+
DEFAULT_FORMAT = :xml
|
19
|
+
DEFAULT_PROXY = nil
|
20
|
+
DEFAULT_USER_AGENT = "Connexionz Ruby Gem #{Connexionz::VERSION}".freeze
|
21
|
+
|
22
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
23
|
+
|
24
|
+
def self.extended(base)
|
25
|
+
base.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure
|
29
|
+
yield self
|
30
|
+
end
|
31
|
+
|
32
|
+
def options
|
33
|
+
VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def reset
|
37
|
+
self.adapter = DEFAULT_ADAPTER
|
38
|
+
self.endpoint = DEFAULT_ENDPOINT
|
39
|
+
self.format = DEFAULT_FORMAT
|
40
|
+
self.proxy = DEFAULT_PROXY
|
41
|
+
self.user_agent = DEFAULT_USER_AGENT
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Connexionz::Client do
|
4
|
+
describe ".new" do
|
5
|
+
it "should return a Connexionz::Client" do
|
6
|
+
Connexionz::Client.new.should be_a Connexionz::Client
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
@client = Connexionz::Client.new({:endpoint => "http://businfo.santa-clarita.com/"})
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#platform" do
|
15
|
+
it "should return a list of all the platforms" do
|
16
|
+
test = @client.platform
|
17
|
+
test.platforms.platform[1].platform_no.should == "12412"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#platform_group" do
|
22
|
+
it "should return a list of all the platforms" do
|
23
|
+
test = @client.platform_group
|
24
|
+
test.platform_groups.platform_group[1].name.should == "Ave Stanford & Rye Cyn"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#describe "#route_pattern" do
|
29
|
+
# it "should return all the route patterns" do
|
30
|
+
# test = @client.route_pattern
|
31
|
+
# test.routepattern.project.route.destination_name = "Ave Stanford & Rye Cyn"
|
32
|
+
# end
|
33
|
+
#end
|
34
|
+
|
35
|
+
describe "#route_position_et" do
|
36
|
+
it "should return the ET for the current bus stop" do
|
37
|
+
test = @client.route_position_et({:platformno => "16890"})
|
38
|
+
test.route_position_et.platform.name.should == "McBean Pky & Valencia Blvd"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#schedule_master" do
|
43
|
+
it "should return the master schedule list" do
|
44
|
+
test = @client.schedule_master
|
45
|
+
test.schedule_master.project.schedule.route[0].name.should == "Whites Cyn/Castaic"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#schedule_detail" do
|
50
|
+
it "should return the schedule detail for the correct route id" do
|
51
|
+
test = @client.schedule_detail("Weekday",{:id => "1"})
|
52
|
+
test.schedule_detail.route.destination_group.name.should == "Castaic to Whites Cyn"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|