hypertrack 0.0.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 +7 -0
- data/lib/hypertrack.rb +44 -0
- data/lib/hypertrack/api_client.rb +94 -0
- data/lib/hypertrack/api_operations/common/create.rb +16 -0
- data/lib/hypertrack/api_operations/common/list.rb +19 -0
- data/lib/hypertrack/api_operations/common/retrieve.rb +24 -0
- data/lib/hypertrack/api_operations/common/update.rb +33 -0
- data/lib/hypertrack/api_operations/driver_api.rb +25 -0
- data/lib/hypertrack/api_operations/shift_api.rb +13 -0
- data/lib/hypertrack/api_operations/task_api.rb +32 -0
- data/lib/hypertrack/api_operations/trip_api.rb +43 -0
- data/lib/hypertrack/errors/hypertrack_errors.rb +67 -0
- data/lib/hypertrack/params_validator.rb +46 -0
- data/lib/hypertrack/resources/customer.rb +10 -0
- data/lib/hypertrack/resources/destination.rb +10 -0
- data/lib/hypertrack/resources/driver.rb +15 -0
- data/lib/hypertrack/resources/event.rb +14 -0
- data/lib/hypertrack/resources/fleet.rb +10 -0
- data/lib/hypertrack/resources/hub.rb +10 -0
- data/lib/hypertrack/resources/neighbourhood.rb +14 -0
- data/lib/hypertrack/resources/shift.rb +11 -0
- data/lib/hypertrack/resources/task.rb +22 -0
- data/lib/hypertrack/resources/trip.rb +15 -0
- data/lib/hypertrack/shared_resource.rb +63 -0
- data/lib/util.rb +15 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9716d695f09e507853ca9745f765191d5efeabda
|
4
|
+
data.tar.gz: 8a2c4b15c4770a2f9cc2952efe8b1c2cec933972
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 465a675a0ce5a9e5c70110c7b1c79243b094dcdf58f9d545243ce40ea97661dfa5d7db810ac108e42910c9f42968995473edcce51e8b582b2b608036f427f34c
|
7
|
+
data.tar.gz: eb695184c6af67acd6e5c592660586744606d95926424acb4c3aef76c866cec9da60ede42917479a8838e5ac5047270f4605ad18356fb4bbf021fdb31e407fc2
|
data/lib/hypertrack.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "json"
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
require_relative "util"
|
5
|
+
require_relative "hypertrack/params_validator"
|
6
|
+
|
7
|
+
# Errors
|
8
|
+
require_relative "hypertrack/errors/hypertrack_errors"
|
9
|
+
|
10
|
+
# API Operations
|
11
|
+
require_relative "hypertrack/api_operations/common/create"
|
12
|
+
require_relative "hypertrack/api_operations/common/retrieve"
|
13
|
+
require_relative "hypertrack/api_operations/common/list"
|
14
|
+
require_relative "hypertrack/api_operations/common/update"
|
15
|
+
require_relative "hypertrack/api_operations/driver_api"
|
16
|
+
require_relative "hypertrack/api_operations/task_api"
|
17
|
+
require_relative "hypertrack/api_operations/trip_api"
|
18
|
+
require_relative "hypertrack/api_operations/shift_api"
|
19
|
+
|
20
|
+
# All HTTP calls made here
|
21
|
+
require_relative "hypertrack/api_client"
|
22
|
+
|
23
|
+
# HyperTrack Resouce Wrapper
|
24
|
+
require_relative "hypertrack/shared_resource"
|
25
|
+
|
26
|
+
# Resources
|
27
|
+
require_relative "hypertrack/resources/driver"
|
28
|
+
require_relative "hypertrack/resources/customer"
|
29
|
+
require_relative "hypertrack/resources/destination"
|
30
|
+
require_relative "hypertrack/resources/task"
|
31
|
+
require_relative "hypertrack/resources/trip"
|
32
|
+
require_relative "hypertrack/resources/neighbourhood"
|
33
|
+
require_relative "hypertrack/resources/fleet"
|
34
|
+
require_relative "hypertrack/resources/hub"
|
35
|
+
require_relative "hypertrack/resources/shift"
|
36
|
+
require_relative "hypertrack/resources/event"
|
37
|
+
|
38
|
+
module HyperTrack
|
39
|
+
|
40
|
+
class << self
|
41
|
+
attr_accessor :secret_key
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class ApiClient
|
3
|
+
|
4
|
+
BASE_URL = "https://app.hypertrack.io/api"
|
5
|
+
API_VERSION = "v1"
|
6
|
+
|
7
|
+
VERB_MAP = {
|
8
|
+
:get => Net::HTTP::Get,
|
9
|
+
:post => Net::HTTP::Post
|
10
|
+
}
|
11
|
+
|
12
|
+
ACCEPTED_RESPONSE_CODES = [200, 201]
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
def create(api_path, data={})
|
17
|
+
api_uri = get_uri(api_path)
|
18
|
+
request_object = create_request_object(api_uri, :post)
|
19
|
+
request_object.body = data.to_json
|
20
|
+
make_request(api_uri, request_object)
|
21
|
+
end
|
22
|
+
alias_method :update, :create
|
23
|
+
|
24
|
+
def fetch(api_path, query_params={})
|
25
|
+
api_path = path_with_params(api_path, query_params) if query_params.is_a?(Hash) && query_params.keys.length > 0
|
26
|
+
api_uri = get_uri(api_path)
|
27
|
+
request_object = create_request_object(api_uri, :get)
|
28
|
+
make_request(api_uri, request_object)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def path_with_params(path, params)
|
34
|
+
encoded_params = URI.encode_www_form(params)
|
35
|
+
[path, encoded_params].join("?")
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_auth_header
|
39
|
+
if Util.blank?(HyperTrack.secret_key)
|
40
|
+
raise HyperTrack::InvalidAPIKey.new("HyperTrack.secret_key is invalid.")
|
41
|
+
end
|
42
|
+
|
43
|
+
{ "Authorization" => "token #{HyperTrack.secret_key}" }
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_uri(path)
|
47
|
+
url = "#{BASE_URL}/#{API_VERSION}/#{path}"
|
48
|
+
URI.parse(url)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_request_object(api_uri, http_method)
|
52
|
+
if VERB_MAP[http_method].nil?
|
53
|
+
raise HyperTrack::MethodNotAllowed.new("Unsupported HTTP verb used - Only #{VERB_MAP.keys.map{ |x| x.to_s.upcase }} allowed")
|
54
|
+
end
|
55
|
+
|
56
|
+
header = get_auth_header
|
57
|
+
request_object = VERB_MAP[http_method].new(api_uri.path, header)
|
58
|
+
request_object['Content-Type'] = 'application/json'
|
59
|
+
request_object
|
60
|
+
end
|
61
|
+
|
62
|
+
# To-Do: Add a timeout
|
63
|
+
def make_request(api_uri, request_object)
|
64
|
+
conn = Net::HTTP.new api_uri.host, api_uri.port
|
65
|
+
conn.use_ssl = api_uri.scheme == 'https'
|
66
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
67
|
+
conn.cert_store = OpenSSL::X509::Store.new
|
68
|
+
conn.cert_store.set_default_paths
|
69
|
+
parse_response(conn.request(request_object))
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_response(response)
|
73
|
+
response_code = response.code.to_i
|
74
|
+
|
75
|
+
if valid_response_code?(response_code)
|
76
|
+
begin
|
77
|
+
JSON.parse(response.body)
|
78
|
+
rescue JSON::ParserError => e
|
79
|
+
raise HyperTrack::InvalidJSONResponse(response.body)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
error_klass = HyperTrack::Error.defined_codes[response_code] || HyperTrack::UnknownError
|
83
|
+
raise error_klass.new(response.body, response_code)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def valid_response_code?(code)
|
88
|
+
ACCEPTED_RESPONSE_CODES.include?(code)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module Common
|
4
|
+
module Create
|
5
|
+
|
6
|
+
def create(params={})
|
7
|
+
if HyperTrack::ParamsValidator.valid_args?(params, get_class_name::REQUIRED_FIELDS, get_class_name::VALID_ATTRIBUTE_VALUES)
|
8
|
+
result = HyperTrack::ApiClient.create(get_class_name::API_BASE_PATH, params)
|
9
|
+
get_class_name.new(result['id'], result)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module Common
|
4
|
+
module List
|
5
|
+
|
6
|
+
def list(filter_params={})
|
7
|
+
api_result = HyperTrack::ApiClient.fetch(get_class_name::API_BASE_PATH, filter_params)
|
8
|
+
|
9
|
+
api_result['results'].each_with_index do |opts, idx|
|
10
|
+
api_result['results'][idx] = get_class_name.new(opts['id'], opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
api_result
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module Common
|
4
|
+
module Retrieve
|
5
|
+
|
6
|
+
def retrieve(id)
|
7
|
+
raise HyperTrack::InvalidParameters.new("ID is required to retrieve a #{self.name}") unless valid_retrieve_id?(id)
|
8
|
+
|
9
|
+
retrieve_customer_path = "#{get_class_name::API_BASE_PATH}#{id}/"
|
10
|
+
result = HyperTrack::ApiClient.fetch(retrieve_customer_path)
|
11
|
+
|
12
|
+
get_class_name.new(id, result)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_retrieve_id?(id)
|
18
|
+
!Util.blank?(id)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module Common
|
4
|
+
module Update
|
5
|
+
|
6
|
+
def update(path, params, required_params=[])
|
7
|
+
if HyperTrack::ParamsValidator.valid_args?(params, required_params, self.class::VALID_ATTRIBUTE_VALUES)
|
8
|
+
api_path = "#{self.class::API_BASE_PATH}#{self.id}/" + path
|
9
|
+
result = HyperTrack::ApiClient.update(api_path, params)
|
10
|
+
update_attributes_in_object(result)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def update_attributes_in_object(result)
|
17
|
+
result = Util.symbolize_keys(result)
|
18
|
+
|
19
|
+
self_keys = self.keys
|
20
|
+
|
21
|
+
result.each do |key, value|
|
22
|
+
if self_keys.include?(key) && self[key] != value
|
23
|
+
self[key] = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module DriverAPI
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def map_list(filter_params={})
|
12
|
+
map_list_path = "#{HyperTrack::Driver::API_BASE_PATH}map_list/"
|
13
|
+
result = HyperTrack::ApiClient.fetch(map_list_path, filter_params)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def overview(filter_params={})
|
19
|
+
driver_overview_path = "#{HyperTrack::Driver::API_BASE_PATH}#{self.id}/overview/"
|
20
|
+
result = HyperTrack::ApiClient.fetch(driver_overview_path, filter_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module TaskAPI
|
4
|
+
|
5
|
+
def editable_url(params)
|
6
|
+
path = "editable_url/"
|
7
|
+
self.update(path, params, [:editable])
|
8
|
+
end
|
9
|
+
|
10
|
+
def start(params)
|
11
|
+
path = "start/"
|
12
|
+
self.update(path, params, [:start_location, :start_time])
|
13
|
+
end
|
14
|
+
|
15
|
+
def complete(params)
|
16
|
+
path = "completed/"
|
17
|
+
self.update(path, params, [:completion_location])
|
18
|
+
end
|
19
|
+
|
20
|
+
def cancel(params={})
|
21
|
+
path = "canceled/"
|
22
|
+
self.update(path, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_destination(params)
|
26
|
+
path = "update_destination/"
|
27
|
+
self.update(path, params, [:location])
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ApiOperations
|
3
|
+
module TripAPI
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def sending_eta(params)
|
12
|
+
if HyperTrack::ParamsValidator.valid_args?(params, [:driver, :destination], HyperTrack::Trip::VALID_ATTRIBUTE_VALUES)
|
13
|
+
eta_path = "#{HyperTrack::Trip::API_BASE_PATH}lite/"
|
14
|
+
result = HyperTrack::ApiClient.update(eta_path, params)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Don't want to name this method as 'end'. Its a reserved keyword in Ruby.
|
21
|
+
def end_trip(params)
|
22
|
+
path = "end/"
|
23
|
+
self.update(path, params, [:end_location])
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_task(params)
|
27
|
+
path = 'add_task/'
|
28
|
+
self.update(path, params, [:task_id])
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_task(params)
|
32
|
+
path = 'remove_task/'
|
33
|
+
self.update(path, params, [:task_id])
|
34
|
+
end
|
35
|
+
|
36
|
+
def change_task_order(params)
|
37
|
+
path = 'change_task_order/'
|
38
|
+
self.update(path, params, [:task_order])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
attr_reader :code
|
5
|
+
|
6
|
+
def self.defined_codes
|
7
|
+
{
|
8
|
+
400 => HyperTrack::InvalidParameters,
|
9
|
+
401 => HyperTrack::InvalidAPIKey,
|
10
|
+
402 => HyperTrack::NoFreeCreditsLeft,
|
11
|
+
403 => HyperTrack::AccessForbidden,
|
12
|
+
404 => HyperTrack::ResourceNotFound,
|
13
|
+
405 => HyperTrack::MethodNotAllowed,
|
14
|
+
406 => HyperTrack::FormatNotAcceptable,
|
15
|
+
410 => HyperTrack::ResourceRemovedFromServer,
|
16
|
+
429 => HyperTrack::RateLimitExceeded,
|
17
|
+
500 => HyperTrack::InternalServerError,
|
18
|
+
503 => HyperTrack::ServiceTemporarilyUnavailable
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(message, code=nil)
|
23
|
+
@code = code
|
24
|
+
super(message)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# Raised when - Missing or invalid parameters in API call
|
30
|
+
class InvalidParameters < Error; end
|
31
|
+
|
32
|
+
# Raised when - Missing or invalid API key
|
33
|
+
class InvalidAPIKey < Error; end
|
34
|
+
|
35
|
+
# Raised when - You don't have any free credits left
|
36
|
+
class NoFreeCreditsLeft < Error; end
|
37
|
+
|
38
|
+
# Raised when - You don’t have permission to access the resource
|
39
|
+
class AccessForbidden < Error; end
|
40
|
+
|
41
|
+
# Raised when - The resource does not exist
|
42
|
+
class ResourceNotFound < Error; end
|
43
|
+
|
44
|
+
# Raised when - You tried to access a resource with an invalid method
|
45
|
+
class MethodNotAllowed < Error; end
|
46
|
+
|
47
|
+
# Raised when - You requested a format that isn’t json
|
48
|
+
class FormatNotAcceptable < Error; end
|
49
|
+
|
50
|
+
# Raised when - The requested resource has been removed from our servers
|
51
|
+
class ResourceRemovedFromServer < Error; end
|
52
|
+
|
53
|
+
# Raised when - You have hit the rate limit for your account
|
54
|
+
class RateLimitExceeded < Error; end
|
55
|
+
|
56
|
+
# Raised when - There was an error on the server and we have been notified. Try again later.
|
57
|
+
class InternalServerError < Error; end
|
58
|
+
|
59
|
+
# Raised when - We are temporarily offline for maintenance. Please try again later.
|
60
|
+
class ServiceTemporarilyUnavailable < Error; end
|
61
|
+
|
62
|
+
# Raised when - We get an unknown response code from the API
|
63
|
+
class UnknownError < Error; end
|
64
|
+
|
65
|
+
# Raised when - We get an invalid JSON in response from API
|
66
|
+
class InvalidJSONResponse < Error; end
|
67
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
module ParamsValidator
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def valid_args?(params, required_fields, valid_attr_values)
|
7
|
+
unless valid_params_object?(params)
|
8
|
+
raise HyperTrack::InvalidParameters.new("Error: Expected a Hash. Got: #{params}")
|
9
|
+
end
|
10
|
+
|
11
|
+
params = Util.symbolize_keys(params)
|
12
|
+
|
13
|
+
if missing_required_fields?(params, required_fields)
|
14
|
+
raise HyperTrack::InvalidParameters.new("Request is missing required params - #{required_fields - params.keys}")
|
15
|
+
end
|
16
|
+
|
17
|
+
params.each do |name, value|
|
18
|
+
next if Util.blank?(value) && valid_attr_values[name][:allow_nil]
|
19
|
+
next if valid_attr_values[name].nil? || valid_attr_values[name][:allowed].nil?
|
20
|
+
|
21
|
+
valid_values = valid_attr_values[name][:allowed]
|
22
|
+
if !valid_values.include?(value) && !valid_values.include?(value.to_sym)
|
23
|
+
raise HyperTrack::InvalidParameters.new("Error: Invalid #{name}: #{value}. Allowed: #{valid_values.join(', ')}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def valid_params_object?(params)
|
33
|
+
params.is_a?(Hash)
|
34
|
+
end
|
35
|
+
|
36
|
+
def missing_required_fields?(params, required_fields)
|
37
|
+
required_fields.each do |field|
|
38
|
+
return true if Util.blank?(params[field])
|
39
|
+
end
|
40
|
+
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Driver < HyperTrack::SharedResource
|
3
|
+
include HyperTrack::ApiOperations::DriverAPI
|
4
|
+
|
5
|
+
API_BASE_PATH = "drivers/"
|
6
|
+
REQUIRED_FIELDS = [:name, :vehicle_type]
|
7
|
+
|
8
|
+
VALID_ATTRIBUTE_VALUES = {
|
9
|
+
vehicle_type: {
|
10
|
+
allowed: HyperTrack::SharedResource::VALID_VEHICLE_TYPES
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Event < HyperTrack::SharedResource
|
3
|
+
|
4
|
+
API_BASE_PATH = "events/"
|
5
|
+
REQUIRED_FIELDS = []
|
6
|
+
|
7
|
+
VALID_ATTRIBUTE_VALUES = {}
|
8
|
+
|
9
|
+
def self.create(params={})
|
10
|
+
raise HyperTrack::MethodNotAllowed.new("Create not allowed on HyperTrack::Event class")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Neighbourhood < HyperTrack::SharedResource
|
3
|
+
|
4
|
+
API_BASE_PATH = "neighborhoods/"
|
5
|
+
REQUIRED_FIELDS = []
|
6
|
+
|
7
|
+
VALID_ATTRIBUTE_VALUES = {}
|
8
|
+
|
9
|
+
def self.create(params={})
|
10
|
+
raise HyperTrack::MethodNotAllowed.new("Create not allowed on HyperTrack::Neighbourhood class")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Task < HyperTrack::SharedResource
|
3
|
+
include HyperTrack::ApiOperations::TaskAPI
|
4
|
+
|
5
|
+
API_BASE_PATH = "tasks/"
|
6
|
+
REQUIRED_FIELDS = []
|
7
|
+
|
8
|
+
VALID_ATTRIBUTE_VALUES = {
|
9
|
+
action: {
|
10
|
+
allowed: [:pickup, :delivery, :visit, :task],
|
11
|
+
allow_nil: true
|
12
|
+
},
|
13
|
+
editable: {
|
14
|
+
allowed: [:'not editable', :once, :multiple]
|
15
|
+
},
|
16
|
+
vehicle_type: {
|
17
|
+
allowed: HyperTrack::SharedResource::VALID_VEHICLE_TYPES
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class Trip < HyperTrack::SharedResource
|
3
|
+
include HyperTrack::ApiOperations::TripAPI
|
4
|
+
|
5
|
+
API_BASE_PATH = "trips/"
|
6
|
+
REQUIRED_FIELDS = [:driver_id, :start_location, :tasks]
|
7
|
+
|
8
|
+
VALID_ATTRIBUTE_VALUES = {
|
9
|
+
vehicle_type: {
|
10
|
+
allowed: HyperTrack::SharedResource::VALID_VEHICLE_TYPES
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module HyperTrack
|
2
|
+
class SharedResource
|
3
|
+
extend HyperTrack::ApiOperations::Common::Create
|
4
|
+
extend HyperTrack::ApiOperations::Common::Retrieve
|
5
|
+
extend HyperTrack::ApiOperations::Common::List
|
6
|
+
include HyperTrack::ApiOperations::Common::Update
|
7
|
+
|
8
|
+
VALID_VEHICLE_TYPES = [:walking, :bicycle, :motorcycle, :car, :'3-wheeler', :van] #[:flight, :train, :ship]
|
9
|
+
|
10
|
+
attr_accessor :id
|
11
|
+
|
12
|
+
def initialize(id, opts)
|
13
|
+
@id = id
|
14
|
+
@values = Util.symbolize_keys(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](k)
|
18
|
+
@values[k.to_sym]
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(k, v)
|
22
|
+
@values[k.to_sym] = v
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys
|
26
|
+
@values.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def values
|
30
|
+
@values.values
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_json(*a)
|
34
|
+
JSON.generate(@values)
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def method_missing(name, *args)
|
40
|
+
if name[-1] == "="
|
41
|
+
name = name[0..-2]
|
42
|
+
|
43
|
+
if @values.has_key?(name.to_sym)
|
44
|
+
self[name.to_sym] = args[0]
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
elsif @values.has_key?(name.to_sym)
|
49
|
+
return @values[name.to_sym]
|
50
|
+
end
|
51
|
+
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def self.get_class_name
|
58
|
+
# To-Do: Umm.. Find some better approach
|
59
|
+
Object.const_get(self.name)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/lib/util.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hypertrack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Utsav Kesharwani
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-01 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: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
description: Ruby wrapper around HyperTrack's API. Refer http://docs.hypertrack.io/
|
28
|
+
for more information.
|
29
|
+
email: utsav.kesharwani@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/hypertrack.rb
|
35
|
+
- lib/hypertrack/api_client.rb
|
36
|
+
- lib/hypertrack/api_operations/common/create.rb
|
37
|
+
- lib/hypertrack/api_operations/common/list.rb
|
38
|
+
- lib/hypertrack/api_operations/common/retrieve.rb
|
39
|
+
- lib/hypertrack/api_operations/common/update.rb
|
40
|
+
- lib/hypertrack/api_operations/driver_api.rb
|
41
|
+
- lib/hypertrack/api_operations/shift_api.rb
|
42
|
+
- lib/hypertrack/api_operations/task_api.rb
|
43
|
+
- lib/hypertrack/api_operations/trip_api.rb
|
44
|
+
- lib/hypertrack/errors/hypertrack_errors.rb
|
45
|
+
- lib/hypertrack/params_validator.rb
|
46
|
+
- lib/hypertrack/resources/customer.rb
|
47
|
+
- lib/hypertrack/resources/destination.rb
|
48
|
+
- lib/hypertrack/resources/driver.rb
|
49
|
+
- lib/hypertrack/resources/event.rb
|
50
|
+
- lib/hypertrack/resources/fleet.rb
|
51
|
+
- lib/hypertrack/resources/hub.rb
|
52
|
+
- lib/hypertrack/resources/neighbourhood.rb
|
53
|
+
- lib/hypertrack/resources/shift.rb
|
54
|
+
- lib/hypertrack/resources/task.rb
|
55
|
+
- lib/hypertrack/resources/trip.rb
|
56
|
+
- lib/hypertrack/shared_resource.rb
|
57
|
+
- lib/util.rb
|
58
|
+
homepage: http://rubygems.org/gems/hypertrack
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.0.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.7
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Ruby bindings for the HyperTrack API!
|
82
|
+
test_files: []
|