wialon_api 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +5 -0
- data/lib/generators/wialon_api/install/templates/initializer.rb +3 -0
- data/lib/wialon_api/api.rb +1 -1
- data/lib/wialon_api/authorization.rb +1 -5
- data/lib/wialon_api/configuration.rb +19 -0
- data/lib/wialon_api/version.rb +1 -1
- data/spec/wialon_api/authorization_spec.rb +0 -10
- data/spec/wialon_api/configuration_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837b4373fd4679f2e4ff1836a4a0e5539a13e938
|
4
|
+
data.tar.gz: 2546fbb21ba7c2485bcec73cafebcccbff59e742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0428f8f6cff58ff21817135e088a0270bbeec42c153f956fd99526c1d6bab64337a1c94e0b77d46c74556a8b5daad2fcaceb380b9251244ecfbc9b6c2aa5b4c2
|
7
|
+
data.tar.gz: b599c28dd28a925035335516c51cd28d5f6ff0aac93de75c224cb6ac210571137dbd20b7818bfda5bd550c400732ee85d253e3474ae3f57f38d87851ceebd64f
|
data/README.md
CHANGED
@@ -143,9 +143,14 @@ WialonApi.configure do |config|
|
|
143
143
|
|
144
144
|
# Wialon server host
|
145
145
|
# config.wialon_host = 'https://hst-api.wialon.com/wialon/ajax.html'
|
146
|
+
|
147
|
+
# Wialon server edition: :hosting, :local, :pro
|
148
|
+
# config.wialon_edition = :hosting
|
146
149
|
end
|
147
150
|
```
|
148
151
|
|
152
|
+
Note that `Wialon Pro` edition uses different parameters in requests, e.g. `ssid` vs `eid` as the session identifier. `WialonApi` gem handles these differences automatically.
|
153
|
+
|
149
154
|
`Net::HTTP` is used by default for a HTTP requests. One can choose any [other adapter](https://github.com/technoweenie/faraday/blob/master/lib/faraday/adapter.rb) suported by `faraday`.
|
150
155
|
|
151
156
|
Options for faraday connection (e.g. proxy settings or SSL certificates path) could be set through `faraday_options` when configuring `wialon_api`
|
data/lib/wialon_api/api.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
module WialonApi
|
4
4
|
module Api
|
5
5
|
def self.call(service_name, args = {}, sid = nil)
|
6
|
-
parameters = { svc: service_name, params: args.to_json,
|
6
|
+
parameters = { svc: service_name, params: args.to_json, WialonApi.wialon_session_identifier => sid }
|
7
7
|
connection(url: WialonApi.wialon_host).send(WialonApi.http_verb, nil, parameters).body
|
8
8
|
end
|
9
9
|
|
@@ -3,11 +3,7 @@ module WialonApi
|
|
3
3
|
def authorize(user, password)
|
4
4
|
response = WialonApi::Api.call('core/login', user: user, password: password)
|
5
5
|
result = WialonApi::Result.process(response)
|
6
|
-
|
7
|
-
WialonApi::Client.new(result.ssid)
|
8
|
-
else
|
9
|
-
WialonApi::Client.new(result.eid)
|
10
|
-
end
|
6
|
+
WialonApi::Client.new(result.send(WialonApi.wialon_client_session_identifier))
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
@@ -17,12 +17,21 @@ module WialonApi
|
|
17
17
|
|
18
18
|
attr_accessor(*OPTION_NAMES)
|
19
19
|
|
20
|
+
READ_ONLY_OPTIONS = [
|
21
|
+
:wialon_session_identifier,
|
22
|
+
:wialon_client_session_identifier
|
23
|
+
]
|
24
|
+
|
25
|
+
attr_reader(*READ_ONLY_OPTIONS)
|
26
|
+
|
20
27
|
alias_method :log_requests?, :log_requests
|
21
28
|
alias_method :log_errors?, :log_errors
|
22
29
|
alias_method :log_responses?, :log_responses
|
23
30
|
|
24
31
|
DEFAULT_WIALON_HOST = 'https://hst-api.wialon.com/wialon/ajax.html'
|
25
32
|
DEFAULT_WIALON_EDITION = :hosting
|
33
|
+
DEFAULT_SESSION_IDENTIFIER = :sid
|
34
|
+
DEFAULT_CLIENT_SESSION_IDENTIFIER = :eid
|
26
35
|
DEFAULT_HTTP_VERB = :post
|
27
36
|
DEFAULT_MAX_RETRIES = 1
|
28
37
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
@@ -40,6 +49,8 @@ module WialonApi
|
|
40
49
|
def reset
|
41
50
|
@wialon_host = DEFAULT_WIALON_HOST
|
42
51
|
@wialon_edition = DEFAULT_WIALON_EDITION
|
52
|
+
@wialon_session_identifier = DEFAULT_SESSION_IDENTIFIER
|
53
|
+
@wialon_client_session_identifier = DEFAULT_CLIENT_SESSION_IDENTIFIER
|
43
54
|
@http_verb = DEFAULT_HTTP_VERB
|
44
55
|
@max_retries = DEFAULT_MAX_RETRIES
|
45
56
|
@faraday_options = {}
|
@@ -53,5 +64,13 @@ module WialonApi
|
|
53
64
|
def self.extended(base)
|
54
65
|
base.reset
|
55
66
|
end
|
67
|
+
|
68
|
+
def wialon_edition=(edition)
|
69
|
+
@wialon_edition = edition
|
70
|
+
if edition == :pro
|
71
|
+
@wialon_session_identifier = :ssid
|
72
|
+
@wialon_client_session_identifier = :ssid
|
73
|
+
end
|
74
|
+
end
|
56
75
|
end
|
57
76
|
end
|
data/lib/wialon_api/version.rb
CHANGED
@@ -12,16 +12,6 @@ describe WialonApi::Authorization do
|
|
12
12
|
WialonApi.authorize(*credentials)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "uses ssid with wialon pro edition" do
|
16
|
-
success = Hashie::Mash.new(ssid: 'sid')
|
17
|
-
allow(WialonApi::Api).to receive(:call).and_return(success)
|
18
|
-
WialonApi.configure do |config|
|
19
|
-
config.wialon_edition = :pro
|
20
|
-
end
|
21
|
-
expect(WialonApi::Client).to receive(:new).with('sid')
|
22
|
-
WialonApi.authorize(*credentials)
|
23
|
-
end
|
24
|
-
|
25
15
|
it 'raises an error if password or login do not match' do
|
26
16
|
allow(WialonApi::Api).to receive(:call).and_return(error)
|
27
17
|
expect { WialonApi.authorize(*credentials) }.to raise_error(WialonApi::Error)
|
@@ -22,6 +22,8 @@ describe WialonApi::Configuration do
|
|
22
22
|
TestConfiguration.reset
|
23
23
|
expect(TestConfiguration.wialon_host).to eq('https://hst-api.wialon.com/wialon/ajax.html')
|
24
24
|
expect(TestConfiguration.wialon_edition).to eq(:hosting)
|
25
|
+
expect(TestConfiguration.wialon_session_identifier).to eq(:sid)
|
26
|
+
expect(TestConfiguration.wialon_client_session_identifier).to eq(:eid)
|
25
27
|
expect(TestConfiguration.http_verb).to eq(:post)
|
26
28
|
expect(TestConfiguration.max_retries).to eq(1)
|
27
29
|
expect(TestConfiguration.faraday_options).to eq({})
|
@@ -33,4 +35,21 @@ describe WialonApi::Configuration do
|
|
33
35
|
expect(TestConfiguration.log_responses).not_to eq(true)
|
34
36
|
end
|
35
37
|
end
|
38
|
+
|
39
|
+
describe 'Wialon edition specific params' do
|
40
|
+
describe 'Pro edition' do
|
41
|
+
before do
|
42
|
+
TestConfiguration.reset
|
43
|
+
TestConfiguration.configure do |config|
|
44
|
+
config.wialon_edition = :pro
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sets pro edition params when setting edition' do
|
49
|
+
expect(TestConfiguration.wialon_edition).to eq(:pro)
|
50
|
+
expect(TestConfiguration.wialon_session_identifier).to eq(:ssid)
|
51
|
+
expect(TestConfiguration.wialon_client_session_identifier).to eq(:ssid)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
36
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wialon_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arsen Shamkhalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|