kerio-api 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kerio-api/client.rb +6 -5
- data/lib/kerio-api/error.rb +21 -4
- data/lib/kerio-api/method/generic.rb +3 -4
- data/lib/kerio-api/session.rb +2 -2
- metadata +15 -2
- data/lib/kerio-api/method/session/logout.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed1d374f7e67728c9f81ee24c8c484adb617d85c
|
4
|
+
data.tar.gz: 5cc20455c029cc1c11b9e3bf447f3079eff7aca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05b48afc2d4064f818befd652001380d7bf173f92794ad8e9387dbcdee72fe9d1e97101e712ecf84011dd21ecffd5917af0868dbcc20e1fa4bc1cdfd71468cf
|
7
|
+
data.tar.gz: 22dac90f622f009efccb0f843f186afd77a782ac11f155be876984e487af8cd77584af2a83aa98444d35a817bbf37051e1576d803dd342ae41da3df078e4cae6
|
data/lib/kerio-api/client.rb
CHANGED
@@ -7,12 +7,13 @@ module Kerio
|
|
7
7
|
class Client
|
8
8
|
include Kerio::Api::ChainableMethod
|
9
9
|
|
10
|
-
|
10
|
+
# Create new instance of the client
|
11
|
+
#
|
12
|
+
# @param url [URL] an URL of the API endpoint
|
13
|
+
# @param insecure [TrueClass] whether to ignore ssl verification error (true/false)
|
14
|
+
def initialize (url: nil, insecure: false)
|
11
15
|
|
12
|
-
|
13
|
-
verify_ssl = !params[:insecure] if not params[:insecure].nil?
|
14
|
-
|
15
|
-
@session = Kerio::Api::Session.new(params[:url], verify_ssl)
|
16
|
+
@session = Kerio::Api::Session.new(url, !insecure)
|
16
17
|
end
|
17
18
|
|
18
19
|
def method_missing(method, *args, &block)
|
data/lib/kerio-api/error.rb
CHANGED
@@ -2,15 +2,32 @@ module Kerio
|
|
2
2
|
module Api
|
3
3
|
class Error < StandardError
|
4
4
|
|
5
|
-
|
5
|
+
# Returns HTTP response as returned by used http library
|
6
|
+
attr_reader :resp
|
6
7
|
|
7
|
-
def initialize resp
|
8
|
+
def initialize resp
|
8
9
|
@resp = resp
|
9
|
-
@headers = headers
|
10
10
|
end
|
11
11
|
|
12
|
+
# Returns HTTP headers returned by the server
|
13
|
+
def headers
|
14
|
+
return @resp.headers
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns HTTP code returned by the server
|
18
|
+
def code
|
19
|
+
return @resp.code
|
20
|
+
end
|
21
|
+
|
22
|
+
# Formats human readable error message
|
12
23
|
def to_s
|
13
|
-
|
24
|
+
s = "Http code: #{code}"
|
25
|
+
|
26
|
+
if not @resp["jsonrpc"].nil?
|
27
|
+
s += ", json-rpc message: #{@resp["error"]["message"]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
return s
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|
@@ -14,18 +14,17 @@ module Kerio
|
|
14
14
|
|
15
15
|
@block = params[:block]
|
16
16
|
|
17
|
-
|
17
|
+
if ((@args.count > 0) || (@names.count == 2))
|
18
|
+
__invoke_method
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def __invoke_method
|
21
|
-
if @resp.nil?
|
22
23
|
name = @names.join('.')
|
23
24
|
@resp = @session.json_method(name, @args[0])
|
24
|
-
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def __result
|
28
|
-
__invoke_method
|
29
28
|
return @resp['result']
|
30
29
|
end
|
31
30
|
|
data/lib/kerio-api/session.rb
CHANGED
@@ -28,7 +28,7 @@ module Kerio
|
|
28
28
|
def process_json_response(resp)
|
29
29
|
@cookie = resp.headers['Set-Cookie'] if not resp.headers['Set-Cookie'].nil?
|
30
30
|
|
31
|
-
raise Kerio::Api::Error.new(resp
|
31
|
+
raise Kerio::Api::Error.new(resp) if ((not resp["error"].nil?) || (resp.code != 200))
|
32
32
|
end
|
33
33
|
|
34
34
|
def json_method(name, params)
|
@@ -91,7 +91,7 @@ module Kerio
|
|
91
91
|
yield fragment
|
92
92
|
end
|
93
93
|
|
94
|
-
raise Kerio::Api::Error.new(resp
|
94
|
+
raise Kerio::Api::Error.new(resp) if resp.code != 200
|
95
95
|
|
96
96
|
return {"result" => {"code" => resp.code}}
|
97
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kerio-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Baloun
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.5
|
97
111
|
description: This gem allows simple access to administration API of Kerio products
|
98
112
|
email: balounp@gmail.com
|
99
113
|
executables: []
|
@@ -107,7 +121,6 @@ files:
|
|
107
121
|
- lib/kerio-api/method/download.rb
|
108
122
|
- lib/kerio-api/method/generic.rb
|
109
123
|
- lib/kerio-api/method/session/login.rb
|
110
|
-
- lib/kerio-api/method/session/logout.rb
|
111
124
|
- lib/kerio-api/method/upload.rb
|
112
125
|
- lib/kerio-api/session.rb
|
113
126
|
homepage: https://github.com/balous/ruby-kerio-api
|