webfleet_connect 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/Gemfile +8 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +674 -0
- data/README.md +286 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/webfleet_connect/actions/action.rb +24 -0
- data/lib/webfleet_connect/actions/actions.rb +14 -0
- data/lib/webfleet_connect/actions/addresses.rb +17 -0
- data/lib/webfleet_connect/actions/drivers.rb +23 -0
- data/lib/webfleet_connect/actions/events.rb +15 -0
- data/lib/webfleet_connect/actions/geocoding.rb +9 -0
- data/lib/webfleet_connect/actions/messages.rb +13 -0
- data/lib/webfleet_connect/actions/miscellaneous.rb +13 -0
- data/lib/webfleet_connect/actions/objects.rb +28 -0
- data/lib/webfleet_connect/actions/orders.rb +19 -0
- data/lib/webfleet_connect/actions/trips.rb +21 -0
- data/lib/webfleet_connect/builder.rb +13 -0
- data/lib/webfleet_connect/connection.rb +39 -0
- data/lib/webfleet_connect/credentials.rb +53 -0
- data/lib/webfleet_connect/default_config.rb +46 -0
- data/lib/webfleet_connect/enums/devices.rb +10 -0
- data/lib/webfleet_connect/enums/special_vehicle_types.rb +7 -0
- data/lib/webfleet_connect/enums/vehicle_types.rb +49 -0
- data/lib/webfleet_connect/error.rb +34 -0
- data/lib/webfleet_connect/format_handlers/csv_error_parser.rb +16 -0
- data/lib/webfleet_connect/format_handlers/csv_response_error_parser.rb +11 -0
- data/lib/webfleet_connect/format_handlers/csv_response_parser.rb +25 -0
- data/lib/webfleet_connect/format_handlers/error_parser.rb +11 -0
- data/lib/webfleet_connect/format_handlers/json_error_parser.rb +17 -0
- data/lib/webfleet_connect/format_handlers/json_response_parser.rb +9 -0
- data/lib/webfleet_connect/helpers/case_helper.rb +18 -0
- data/lib/webfleet_connect/helpers/class_helper.rb +5 -0
- data/lib/webfleet_connect/helpers/date_format_helper.rb +13 -0
- data/lib/webfleet_connect/helpers/encoding_helper.rb +8 -0
- data/lib/webfleet_connect/helpers.rb +2 -0
- data/lib/webfleet_connect/params/default_param.rb +16 -0
- data/lib/webfleet_connect/params/param.rb +23 -0
- data/lib/webfleet_connect/params/params.rb +2 -0
- data/lib/webfleet_connect/params/params_factory.rb +22 -0
- data/lib/webfleet_connect/params/range_pattern.rb +39 -0
- data/lib/webfleet_connect/params/rangefrom_string.rb +23 -0
- data/lib/webfleet_connect/params/rangeto_string.rb +9 -0
- data/lib/webfleet_connect/response.rb +33 -0
- data/lib/webfleet_connect/session.rb +44 -0
- data/lib/webfleet_connect/version.rb +5 -0
- data/lib/webfleet_connect.rb +10 -0
- data/sig/webfleet_connect.rbs +4 -0
- data/webfleet_connect.gemspec +33 -0
- metadata +161 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
class WebfleetConnect::DefaultConfig
|
2
|
+
HOST = 'csv.webfleet.com'
|
3
|
+
PATH = 'extern'
|
4
|
+
|
5
|
+
def initialize(args = {})
|
6
|
+
args = default_arguments.merge(args)
|
7
|
+
@lang = args[:lang]
|
8
|
+
@format = args[:format]
|
9
|
+
@useUTF8 = args[:useUTF8]
|
10
|
+
@useISO8601 = args[:useISO8601]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{base_url}?#{lang}&#{format}&#{useUTF8}&#{useISO8601}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def json?
|
18
|
+
@format == :json
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def default_arguments
|
24
|
+
{ lang: :en, format: :csv, useUTF8: false, useISO8601: false }
|
25
|
+
end
|
26
|
+
|
27
|
+
def base_url
|
28
|
+
"https://#{HOST}/#{PATH}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def lang
|
32
|
+
"lang=#{@lang}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def format
|
36
|
+
"outputformat=#{@format}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def useUTF8
|
40
|
+
"useUTF8=#{@useUTF8}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def useISO8601
|
44
|
+
"useISO8601=#{@useISO8601}"
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module WebfleetConnect::Enums::Devices
|
2
|
+
def link() :link end
|
3
|
+
def ecoPLUS() :ecoPLUS end
|
4
|
+
def link100() :link100 end
|
5
|
+
def link510() :link510 end
|
6
|
+
def link610() :link610 end
|
7
|
+
def link710() :link710 end
|
8
|
+
def phone() :phone end
|
9
|
+
def tablet() :tablet end
|
10
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module WebfleetConnect::Enums::VehicleTypes
|
2
|
+
def ape() :ape end
|
3
|
+
def barge() :barge end
|
4
|
+
def bike() :bike end
|
5
|
+
def boom_lift() :boom_lift end
|
6
|
+
def boom_lift_truck() :boom_lift_truck end
|
7
|
+
def bus() :bus end
|
8
|
+
def caddy() :caddy end
|
9
|
+
def car() :car end
|
10
|
+
def car_station_wagon() :car_station_wagon end
|
11
|
+
def concrete_lorry() :concrete_lorry end
|
12
|
+
def containership() :containership end
|
13
|
+
def crane() :crane end
|
14
|
+
def deposit_tipper() :deposit_tipper end
|
15
|
+
def dump_truck() :dump_truck end
|
16
|
+
def dump_truck_open() :dump_truck_open end
|
17
|
+
def excavator() :excavator end
|
18
|
+
def garbage_truck() :garbage_truck end
|
19
|
+
def heavy_truck() :heavy_truck end
|
20
|
+
def heavytruck_us() :heavytruck_us end
|
21
|
+
def heavyweight_truck() :heavyweight_truck end
|
22
|
+
def heavyweight_truck_trailer() :heavyweight_truck_trailer end
|
23
|
+
def lighttruck() :lighttruck end
|
24
|
+
def light_truck_pallet() :light_truck_pallet end
|
25
|
+
def loader() :loader end
|
26
|
+
def medium_truck() :medium_truck end
|
27
|
+
def multicar() :multicar end
|
28
|
+
def multivan() :multivan end
|
29
|
+
def pallet_truck() :pallet_truck end
|
30
|
+
def pickup() :pickup end
|
31
|
+
def smart() :smart end
|
32
|
+
def sprinter() :sprinter end
|
33
|
+
def street_sweeper() :street_sweeper end
|
34
|
+
def suv() :suv end
|
35
|
+
def tanker_truck() :tanker_truck end
|
36
|
+
def telescopic_handler() :telescopic_handler end
|
37
|
+
def tractor() :tractor end
|
38
|
+
def trailer() :trailer end
|
39
|
+
def train() :train end
|
40
|
+
def truck() :truck end
|
41
|
+
def truck_loader_arm() :truck_loader_arm end
|
42
|
+
def truck_trailer() :truck_trailer end
|
43
|
+
def truck_with_trailer() :truck_with_trailer end
|
44
|
+
def truck_wrecker() :truck_wrecker end
|
45
|
+
def van() :van end
|
46
|
+
def vespa() :vespa end
|
47
|
+
def wrecker() :wrecker end
|
48
|
+
def yacht() :yacht end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'format_handlers/json_response_parser'
|
2
|
+
require_relative 'format_handlers/csv_response_error_parser'
|
3
|
+
|
4
|
+
module WebfleetConnect
|
5
|
+
class Error < StandardError
|
6
|
+
SITE = 'https://www.webfleet.com'
|
7
|
+
PATH = '/static/help/webfleet-connect/en_gb/index.html'
|
8
|
+
|
9
|
+
attr_reader :code, :url
|
10
|
+
|
11
|
+
def initialize(message, url, is_json)
|
12
|
+
parser = build_parser(is_json)
|
13
|
+
hash = parser.to_hash(message)
|
14
|
+
@code = hash[:errorCode]
|
15
|
+
@message = hash[:errorMsg]
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
"#{code}, #{@message}\n\nCheck #{api_docs_url} for more details.\n\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def api_docs_url
|
26
|
+
"#{SITE}#{PATH}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_parser(is_json)
|
30
|
+
return FormatHandlers::JsonResponseParser.new if is_json
|
31
|
+
FormatHandlers::CsvResponseErrorParser.new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'error_parser'
|
2
|
+
|
3
|
+
module WebfleetConnect::FormatHandlers
|
4
|
+
class CsvErrorParser < ErrorParser
|
5
|
+
def error?(message)
|
6
|
+
code = message.split(',').first
|
7
|
+
four_digit_number?(code)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def four_digit_number?(string)
|
13
|
+
/\A\d+\z/ === string
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module WebfleetConnect::FormatHandlers
|
4
|
+
class CsvResponseParser
|
5
|
+
def to_hash(message)
|
6
|
+
csv = parse(message)
|
7
|
+
hash = format(csv)
|
8
|
+
symbolized_hash(hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def parse(text)
|
14
|
+
CSV.parse(text, headers: true, col_sep: ';')
|
15
|
+
end
|
16
|
+
|
17
|
+
def format(csv)
|
18
|
+
csv.map(&:to_h)
|
19
|
+
end
|
20
|
+
|
21
|
+
def symbolized_hash(hash)
|
22
|
+
hash.map { |h| h.transform_keys(&:to_sym) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'error_parser'
|
2
|
+
|
3
|
+
module WebfleetConnect::FormatHandlers
|
4
|
+
class JsonErrorParser < ErrorParser
|
5
|
+
def error?(message)
|
6
|
+
json = to_json(message)
|
7
|
+
return false if json.is_a?(Array)
|
8
|
+
json.key?(:errorCode)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def to_json(message)
|
14
|
+
JSON.parse(message, symbolize_names: true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WebfleetConnect::Helpers::CaseHelper
|
2
|
+
def pascal_to_snake(str)
|
3
|
+
str.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
|
4
|
+
end
|
5
|
+
|
6
|
+
def pascal_to_cammel(str)
|
7
|
+
str[0].downcase + str[1..]
|
8
|
+
end
|
9
|
+
|
10
|
+
def snake_to_pascal(str)
|
11
|
+
str.split('_').map(&:capitalize).join('')
|
12
|
+
end
|
13
|
+
|
14
|
+
def snake_to_cammel(str)
|
15
|
+
pascal = snake_to_pascal(str)
|
16
|
+
pascal_to_cammel(pascal)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module WebfleetConnect::Helpers::DateFormatHelper
|
2
|
+
def to_de(datetime)
|
3
|
+
datetime.strftime('%d.%m.%Y %H:%M:%S')
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_en(datetime)
|
7
|
+
datetime.strftime('%d/%m/%Y %H:%M:%S')
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_nl
|
11
|
+
datetime.strftime('%d-%m-%Y %H:%M:%S')
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../helpers/class_helper'
|
2
|
+
require_relative '../helpers/case_helper'
|
3
|
+
|
4
|
+
module WebfleetConnect
|
5
|
+
class Params::Param
|
6
|
+
include Helpers::ClassHelper
|
7
|
+
include Helpers::CaseHelper
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"&#{param}=#{@value}"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def param
|
20
|
+
pascal_to_snake(class_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'params'
|
2
|
+
require_relative 'default_param'
|
3
|
+
require_relative 'rangefrom_string'
|
4
|
+
require_relative 'rangeto_string'
|
5
|
+
require_relative 'range_pattern'
|
6
|
+
|
7
|
+
module WebfleetConnect::Params
|
8
|
+
module ParamsFactory
|
9
|
+
def build_params(args)
|
10
|
+
args.map { |k, v| build(k, v) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def build(param, value)
|
16
|
+
return RangePattern.new(value) if param == :range_pattern
|
17
|
+
return RangefromString.new(value) if param == :rangefrom_string
|
18
|
+
return RangetoString.new(value) if param == :rangeto_string
|
19
|
+
DefaultParam.new(param, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'param'
|
2
|
+
|
3
|
+
module WebfleetConnect::Params
|
4
|
+
class RangePattern < Param
|
5
|
+
def initialize(value)
|
6
|
+
@value = format(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
VALID_OPTIONS = {
|
12
|
+
today: 'd0',
|
13
|
+
yesterday: 'd-1',
|
14
|
+
two_days_ago: 'd-2',
|
15
|
+
three_days_ago: 'd-3',
|
16
|
+
four_days_ago: 'd-4',
|
17
|
+
five_days_ago: 'd-5',
|
18
|
+
six_days_ago: 'd-6',
|
19
|
+
current_week: 'w0',
|
20
|
+
last_week: 'w-1',
|
21
|
+
two_weeks_ago: 'w-2',
|
22
|
+
three_weeks_ago: 'w-3',
|
23
|
+
floating_week: 'wf0',
|
24
|
+
last_floating_week: 'wf-1',
|
25
|
+
two_floating_weeks_ago: 'wf-2',
|
26
|
+
three_floating_weeks_ago: 'wf-3',
|
27
|
+
current_month: 'm0',
|
28
|
+
last_month: 'm-1',
|
29
|
+
two_months_ago: 'm-2',
|
30
|
+
three_months_ago: 'm-3',
|
31
|
+
user_defined_range: 'ud',
|
32
|
+
ud: 'ud'
|
33
|
+
}
|
34
|
+
|
35
|
+
def format(value)
|
36
|
+
VALID_OPTIONS[value.to_sym] || value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'param'
|
2
|
+
require_relative '../helpers/date_format_helper'
|
3
|
+
|
4
|
+
module WebfleetConnect::Params
|
5
|
+
class RangefromString < Param
|
6
|
+
include WebfleetConnect::Helpers::DateFormatHelper
|
7
|
+
|
8
|
+
def initialize(value)
|
9
|
+
@value = format(value)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def format(value)
|
15
|
+
return value if string?(value)
|
16
|
+
to_en(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def string?(value)
|
20
|
+
value.class == String
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'format_handlers/json_response_parser'
|
2
|
+
require_relative 'format_handlers/csv_response_parser'
|
3
|
+
|
4
|
+
module WebfleetConnect
|
5
|
+
class Response
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize(response, url, is_json)
|
9
|
+
@response = response
|
10
|
+
@url = url
|
11
|
+
@parser = build_parser(is_json)
|
12
|
+
end
|
13
|
+
|
14
|
+
def status_code
|
15
|
+
@response.code
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
@parser.to_hash(@response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_parser(is_json)
|
29
|
+
return FormatHandlers::JsonResponseParser.new if is_json
|
30
|
+
FormatHandlers::CsvResponseParser.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'actions/addresses'
|
2
|
+
require_relative 'actions/drivers'
|
3
|
+
require_relative 'actions/events'
|
4
|
+
require_relative 'actions/geocoding'
|
5
|
+
require_relative 'actions/messages'
|
6
|
+
require_relative 'actions/miscellaneous'
|
7
|
+
require_relative 'actions/objects'
|
8
|
+
require_relative 'actions/orders'
|
9
|
+
require_relative 'actions/trips'
|
10
|
+
require_relative 'connection'
|
11
|
+
|
12
|
+
module WebfleetConnect
|
13
|
+
class WebfleetConnect::Session
|
14
|
+
include Actions::Addresses
|
15
|
+
include Actions::Drivers
|
16
|
+
include Actions::Events
|
17
|
+
include Actions::Geocoding
|
18
|
+
include Actions::Messages
|
19
|
+
include Actions::Miscellaneous
|
20
|
+
include Actions::Objects
|
21
|
+
include Actions::Orders
|
22
|
+
include Actions::Trips
|
23
|
+
|
24
|
+
def initialize(credentials, config)
|
25
|
+
@credentials = credentials
|
26
|
+
@config = config
|
27
|
+
@connection = Connection.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def json?
|
31
|
+
@config.json?
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def exec(action)
|
37
|
+
@connection.exec(url(action))
|
38
|
+
end
|
39
|
+
|
40
|
+
def url(action)
|
41
|
+
"#{@config}&#{@credentials}&#{action}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/webfleet_connect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "webfleet_connect"
|
7
|
+
spec.version = WebfleetConnect::VERSION
|
8
|
+
spec.authors = ["alex"]
|
9
|
+
spec.email = ["alex.guajardo@movomx.com"]
|
10
|
+
|
11
|
+
spec.summary = "Gem to consume Webfleet connect api."
|
12
|
+
spec.description = "The WEBFLEET.connect API connects software applications with the Webfleet fleet management solution. Via WEBFLEET.connect you can enhance the value of all types of business solutions, including routing and scheduling optimization, ERP, Transport Management System (TMS), supply chain planning, asset management, and much more."
|
13
|
+
spec.homepage = "https://movomx.com"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = "https://github.com/movomx/webfleet_connect"
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/movomx/webfleet_connect"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/movomx/webfleet_connect"
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency 'httparty', "~> 0.21.0"
|
30
|
+
spec.add_dependency 'json', '2.6.3'
|
31
|
+
spec.add_dependency 'csv', '~> 3.2', '>= 3.2.7'
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
33
|
+
end
|