wialon 1.0.0 → 1.1.0
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 +5 -5
- data/lib/wialon.rb +75 -23
- data/lib/wialon_error.rb +39 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4283353117672ce224554a65bdcd7ca86e93f887fb7fd1508d26a0e92334104f
|
4
|
+
data.tar.gz: 24d7d1123a83c6f18d526b27b24dfbfc66bb88bdf4aee5cf641c20f903b7b58d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 981599957855829ec11183f33a1c5cb737000fc0ee7d7205b4c7812abf86a51698084b4cf457dd25f8290aa5fc25fb762a972655adb09b3c62b4436ee8925b25
|
7
|
+
data.tar.gz: e0f4242e244bf01b6e6ac4ba6d149548fcad2a7c776a662d50c1394065e4f16f19417ecea49e84323225502cff48c4d45d695ce89b890de80f0411d518ece235
|
data/lib/wialon.rb
CHANGED
@@ -4,10 +4,11 @@ class Wialon
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
# Variables
|
7
|
-
attr_accessor :sid, :base_api_url, :default_params, :uid, :host, :scheme
|
7
|
+
attr_accessor :sid, :base_api_url, :default_params, :uid, :host, :scheme, :debug
|
8
8
|
|
9
9
|
# Class constructor
|
10
|
-
def initialize(scheme = 'https', host = 'hst-api.wialon.com', port = '', sid = '', extra_params = {})
|
10
|
+
def initialize(debug = false, scheme = 'https', host = 'hst-api.wialon.com', port = '', sid = '', extra_params = {})
|
11
|
+
self.debug = debug
|
11
12
|
self.sid = ''
|
12
13
|
self.scheme = scheme
|
13
14
|
self.default_params = {}
|
@@ -17,8 +18,11 @@ class Wialon
|
|
17
18
|
self.uid = ''
|
18
19
|
end
|
19
20
|
|
20
|
-
def get_address(lat, lon)
|
21
|
-
|
21
|
+
def get_address(lat, lon, flags = 1255211008)
|
22
|
+
if self.debug
|
23
|
+
puts "URL: #{'https://geocode-maps.wialon.com/' + self.host + '/gis_geocode?coords=[' + JSON.generate({"lon": lon,"lat": lat}) + ']&flags=' + flags.to_s + '&uid=' + self.uid.to_s}"
|
24
|
+
end
|
25
|
+
uri = URI.parse('https://geocode-maps.wialon.com/' + self.host + '/gis_geocode?coords=[' + JSON.generate({"lon": lon,"lat": lat}) + ']&flags=' + flags.to_s + '&uid=' + self.uid.to_s)
|
22
26
|
request = Net::HTTP::Post.new(uri)
|
23
27
|
req_options = { use_ssl: uri.scheme == self.scheme }
|
24
28
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
@@ -43,6 +47,46 @@ class Wialon
|
|
43
47
|
return JSON.parse(response.body)
|
44
48
|
end
|
45
49
|
|
50
|
+
def call_without_svc_parse(action, args)
|
51
|
+
# Set local variable with base url
|
52
|
+
url = self.base_api_url
|
53
|
+
|
54
|
+
# Set params
|
55
|
+
params = {'svc': action.to_s, 'params': JSON.generate(args), 'sid': self.sid}
|
56
|
+
|
57
|
+
# Replacing global params with local params
|
58
|
+
all_params = self.default_params.replace(params)
|
59
|
+
|
60
|
+
if self.debug
|
61
|
+
puts "========="
|
62
|
+
puts "Query URL: #{url} - Params: #{all_params}"
|
63
|
+
puts "========="
|
64
|
+
puts "#{url}&svc=#{action.to_s}¶ms=#{JSON.generate(args)}&sid=#{self.sid}"
|
65
|
+
puts "========="
|
66
|
+
end
|
67
|
+
|
68
|
+
uri = URI.parse(url)
|
69
|
+
|
70
|
+
# Curl request
|
71
|
+
request = Net::HTTP::Post.new(uri)
|
72
|
+
|
73
|
+
request.set_form_data(
|
74
|
+
"svc" => action.to_s,
|
75
|
+
"params" => JSON.generate(args),
|
76
|
+
"sid" => self.sid
|
77
|
+
)
|
78
|
+
|
79
|
+
req_options = { use_ssl: uri.scheme == self.scheme }
|
80
|
+
|
81
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
82
|
+
http.request(request)
|
83
|
+
end
|
84
|
+
|
85
|
+
response = JSON.parse(response.body)
|
86
|
+
|
87
|
+
return response
|
88
|
+
end
|
89
|
+
|
46
90
|
# RemoteAPI request performer
|
47
91
|
# action: RemoteAPI command name
|
48
92
|
# args: JSON string with request parameters
|
@@ -56,23 +100,25 @@ class Wialon
|
|
56
100
|
# Replacing global params with local params
|
57
101
|
all_params = self.default_params.replace(params)
|
58
102
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
|
65
|
-
str += "&"
|
66
|
-
end
|
67
|
-
str += slug.to_s + "=" + param
|
103
|
+
if self.debug
|
104
|
+
puts "========="
|
105
|
+
puts "Query URL: #{url} - Params: #{all_params}"
|
106
|
+
puts "========="
|
107
|
+
puts "#{url}&svc=#{action.to_s.sub('_', '/')}¶ms=#{JSON.generate(args)}&sid=#{self.sid}"
|
108
|
+
puts "========="
|
68
109
|
end
|
69
110
|
|
70
|
-
|
71
|
-
puts url + str
|
72
|
-
uri = URI.parse(url + str)
|
111
|
+
uri = URI.parse(url)
|
73
112
|
|
113
|
+
# Curl request
|
74
114
|
request = Net::HTTP::Post.new(uri)
|
75
115
|
|
116
|
+
request.set_form_data(
|
117
|
+
"svc" => action.to_s.sub('_', '/'),
|
118
|
+
"params" => JSON.generate(args),
|
119
|
+
"sid" => self.sid
|
120
|
+
)
|
121
|
+
|
76
122
|
req_options = { use_ssl: uri.scheme == self.scheme }
|
77
123
|
|
78
124
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
@@ -85,17 +131,20 @@ class Wialon
|
|
85
131
|
end
|
86
132
|
|
87
133
|
def login(token)
|
88
|
-
|
89
|
-
result = self.token_login(data)
|
134
|
+
result = self.token_login({token: token})
|
90
135
|
if !result['eid'].nil?
|
91
136
|
self.sid = result['eid']
|
92
137
|
end
|
93
138
|
|
94
|
-
|
95
|
-
|
139
|
+
begin
|
140
|
+
if !result['user']['id'].nil?
|
141
|
+
self.uid = result['user']['id']
|
142
|
+
end
|
143
|
+
rescue Exception => e
|
144
|
+
if self.debug
|
145
|
+
puts "Error in login: #{e}"
|
146
|
+
end
|
96
147
|
end
|
97
|
-
|
98
|
-
puts "Here"
|
99
148
|
return result
|
100
149
|
end
|
101
150
|
|
@@ -109,7 +158,10 @@ class Wialon
|
|
109
158
|
|
110
159
|
# Unknonwn methods handler
|
111
160
|
def method_missing(name, *args)
|
112
|
-
|
161
|
+
if self.debug
|
162
|
+
puts "Query method: #{name}"
|
163
|
+
end
|
164
|
+
|
113
165
|
return self.call(name, ((args.count === 0) ? '{}' : args[0]))
|
114
166
|
end
|
115
167
|
|
data/lib/wialon_error.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class WialonError
|
2
|
+
attr_accessor :error
|
3
|
+
def initialize(error)
|
4
|
+
self.error = error
|
5
|
+
end
|
6
|
+
|
7
|
+
def message
|
8
|
+
@errors = {
|
9
|
+
'1' => "Invalid session",
|
10
|
+
'2' => "Invalid service name",
|
11
|
+
'3' => "Invalid result",
|
12
|
+
'4' => "Invalid input",
|
13
|
+
'5' => "Error performing request",
|
14
|
+
'6' => "Unknown error",
|
15
|
+
'7' => "Access denied",
|
16
|
+
'8' => "Invalid user name or password",
|
17
|
+
'9' => "Authorization server is unavailable",
|
18
|
+
'10' => "Reached limit of concurrent requests",
|
19
|
+
'11' => "Password reset error",
|
20
|
+
'14' => "Billing error",
|
21
|
+
'1001' => "No messages for selected interval",
|
22
|
+
'1002' => "Item with such unique property already exists or Item cannot be created according to billing restrictions",
|
23
|
+
'1003' => "Only one request is allowed at the moment",
|
24
|
+
'1004' => "Limit of messages has been exceeded",
|
25
|
+
'1005' => "Execution time has exceeded the limit",
|
26
|
+
'1006' => "Exceeding the limit of attempts to enter a two-factor authorization code",
|
27
|
+
'1011' => "Your IP has changed or session has expired",
|
28
|
+
'2014' => "Selected user is a creator for some system objects, thus this user cannot be bound to a new account",
|
29
|
+
'2015' => "Sensor deleting is forbidden because of using in another sensor or advanced properties of the unit"
|
30
|
+
}
|
31
|
+
|
32
|
+
response = {
|
33
|
+
original_message: self.error,
|
34
|
+
message: @errors[self.error['error'].to_s]
|
35
|
+
}
|
36
|
+
|
37
|
+
return response
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wialon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenny Mochizuki
|
8
|
+
- Golden M
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2018-08-26 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
|
-
description: Wialon
|
14
|
-
email:
|
14
|
+
description: Wialon gem wrapper for Remote API
|
15
|
+
email: support@goldenmcorp.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
19
20
|
- lib/wialon.rb
|
20
|
-
|
21
|
+
- lib/wialon_error.rb
|
22
|
+
homepage: http://rubygems.org/gems/wialon
|
21
23
|
licenses:
|
22
|
-
-
|
24
|
+
- CC-BY-NC-4.0
|
23
25
|
metadata: {}
|
24
26
|
post_install_message:
|
25
27
|
rdoc_options: []
|
@@ -37,8 +39,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
39
|
version: '0'
|
38
40
|
requirements: []
|
39
41
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.7.7
|
41
43
|
signing_key:
|
42
44
|
specification_version: 4
|
43
|
-
summary: Wialon Remote API
|
45
|
+
summary: Wialon gem wrapper for Remote API
|
44
46
|
test_files: []
|