tripspark_api 0.0.0 → 0.1.1
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 +4 -4
- data/lib/tripspark_api.rb +32 -0
- data/lib/tripspark_api/api.rb +52 -0
- data/lib/tripspark_api/client.rb +17 -0
- data/lib/tripspark_api/client/patterns.rb +25 -0
- data/lib/tripspark_api/client/routes.rb +31 -0
- data/lib/tripspark_api/client/vehicles.rb +66 -0
- data/lib/tripspark_api/configuration.rb +41 -0
- data/lib/tripspark_api/connection.rb +23 -0
- data/lib/tripspark_api/connection_adapters/httparty_adapter.rb +27 -0
- data/lib/tripspark_api/core_ext/string.rb +21 -0
- data/lib/tripspark_api/models.rb +92 -0
- data/lib/tripspark_api/models/direction.rb +21 -0
- data/lib/tripspark_api/models/gps.rb +25 -0
- data/lib/tripspark_api/models/pattern.rb +41 -0
- data/lib/tripspark_api/models/pattern_point.rb +35 -0
- data/lib/tripspark_api/models/route.rb +24 -0
- data/lib/tripspark_api/models/stop.rb +40 -0
- data/lib/tripspark_api/models/vehicle.rb +52 -0
- data/lib/tripspark_api/version.rb +1 -1
- metadata +49 -4
- data/lib/tripspark.rb +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce1db8d390b3759ead6003e38195fdc40245a746
|
|
4
|
+
data.tar.gz: c76c01fd63b9db6042640dfda5b426ebbf957a70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3837c3875c6d8f56b4109754ca747583b0b4a8e03a750440f474ceff9caaa68d6e640c16b3ab84da5d69f6045066f67986b6c832958e7db827c751fa115c88dc
|
|
7
|
+
data.tar.gz: 0b4a78bc31fb43b1bfa2b22bc5eff2f96e15d9ba27b0646d5b894054574c95dc56f4c32713a27a909ce8f1f179e61a7a0c6ebf98d3d6441cbd63c11b38541aa9
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative 'tripspark_api/core_ext/string'
|
|
2
|
+
|
|
3
|
+
require_relative 'tripspark_api/version'
|
|
4
|
+
require_relative 'tripspark_api/configuration'
|
|
5
|
+
require_relative 'tripspark_api/connection'
|
|
6
|
+
require_relative 'tripspark_api/models'
|
|
7
|
+
require_relative 'tripspark_api/api'
|
|
8
|
+
require_relative 'tripspark_api/client'
|
|
9
|
+
|
|
10
|
+
module TripSpark
|
|
11
|
+
class << self
|
|
12
|
+
# Alias for `TripSpark::Client.new`
|
|
13
|
+
def new
|
|
14
|
+
Client.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The current client configuration
|
|
18
|
+
def configuration
|
|
19
|
+
@configuration ||= Configuration.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Allow users to set configuration options via a block. By default, the
|
|
23
|
+
# configuration will be validated after the block returns. This will raise
|
|
24
|
+
# an exception if any required configurations are not provided. This
|
|
25
|
+
# behavior can be skipped by passing `validate: false` as a parameter.
|
|
26
|
+
def configure validate: true
|
|
27
|
+
yield configuration
|
|
28
|
+
configuration.validate! if validate
|
|
29
|
+
configuration
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'memoist'
|
|
2
|
+
|
|
3
|
+
module TripSpark
|
|
4
|
+
# A base class implementing common API operations
|
|
5
|
+
class API
|
|
6
|
+
include Connection
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
extend Memoist
|
|
10
|
+
|
|
11
|
+
# Include another API's functionality via a new method on this API.
|
|
12
|
+
# For example, `include_api :routes` would include the "Routes" API into
|
|
13
|
+
# the "Client" API, accessible as `Client#routes`.
|
|
14
|
+
def include_api name
|
|
15
|
+
klass = self.const_get(name.to_s.constantize)
|
|
16
|
+
define_method(name) do
|
|
17
|
+
klass.new
|
|
18
|
+
end
|
|
19
|
+
self.memoize name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Require all the files given in `names` that exist in the given folder
|
|
23
|
+
def require_all folder, *libs
|
|
24
|
+
libs.each do |lib|
|
|
25
|
+
require_relative "#{File.join(folder, lib)}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Return a singleton instance of this API
|
|
30
|
+
def singleton
|
|
31
|
+
@singleton ||= self.new
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Perform a GET request over the connection to the given endpoint.
|
|
37
|
+
def get_request endpoint, opts={}, &block
|
|
38
|
+
connection.get endpoint, opts, &block
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Perform a POST request over the connection to the given endpoint.
|
|
42
|
+
def post_request endpoint, opts={}, &block
|
|
43
|
+
connection.post endpoint, opts, &block
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# For APIs that extend Memoist, allow the user to call `refresh` as an
|
|
47
|
+
# alias for `flush_cache`.
|
|
48
|
+
def refresh
|
|
49
|
+
send(:flush_cache) if respond_to?(:flush_cache)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Client::Patterns < API
|
|
3
|
+
extend Memoist
|
|
4
|
+
|
|
5
|
+
# Return a list of all patterns belonging to the given route. Currently,
|
|
6
|
+
# there is no direct way to retrieve all patterns for all routes.
|
|
7
|
+
def list route_key
|
|
8
|
+
params = {
|
|
9
|
+
body: {
|
|
10
|
+
routeKey: route_key
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
post_request('/RouteMap/GetPatternPoints/', params).map{ |pattern| Pattern.new(pattern) }
|
|
14
|
+
end
|
|
15
|
+
memoize :list
|
|
16
|
+
alias_method :all, :list
|
|
17
|
+
|
|
18
|
+
# Return the route whose key matches the given key
|
|
19
|
+
def get key
|
|
20
|
+
list.find{ |pattern| pattern.key == key }
|
|
21
|
+
end
|
|
22
|
+
memoize :get
|
|
23
|
+
alias_method :find, :get
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Client::Routes < API
|
|
3
|
+
extend Memoist
|
|
4
|
+
|
|
5
|
+
# Return a list of all routes on the system.
|
|
6
|
+
def list
|
|
7
|
+
post_request('/RouteMap/GetRoutes/').map{ |route| Route.new(route) }
|
|
8
|
+
end
|
|
9
|
+
memoize :list
|
|
10
|
+
alias_method :all, :list
|
|
11
|
+
|
|
12
|
+
# Return the route whose key matches the given key
|
|
13
|
+
def get key
|
|
14
|
+
list.find{ |route| route.key == key }
|
|
15
|
+
end
|
|
16
|
+
memoize :get
|
|
17
|
+
alias_method :find, :get
|
|
18
|
+
|
|
19
|
+
# Return a list of pairs of route keys and direction keys. Used when
|
|
20
|
+
# requesting vehicles.
|
|
21
|
+
def route_direction_pairs *routes
|
|
22
|
+
list.each_with_object([]) do |route, pairs|
|
|
23
|
+
next unless routes.empty? or !routes.include?(route.key)
|
|
24
|
+
route.patterns.each do |pattern|
|
|
25
|
+
pairs << [route.key, pattern.direction.key]
|
|
26
|
+
end
|
|
27
|
+
end.uniq
|
|
28
|
+
end
|
|
29
|
+
memoize :route_direction_pairs
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Client::Vehicles < API
|
|
3
|
+
extend Memoist
|
|
4
|
+
|
|
5
|
+
# Return a Hash of Pattern objects to Vehicles on that pattern. If `routes`
|
|
6
|
+
# is provided (as an array of route keys), only vehicles on those routes
|
|
7
|
+
# will be included.
|
|
8
|
+
def by_pattern *routes
|
|
9
|
+
params = _route_direction_pair_params(routes)
|
|
10
|
+
routes = post_request('/RouteMap/GetVehicles/', body: params)
|
|
11
|
+
routes.each.with_object({}) do |route, patterns_hash|
|
|
12
|
+
route['VehiclesByPattern'].each do |pat|
|
|
13
|
+
pattern = Pattern.new(pat['Pattern'])
|
|
14
|
+
# Apparently, vehicles can go in multiple directions concurrently,
|
|
15
|
+
# even though that directly conflicts with the idea that vehicles
|
|
16
|
+
# belong to patterns and patterns have one direction.
|
|
17
|
+
# To avoid creating more Vehicle objects that necessary, first clear
|
|
18
|
+
# the Vehicles hash of any duplicates, then create the objects.
|
|
19
|
+
vehicles = pat['Vehicles'].uniq{ |vehicle| vehicle['Key'] }
|
|
20
|
+
patterns_hash[pattern] = vehicles.map{ |vehicle| Vehicle.new(vehicle) }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
memoize :by_pattern
|
|
25
|
+
|
|
26
|
+
# Return a list of all vehicles currently traveling on routes. If `routes`
|
|
27
|
+
# is provided (as an array of route keys), only vehicles on those routes
|
|
28
|
+
# will be included.
|
|
29
|
+
def list *routes
|
|
30
|
+
by_pattern(*routes).values.flatten
|
|
31
|
+
end
|
|
32
|
+
memoize :list
|
|
33
|
+
alias_method :all, :list
|
|
34
|
+
|
|
35
|
+
# Return a Hash of Route keys to Vehicles. If `route_keys` are given,
|
|
36
|
+
# only those Routes will be included
|
|
37
|
+
def by_route *route_keys
|
|
38
|
+
list(*route_keys).each.with_object({}) do |vehicle, route_hash|
|
|
39
|
+
(route_hash[vehicle.route.key] ||= []) << vehicle
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
memoize :by_route
|
|
43
|
+
|
|
44
|
+
# Return the vehicle whose key matches the given key
|
|
45
|
+
def get key
|
|
46
|
+
list.find{ |vehicle| vehicle.key == key }
|
|
47
|
+
end
|
|
48
|
+
memoize :get
|
|
49
|
+
alias_method :find, :get
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
# Return a parameter string suitable for supplying routeDirectionKeys to
|
|
54
|
+
# a call to /GetVehicles/. If rd_pairs is provided (as an array of route-
|
|
55
|
+
# direction_pairs), onlye those routes will be included.
|
|
56
|
+
def _route_direction_pair_params routes
|
|
57
|
+
# The information to populate `routeDirectionKeys` for a request is
|
|
58
|
+
# most easily found in `Client::Routes`, if it was not given directly.
|
|
59
|
+
rd_pairs = Client::Routes.singleton.route_direction_pairs(*routes)
|
|
60
|
+
rd_pairs.each.with_index.with_object([]) do |((route, dir), idx), params|
|
|
61
|
+
params << "routeDirectionKeys[#{idx}][routeKey]=#{route}"
|
|
62
|
+
params << "routeDirectionKeys[#{idx}][directionKey]=#{dir}"
|
|
63
|
+
end.join('&')
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Configuration
|
|
3
|
+
# The version of the TripSpark system
|
|
4
|
+
attr_accessor :version
|
|
5
|
+
# The base URL of the TripSpark system
|
|
6
|
+
attr_accessor :base_uri
|
|
7
|
+
# The adapter to use for network communication
|
|
8
|
+
attr_accessor :adapter
|
|
9
|
+
# The output stream to which debug information should be written
|
|
10
|
+
attr_accessor :debug_output
|
|
11
|
+
|
|
12
|
+
# The defaults to use for any configuration options that are not provided
|
|
13
|
+
DEFAULT_CONFIGURATION = {
|
|
14
|
+
version: '3.2', # Taken from a comment on "http://bus.gocitybus.com/RouteMap/Index"
|
|
15
|
+
adapter: :httparty,
|
|
16
|
+
debug_output: false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# The options required when configuring a TripSpark instance
|
|
20
|
+
REQUIRED_CONFIGURATION = [
|
|
21
|
+
:base_uri
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
# Apply the default set of configurations before anything else to ensure
|
|
26
|
+
# all options are initialized.
|
|
27
|
+
DEFAULT_CONFIGURATION.each do |name, value|
|
|
28
|
+
send("#{name}=", value)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Ensure that all required configurations have been given a value. Returns
|
|
33
|
+
# true if all required configuration options have been set.
|
|
34
|
+
def validate!
|
|
35
|
+
REQUIRED_CONFIGURATION.each do |name|
|
|
36
|
+
raise "`#{name}` is a required configuration option, but was not given a value." if send("#{name}").nil?
|
|
37
|
+
end
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
module Connection
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
# Return the connection adapter instance
|
|
6
|
+
def connection
|
|
7
|
+
@connection ||= adapter.new(TripSpark.configuration)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Return the class of the adapter to use for the connection
|
|
11
|
+
def adapter
|
|
12
|
+
@@adapters[TripSpark.configuration.adapter]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Register a new class that can be used as a connection adapter
|
|
16
|
+
def register_adapter name, klass
|
|
17
|
+
(@@adapters ||= {})[name] = klass
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Include the adapters that come packaged with the gem
|
|
23
|
+
require_relative 'connection_adapters/httparty_adapter.rb'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
# A Connection adapter using HTTParty as the network transport
|
|
5
|
+
module TripSpark
|
|
6
|
+
module Connection
|
|
7
|
+
class HTTPartyAdapter
|
|
8
|
+
include HTTParty
|
|
9
|
+
|
|
10
|
+
def initialize config
|
|
11
|
+
self.class.base_uri config.base_uri
|
|
12
|
+
# Write debug information to the configured output stream
|
|
13
|
+
self.class.debug_output config.debug_output
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get endpoint, opts={}, &block
|
|
17
|
+
JSON.parse(self.class.get(endpoint, opts, &block))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def post endpoint, opts={}, &block
|
|
21
|
+
JSON.parse(self.class.post(endpoint, opts, &block))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
register_adapter :httparty, HTTPartyAdapter
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def underscore
|
|
3
|
+
self.dup.underscore!
|
|
4
|
+
end unless method_defined? :underscore
|
|
5
|
+
|
|
6
|
+
def underscore!
|
|
7
|
+
self.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
|
8
|
+
self.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
|
9
|
+
self.tr_s!('- ', '_')
|
|
10
|
+
self.downcase!
|
|
11
|
+
self
|
|
12
|
+
end unless method_defined? :underscore!
|
|
13
|
+
|
|
14
|
+
def titleize
|
|
15
|
+
self.tr_s('- ', '_').split('_').map(&:capitalize).join(' ')
|
|
16
|
+
end unless method_defined? :titleize
|
|
17
|
+
|
|
18
|
+
def constantize
|
|
19
|
+
self.tr_s('- ', '_').split('_').map(&:capitalize).join
|
|
20
|
+
end unless method_defined? :constantize
|
|
21
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
3
|
+
module TripSpark
|
|
4
|
+
class Model
|
|
5
|
+
extend Forwardable
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
# Define a new attribute of the model.
|
|
9
|
+
# If `type` is given, a new instance of `type` will be created whenever
|
|
10
|
+
# this attribute is assigned a value. This allows creation of nested
|
|
11
|
+
# objects from a simple Hash.
|
|
12
|
+
# If `type` is given and `array` is true, the value given to this
|
|
13
|
+
# attribute will be interpreted as an array and a new instance of `type`
|
|
14
|
+
# will be created for each entry in the array
|
|
15
|
+
# It `type` is given, and the value given to this attribute is nil, no
|
|
16
|
+
# new instance of `type` will be created. Instead, the value will remain
|
|
17
|
+
# nil, as an instance of NilClass.
|
|
18
|
+
def attribute name, type: nil, array: false
|
|
19
|
+
attributes << [name, type]
|
|
20
|
+
attr_reader name
|
|
21
|
+
# Use a custom writer method to allow typed attributes to be
|
|
22
|
+
# instantiated properly.
|
|
23
|
+
define_method "#{name}=" do |value|
|
|
24
|
+
# Only do type conversion if the type is specified and the value is
|
|
25
|
+
# not nil.
|
|
26
|
+
if type and !value.nil?
|
|
27
|
+
# Lookup is done on TripSpark to ensure that Model subclasses are
|
|
28
|
+
# searched first, falling back to other types (Numeric, Hash, etc.)
|
|
29
|
+
# if no Model subclass is found.
|
|
30
|
+
klass = TripSpark.const_get(type.to_s.constantize)
|
|
31
|
+
value = array ? value.map{ |v| klass.new(v) } : klass.new(value)
|
|
32
|
+
end
|
|
33
|
+
instance_variable_set("@#{name}", value)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The list of attributes defined on the model
|
|
38
|
+
def attributes
|
|
39
|
+
@attributes ||= Set.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The attribute of the model that can be used to uniquely identify an
|
|
43
|
+
# instance from any other. The primary attribute should also be set
|
|
44
|
+
# with `attribute <name>`.
|
|
45
|
+
attr_accessor :identifier
|
|
46
|
+
def primary_attribute name
|
|
47
|
+
@identifier = name
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Define one or more delegated methods on the model, passing them to the
|
|
51
|
+
# given attribute.
|
|
52
|
+
def delegate *names, to:
|
|
53
|
+
names.each do |name|
|
|
54
|
+
def_delegator to, name
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Initialize a model instance with any given attributes assigned
|
|
60
|
+
def initialize args={}
|
|
61
|
+
assign(args)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Mass assign a group of attributes. Attribute names will be automatically
|
|
65
|
+
# be converted to snake_case for consistency.
|
|
66
|
+
def assign args={}
|
|
67
|
+
args.each do |name, value|
|
|
68
|
+
public_send("#{name.underscore}=", value)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The value of the primary attribute on this model
|
|
73
|
+
def identifier
|
|
74
|
+
send(self.class.identifier)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Assume that two Model objects are the same if their primary attributes
|
|
78
|
+
# have the same value
|
|
79
|
+
def == o
|
|
80
|
+
identifier == o.identifier
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Include all model subclasses
|
|
86
|
+
require_relative 'models/direction'
|
|
87
|
+
require_relative 'models/gps'
|
|
88
|
+
require_relative 'models/route'
|
|
89
|
+
require_relative 'models/pattern'
|
|
90
|
+
require_relative 'models/pattern_point'
|
|
91
|
+
require_relative 'models/stop'
|
|
92
|
+
require_relative 'models/vehicle'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Direction < Model
|
|
3
|
+
# The unique key used when referencing this direction
|
|
4
|
+
attribute :direction_key
|
|
5
|
+
alias_method :key, :direction_key
|
|
6
|
+
# The name of this direction
|
|
7
|
+
attribute :direction_name
|
|
8
|
+
alias_method :name, :direction_name
|
|
9
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
10
|
+
# a value of `null`.
|
|
11
|
+
attribute :route_key
|
|
12
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
13
|
+
# a value of `null`.
|
|
14
|
+
attribute :schedule_key
|
|
15
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
16
|
+
# a value of `null`.
|
|
17
|
+
attribute :direction_external_id
|
|
18
|
+
|
|
19
|
+
primary_attribute :direction_key
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class GPS < Model
|
|
3
|
+
# The time at which this GPS object as updated
|
|
4
|
+
attribute :date
|
|
5
|
+
alias_method :time, :date
|
|
6
|
+
alias_method :last_updated, :date
|
|
7
|
+
# The latitudinal position of this object
|
|
8
|
+
attribute :lat
|
|
9
|
+
alias_method :latitude, :lat
|
|
10
|
+
# The longitudinal position of this object
|
|
11
|
+
attribute :long
|
|
12
|
+
alias_method :lon, :long
|
|
13
|
+
alias_method :longitude, :long
|
|
14
|
+
# The speed at which this object is traveling
|
|
15
|
+
attribute :spd
|
|
16
|
+
alias_method :speed, :spd
|
|
17
|
+
# The direction this object is facing
|
|
18
|
+
attribute :dir
|
|
19
|
+
alias_method :direction, :dir
|
|
20
|
+
alias_method :heading, :dir
|
|
21
|
+
|
|
22
|
+
# GPS objects are always considered unique, and therefore do not have a
|
|
23
|
+
# primary attribute
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Pattern < Model
|
|
3
|
+
# The unique key used when referencing this pattern
|
|
4
|
+
attribute :key
|
|
5
|
+
# The full name of this pattern
|
|
6
|
+
attribute :name
|
|
7
|
+
# The name used to quickly identify this pattern
|
|
8
|
+
attribute :short_name
|
|
9
|
+
# A short summary of the purpose of this pattern
|
|
10
|
+
attribute :description
|
|
11
|
+
# The type of line segment that should be used when displaying this pattern
|
|
12
|
+
attribute :line_type
|
|
13
|
+
# The color that should be used to shade this pattern (as a hexcode)
|
|
14
|
+
attribute :line_color
|
|
15
|
+
# Is this a pattern that can be displayed?
|
|
16
|
+
attribute :is_displayable
|
|
17
|
+
alias_method :displayable?, :is_displayable
|
|
18
|
+
# Is this the primary pattern of the route it belongs to?
|
|
19
|
+
attribute :is_primary_pattern
|
|
20
|
+
alias_method :primary_pattern?, :is_primary_pattern
|
|
21
|
+
# The Direction that this pattern heads in
|
|
22
|
+
attribute :direction, type: :direction
|
|
23
|
+
# The list of key points that this pattern touches
|
|
24
|
+
attribute :pattern_point_list, type: :pattern_point, array: true
|
|
25
|
+
alias_method :pattern_points, :pattern_point_list
|
|
26
|
+
alias_method :points, :pattern_point_list
|
|
27
|
+
|
|
28
|
+
primary_attribute :key
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Return only the pattern points of this pattern that have the type `BusStop`
|
|
32
|
+
def stops
|
|
33
|
+
@stops ||= pattern_point_list.select{ |point| point.type == "BusStop" }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Return only the pattern points of this pattern that have the type `WayPoint`
|
|
37
|
+
def waypoints
|
|
38
|
+
@waypoints ||= pattern_point_list.select{ |point| point.type == "WayPoint" }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class PatternPoint < Model
|
|
3
|
+
# The unique key used when referencing this pattern point
|
|
4
|
+
attribute :key
|
|
5
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
6
|
+
# a value of `null`.
|
|
7
|
+
attribute :name
|
|
8
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
9
|
+
# a value of `null`.
|
|
10
|
+
attribute :description
|
|
11
|
+
# The position of this pattern point in the pattern it belongs to
|
|
12
|
+
attribute :rank
|
|
13
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
14
|
+
# a value of `null`.
|
|
15
|
+
attribute :header_rank
|
|
16
|
+
# The latitudinal position of this pattern point
|
|
17
|
+
attribute :latitude
|
|
18
|
+
# The longitudinal position of this pattern point
|
|
19
|
+
attribute :longitude
|
|
20
|
+
# The type of point that this pattern point represents. Normally either
|
|
21
|
+
# "BusStop" or "WayPoint".
|
|
22
|
+
attribute :point_type_code
|
|
23
|
+
alias_method :type, :point_type_code
|
|
24
|
+
# If this pattern point's type is "BusStop", an instance of `Stop`
|
|
25
|
+
# containing more information about it. Otherwise, nil.
|
|
26
|
+
attribute :stop, type: :stop
|
|
27
|
+
# The key of that pattern that this point belongs to
|
|
28
|
+
attribute :pattern_key
|
|
29
|
+
# Is this pattern point the last point in the pattern it belongs to?
|
|
30
|
+
attribute :is_last_point
|
|
31
|
+
alias_method :last_point?, :is_last_point
|
|
32
|
+
|
|
33
|
+
primary_attribute :key
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Route < Model
|
|
3
|
+
# The unique key used when referencing this route
|
|
4
|
+
attribute :key
|
|
5
|
+
# The full name of this route
|
|
6
|
+
attribute :name
|
|
7
|
+
# The name used to quickly identify this route
|
|
8
|
+
attribute :short_name
|
|
9
|
+
# A short summary of the purpose of this route
|
|
10
|
+
attribute :description
|
|
11
|
+
# The list of patterns that belong to this route
|
|
12
|
+
attribute :pattern_list, type: :pattern, array: true
|
|
13
|
+
alias_method :patterns, :pattern_list
|
|
14
|
+
# A combination of the name and short_name of this route
|
|
15
|
+
attribute :combined_name
|
|
16
|
+
alias_method :full_name, :combined_name
|
|
17
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
18
|
+
# a value of `null`.
|
|
19
|
+
attribute :route_type
|
|
20
|
+
alias_method :type, :route_type
|
|
21
|
+
|
|
22
|
+
primary_attribute :key
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Stop < Model
|
|
3
|
+
# The unique key used when referencing this stop
|
|
4
|
+
attribute :key
|
|
5
|
+
# The name of this stop
|
|
6
|
+
attribute :name
|
|
7
|
+
# The position of this stop in the pattern it belongs to
|
|
8
|
+
attribute :rank
|
|
9
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
10
|
+
# a value of `null`.
|
|
11
|
+
attribute :header_rank
|
|
12
|
+
# The name used to quickly identify this stop
|
|
13
|
+
attribute :stop_code
|
|
14
|
+
# The latitudinal position of this stop
|
|
15
|
+
attribute :latitude
|
|
16
|
+
# The longitudinal position of this stop
|
|
17
|
+
attribute :longitude
|
|
18
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
19
|
+
# a useless value, e.g. "9999-12-31T23:59:59.9999999".
|
|
20
|
+
attribute :arrival_at_stop
|
|
21
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
22
|
+
# a value of `0`.
|
|
23
|
+
attribute :time_to_stop
|
|
24
|
+
# Is this stop a time point of the pattern? (A point at which a vehicle
|
|
25
|
+
# wait to remain on schedule)
|
|
26
|
+
attribute :is_time_point
|
|
27
|
+
alias_method :time_point?, :is_time_point
|
|
28
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
29
|
+
# a useless value, e.g. "0001-01-01T00:00:00".
|
|
30
|
+
attribute :estimated_depart_time
|
|
31
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
32
|
+
# a useless value, e.g. "0001-01-01T00:00:00".
|
|
33
|
+
attribute :scheduled_work_date
|
|
34
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
35
|
+
# a value of `null`.
|
|
36
|
+
attribute :schedule_key
|
|
37
|
+
|
|
38
|
+
primary_attribute :key
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module TripSpark
|
|
2
|
+
class Vehicle < Model
|
|
3
|
+
# The unique key used when referencing this vehicle
|
|
4
|
+
attribute :key
|
|
5
|
+
# The name given to this vehicle
|
|
6
|
+
attribute :name
|
|
7
|
+
# The GPS location of this vehicle, along with when it was last updated
|
|
8
|
+
attribute :gps, type: :g_p_s
|
|
9
|
+
# Expose GPS information directly via this vehicle.
|
|
10
|
+
# NOTE: `direction` is delegated here, then aliased as `gps_direction`, and
|
|
11
|
+
# `heading` but `direction` will be not be available like this at run time
|
|
12
|
+
# because it is also the name of a direct attribute of a vehicle, and will
|
|
13
|
+
# get overwritten by that information.
|
|
14
|
+
delegate :latitude, :longitude, :speed, :direction, :last_updated, to: :gps
|
|
15
|
+
alias_method :gps_direction, :direction
|
|
16
|
+
alias_method :heading, :direction
|
|
17
|
+
# The pattern this vehicle is currently traveling
|
|
18
|
+
attribute :pattern, type: :pattern
|
|
19
|
+
# The route this vehicle is currently traveling
|
|
20
|
+
attribute :route, type: :route
|
|
21
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
22
|
+
# a value of `null`.
|
|
23
|
+
attribute :direction
|
|
24
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
25
|
+
# a value of `null`.
|
|
26
|
+
attribute :trip_data
|
|
27
|
+
# The next stop that this vehicle will arrive at
|
|
28
|
+
attribute :next_stop, type: :stop
|
|
29
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
30
|
+
# a value of `null`.
|
|
31
|
+
# The assumption is that this is a boolean indicating that a passenger has
|
|
32
|
+
# requested the bus stop at the next stop.
|
|
33
|
+
attribute :requested_stop
|
|
34
|
+
# Is this the last vehicle on it's pattern?
|
|
35
|
+
attribute :is_last_vehicle
|
|
36
|
+
alias_method :last_vehicle?, :is_last_vehicle
|
|
37
|
+
# The number of passengers this vehicle can carry at one time
|
|
38
|
+
attribute :passenger_capacity
|
|
39
|
+
alias_method :capacity, :passenger_capacity
|
|
40
|
+
# The number of passengers currently onboard this vehicle
|
|
41
|
+
attribute :passengers_onboard
|
|
42
|
+
alias_method :onboard, :passengers_onboard
|
|
43
|
+
# The saturation of the vehicle with passengers
|
|
44
|
+
attribute :percent_filled
|
|
45
|
+
alias_method :saturation, :percent_filled
|
|
46
|
+
# NOTE: The purpose of this field is unknown, as it is almost always given
|
|
47
|
+
# a value of `null`.
|
|
48
|
+
attribute :work
|
|
49
|
+
|
|
50
|
+
primary_attribute :key
|
|
51
|
+
end
|
|
52
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tripspark_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jon Egeland
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.13'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: memoist
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.14'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.14'
|
|
13
41
|
description: A reverse-engineered Ruby client for the publicly-visible/accessible
|
|
14
42
|
API that TripSpark transit system instances expose through their network traffic.
|
|
15
43
|
email: jonegeland@gmail.com
|
|
@@ -19,7 +47,24 @@ extra_rdoc_files:
|
|
|
19
47
|
- LICENSE
|
|
20
48
|
files:
|
|
21
49
|
- LICENSE
|
|
22
|
-
- lib/
|
|
50
|
+
- lib/tripspark_api.rb
|
|
51
|
+
- lib/tripspark_api/api.rb
|
|
52
|
+
- lib/tripspark_api/client.rb
|
|
53
|
+
- lib/tripspark_api/client/patterns.rb
|
|
54
|
+
- lib/tripspark_api/client/routes.rb
|
|
55
|
+
- lib/tripspark_api/client/vehicles.rb
|
|
56
|
+
- lib/tripspark_api/configuration.rb
|
|
57
|
+
- lib/tripspark_api/connection.rb
|
|
58
|
+
- lib/tripspark_api/connection_adapters/httparty_adapter.rb
|
|
59
|
+
- lib/tripspark_api/core_ext/string.rb
|
|
60
|
+
- lib/tripspark_api/models.rb
|
|
61
|
+
- lib/tripspark_api/models/direction.rb
|
|
62
|
+
- lib/tripspark_api/models/gps.rb
|
|
63
|
+
- lib/tripspark_api/models/pattern.rb
|
|
64
|
+
- lib/tripspark_api/models/pattern_point.rb
|
|
65
|
+
- lib/tripspark_api/models/route.rb
|
|
66
|
+
- lib/tripspark_api/models/stop.rb
|
|
67
|
+
- lib/tripspark_api/models/vehicle.rb
|
|
23
68
|
- lib/tripspark_api/version.rb
|
|
24
69
|
homepage: http://github.com/propershark/tripspark_api
|
|
25
70
|
licenses:
|
data/lib/tripspark.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require_relative 'tripspark_api/version'
|