tttelematics 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bdd512d7d7c164be169515f471c19b29be4d1b5a0b5d7ed2ebb1fe37f0d20f1f
4
+ data.tar.gz: 921b0b6584e92409a8bcde66b1a75f4e8a28e63e51fae3dff3d72397dd383968
5
+ SHA512:
6
+ metadata.gz: c7e80edcd9594631f44be89bc0956dd0447970850381fdbba1d5598b980de80601b50ee4870475d638d6155749e4fbd3c0665c9d6dea2d21bb4fe9aa46eb8790
7
+ data.tar.gz: 87cec370478191bfae88eb9156cd9b8c0630f9010095518745803733dbb054f22f9eeee04bc91461e4f579a8301552efd6b2d81adba85fb1adfbe28619fd66fb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 S·Fleet
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # TTTelematics
2
+ A simple ruby API Wrapper for TomTomTelematics
3
+
4
+ ## 1. Quick start
5
+
6
+ Install via Rubygems
7
+
8
+ ```ruby
9
+ gem install tttelematics
10
+ ```
11
+
12
+ ... or add to Gemfile
13
+
14
+ ```ruby
15
+ gem 'tttelematics'
16
+ ```
17
+
18
+ ## 2. Initialize Client
19
+
20
+ ```ruby
21
+ client = TTTelematics::API::Client.new('apikey','username','account','password')
22
+ ```
23
+
24
+
25
+ ## 3. Get Objects
26
+ For more options [Resources Objects TomTomTelematics](https://telematics.tomtom.com/static/help/webfleet-connect/en_gb/index.htm#Objects.htm).
27
+
28
+ ### 3.1 showObjectReportExtern
29
+ [More details](https://telematics.tomtom.com/static/help/webfleet-connect/en_gb/index.htm#showObjectReportExtern.htm)
30
+
31
+ ```ruby
32
+ #format = ['json','csv']
33
+ #client.asset.objects(options, format)
34
+
35
+ client.asset({objectno: 'OBJECTID'}, 'json')
36
+ or
37
+ asset = client.asset
38
+ objects = asset.objects({}, 'json')
39
+
40
+ asset = TTTelematics::API::Asset.new(client)
41
+ objects = asset({objectno: 'OBJECTID'}, 'json') #response a json
42
+
43
+ array_objects = JSON.parse(objects)
44
+ ```
45
+ ## 4. Errors
46
+ [More details](https://telematics.tomtom.com/static/help/webfleet-connect/en_gb/index.htm#Responsecodes-wfc.htm)
47
+
48
+ ```ruby
49
+ # Common Errors
50
+
51
+ TTTelematics::Err::InvalidAPIKey -> API key is invalid
52
+ TTTelematics::Err::InvalidUser -> User does not exist
53
+ TTTelematics::Err::InvalidAction -> Action is not valid
54
+
55
+
56
+ ```
@@ -0,0 +1,28 @@
1
+ module TTTelematics
2
+ module API
3
+ class Asset < Base
4
+ PERMIT_KEYS = ({ filterstring: 'string',
5
+ objectgroupname: 'string',
6
+ oungroupedonlye: 'string',
7
+ objectno: 'string',
8
+ objectuid: 'string',
9
+ externalid: 'string'}).freeze
10
+ ACTION_OBJECTS_METHOD = 'showObjectReportExtern'.freeze
11
+
12
+ def objects(options = {}, format = 'json')
13
+ validates(options,format)
14
+ request = Request.new(@client)
15
+ response = request.get(ACTION_OBJECTS_METHOD, options, format)
16
+ response.body
17
+ end
18
+
19
+ private
20
+ def validates(options, format)
21
+ raise ArgumentError unless Validator.check_keys?(PERMIT_KEYS, options)
22
+ raise TypeError unless Validator.check_type_values?(PERMIT_KEYS, options)
23
+ raise ArgumentError unless Validator.check_format?(format)
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module TTTelematics
2
+ module API
3
+ class Client
4
+ attr_reader :api_key, :username, :account, :password
5
+ def initialize(api_key, username, account, password)
6
+ raise TypeError unless validate_options?(api_key, username, account, password)
7
+ @api_key = api_key
8
+ @username = username
9
+ @account = account
10
+ @password = password
11
+ end
12
+
13
+ def asset
14
+ Asset.new(self)
15
+ end
16
+
17
+ private
18
+ def validate_options?(*args)
19
+ flag = true
20
+ args.each do |a|
21
+ flag = (!a.nil? && a.class == String && !a.empty?)
22
+ break unless flag
23
+ end
24
+ return flag
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module TTTelematics
2
+ module Err
3
+ class InvalidAPIKey < StandardError
4
+ def message
5
+ 'API key is invalid'
6
+ end
7
+ end
8
+
9
+ class InvalidUser < StandardError
10
+ def message
11
+ 'User does not exist'
12
+ end
13
+ end
14
+
15
+ class InvalidAction < StandardError
16
+ def message
17
+ 'action is not valid'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ module TTTelematics
2
+ module API
3
+ class Request < Base
4
+ require 'faraday'
5
+ require 'json'
6
+ require 'byebug'
7
+ LANG = 'en'.freeze
8
+ def get(action, params, format = 'json')
9
+ if (action.is_a?(String)) &&
10
+ !(action.nil?) &&
11
+ !(action.empty?)
12
+
13
+ params = generate_params(action, params, format)
14
+ response = Faraday.get(BASE_URL, params)
15
+ handle_response(response)
16
+ response
17
+ else
18
+ raise TypeError
19
+ end
20
+ end
21
+ private
22
+ def generate_params(action, params, format)
23
+ params = params
24
+ params[:action] = action
25
+ params[:outputformat] = format
26
+ params[:account] = @client.account
27
+ params[:apikey] = @client.api_key
28
+ params[:username] = @client.username
29
+ params[:password] = @client.password
30
+ params[:lang] = LANG
31
+ params
32
+ end
33
+
34
+ def handle_response(response)
35
+ body = JSON.parse(response.body)
36
+ begin
37
+ errCode = body['errorCode']
38
+ rescue TypeError
39
+ errCode = nil
40
+ end
41
+ unless errCode.nil?
42
+ raise TTTelematics::Err::InvalidAPIKey if body['errorCode'] == 1143
43
+ raise TTTelematics::Err::InvalidUser if body['errorCode'] == 1101
44
+ raise TTTelematics::Err::InvalidAction if body['errorCode'] == 55
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ module Validator
2
+ FORMAT_VALID = ['json', 'csv'].freeze
3
+ def self.check_keys?(permitted, options)
4
+ permitted_keys = permitted.keys.map(&:to_s)
5
+ option_keys = options.keys.map(&:to_s)
6
+ (option_keys - permitted_keys).size <= 0
7
+ end
8
+
9
+ def self.check_type_values?(permit_keys, values)
10
+ err_flag = true
11
+ values.each do |key, value|
12
+ type = permit_keys[key.to_sym]
13
+ if type == 'string'
14
+ err_flag = (value.is_a?(String))
15
+ elsif type == 'integer'
16
+ err_flag = (value.is_a?(Integer))
17
+ else
18
+ err_flag = false
19
+ end
20
+ break unless err_flag
21
+ end
22
+ err_flag
23
+ end
24
+
25
+ def self.check_format?(format)
26
+ FORMAT_VALID.include? format.to_s.downcase
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module TTTelematics
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,26 @@
1
+ #Modules
2
+ require_relative './TTTelematics/validator'
3
+
4
+ #Errors
5
+ require_relative './TTTelematics/err'
6
+
7
+ require_relative './TTTelematics/version'
8
+
9
+ module TTTelematics
10
+ module API
11
+ class Base
12
+ BASE_URL = 'https://csv.telematics.tomtom.com/extern'.freeze
13
+
14
+ def initialize(client)
15
+ raise TypeError if !(client.is_a?(Client))
16
+ @client = client
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ #classes
23
+ require_relative './TTTelematics/asset'
24
+ require_relative './TTTelematics/request'
25
+ require_relative './TTTelematics/client'
26
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tttelematics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alexei Mamani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.71.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.71.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
55
+ description: A simple API wrapper for Tom Tom Telematics
56
+ email: alexeim763@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.md
63
+ - lib/TTTelematics/asset.rb
64
+ - lib/TTTelematics/client.rb
65
+ - lib/TTTelematics/err.rb
66
+ - lib/TTTelematics/request.rb
67
+ - lib/TTTelematics/validator.rb
68
+ - lib/TTTelematics/version.rb
69
+ - lib/tttelematics.rb
70
+ homepage: https://github.com/s-fleet/tom_tom_telematics
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.7.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: a simple client for Tom Tom Telematics
94
+ test_files: []