wialon 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/wialon.rb +131 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37bef448770643db031153bab5ad33b5ad30dd25
|
4
|
+
data.tar.gz: c0a2ab27ecf772c15a91c2e49fb94542d0469cba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a951cf4cb4e809f4a47e0b4fc46eee9f4a798b0a72639871c8ecde142518540a08a5dc476ab45b703987ca8f23d916404d565f0c4ac6ed50c0041a44b87b101
|
7
|
+
data.tar.gz: 94eb30173c3b297ee419b78ff920ec75d8b95acf1c956b04cdfda5e4f18de296aac65bfbde05e620b8ea9bf77af4dca8a916e6505cbecd0cf3259cc2878c7c33
|
data/lib/wialon.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
class Wialon
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
# Variables
|
7
|
+
attr_accessor :sid, :base_api_url, :default_params, :uid, :host, :scheme
|
8
|
+
|
9
|
+
# Class constructor
|
10
|
+
def initialize(scheme = 'https', host = 'hst-api.wialon.com', port = '', sid = '', extra_params = {})
|
11
|
+
self.sid = ''
|
12
|
+
self.scheme = scheme
|
13
|
+
self.default_params = {}
|
14
|
+
self.default_params.replace(extra_params)
|
15
|
+
self.host = host
|
16
|
+
self.base_api_url = "#{scheme}://#{host}#{((port.length > 0) ? ":" + port.to_s : "")}/wialon/ajax.html?"
|
17
|
+
self.uid = ''
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_address(lat, lon)
|
21
|
+
uri = URI.parse('https://geocode-maps.wialon.com/' + self.host + '/gis_geocode?coords=[' + JSON.generate({"lon": lon,"lat": lat}) + ']&flags=1255211008&uid=' + self.uid.to_s)
|
22
|
+
request = Net::HTTP::Post.new(uri)
|
23
|
+
req_options = { use_ssl: uri.scheme == self.scheme }
|
24
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
25
|
+
http.request(request)
|
26
|
+
end
|
27
|
+
return JSON.parse(response.body)[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_coordinates(string)
|
31
|
+
string = string.split(" ").join(" ")
|
32
|
+
from = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"
|
33
|
+
to = "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
|
34
|
+
string = string.tr(from,to)
|
35
|
+
|
36
|
+
uri = URI.parse('https://search-maps.wialon.com/' + self.host + '/gis_searchintelli?phrase=' + string + '&count=1&indexFrom=0&uid=' + self.uid.to_s)
|
37
|
+
request = Net::HTTP::Post.new(uri)
|
38
|
+
req_options = { use_ssl: uri.scheme == self.scheme }
|
39
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
40
|
+
http.request(request)
|
41
|
+
end
|
42
|
+
|
43
|
+
return JSON.parse(response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
# RemoteAPI request performer
|
47
|
+
# action: RemoteAPI command name
|
48
|
+
# args: JSON string with request parameters
|
49
|
+
def call(action, args)
|
50
|
+
# Set local variable with base url
|
51
|
+
url = self.base_api_url
|
52
|
+
|
53
|
+
# Set params
|
54
|
+
params = {'svc': action.to_s.sub('_', '/'), 'params': JSON.generate(args), 'sid': self.sid}
|
55
|
+
|
56
|
+
# Replacing global params with local params
|
57
|
+
all_params = self.default_params.replace(params)
|
58
|
+
|
59
|
+
# Initializing string
|
60
|
+
str = ""
|
61
|
+
# Params each cycle with index
|
62
|
+
all_params.each do |slug, param|
|
63
|
+
# If string length is upper to 0, include "&" to include all params
|
64
|
+
if str.length > 0
|
65
|
+
str += "&"
|
66
|
+
end
|
67
|
+
str += slug.to_s + "=" + param
|
68
|
+
end
|
69
|
+
|
70
|
+
# Curl request
|
71
|
+
puts url + str
|
72
|
+
uri = URI.parse(url + str)
|
73
|
+
|
74
|
+
request = Net::HTTP::Post.new(uri)
|
75
|
+
|
76
|
+
req_options = { use_ssl: uri.scheme == self.scheme }
|
77
|
+
|
78
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
79
|
+
http.request(request)
|
80
|
+
end
|
81
|
+
|
82
|
+
response = JSON.parse(response.body)
|
83
|
+
|
84
|
+
return response
|
85
|
+
end
|
86
|
+
|
87
|
+
def login(token)
|
88
|
+
data = {token: token}
|
89
|
+
result = self.token_login(data)
|
90
|
+
if !result['eid'].nil?
|
91
|
+
self.sid = result['eid']
|
92
|
+
end
|
93
|
+
|
94
|
+
if !result['user']['id'].nil?
|
95
|
+
self.uid = result['user']['id']
|
96
|
+
end
|
97
|
+
|
98
|
+
puts "Here"
|
99
|
+
return result
|
100
|
+
end
|
101
|
+
|
102
|
+
def logout
|
103
|
+
result = self.core_logout()
|
104
|
+
if result.empty? && result['error'] == 0
|
105
|
+
self.sid = ""
|
106
|
+
end
|
107
|
+
return result
|
108
|
+
end
|
109
|
+
|
110
|
+
# Unknonwn methods handler
|
111
|
+
def method_missing(name, *args)
|
112
|
+
puts "#{name}"
|
113
|
+
return self.call(name, ((args.count === 0) ? '{}' : args[0]))
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
# SID setter
|
118
|
+
def set_sid(sid)
|
119
|
+
self.sid = sid
|
120
|
+
end
|
121
|
+
|
122
|
+
# SID getter
|
123
|
+
def get_sid
|
124
|
+
return self.sid
|
125
|
+
end
|
126
|
+
|
127
|
+
# Update extra parameters
|
128
|
+
def update_extra_params(params)
|
129
|
+
self.default_params.replace(params)
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wialon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenny Mochizuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Wialon class for Wialon Remote API
|
14
|
+
email: kenny.mochiuki@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/wialon.rb
|
20
|
+
homepage: http://rubygems.org/gems/wialon-ruby
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.13
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Wialon Remote API Gem
|
44
|
+
test_files: []
|