kerio-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/kerio-api/client.rb +24 -0
- data/lib/kerio-api/error.rb +17 -0
- data/lib/kerio-api/interface/generic.rb +16 -0
- data/lib/kerio-api/interface/session.rb +21 -0
- data/lib/kerio-api/session.rb +48 -0
- data/lib/kerio-api.rb +1 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c84a63b49e50725a033fa58373f24f2509bb072
|
4
|
+
data.tar.gz: def9e00fbe091d5e8fd074b804d532a2c870d746
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c07e1c60adea63977606639c5491f0912ad1a54b16c065452a0507159e1028c1f0e374aa7967fdef39fd0e8cb564361e587e620309bb79cda266c3ae64b0690a
|
7
|
+
data.tar.gz: 240f2f7ec93062ba4b28fb97653010e89952250ffdec2d5ad5f024696e2d5c99aba352bd429ac17012b54a3ed558a68a04ae18f94ec828a15deca0acc7889515
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'kerio-api/session'
|
2
|
+
require 'kerio-api/interface/generic'
|
3
|
+
require 'kerio-api/interface/session'
|
4
|
+
|
5
|
+
module Kerio
|
6
|
+
module Api
|
7
|
+
class Client
|
8
|
+
def initialize (params)
|
9
|
+
|
10
|
+
@session = Kerio::Api::Session.new(params[:url])
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args, &block)
|
14
|
+
|
15
|
+
# prefer special implementation over the generic one
|
16
|
+
return Kerio::Api::Interface.const_get(method).new(method, @session)
|
17
|
+
|
18
|
+
rescue NameError
|
19
|
+
|
20
|
+
return Kerio::Api::Interface::Generic.new(method, @session)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kerio
|
2
|
+
module Api
|
3
|
+
module Interface
|
4
|
+
class Generic
|
5
|
+
def initialize (name, session)
|
6
|
+
@name = name
|
7
|
+
@session = session
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
return @session.request("#{@name}.#{method}", args[0])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'kerio-api/interface/generic'
|
2
|
+
|
3
|
+
module Kerio
|
4
|
+
module Api
|
5
|
+
module Interface
|
6
|
+
class Session < Kerio::Api::Interface::Generic
|
7
|
+
|
8
|
+
# we need special implementation of login method to remember the token
|
9
|
+
def login(params)
|
10
|
+
|
11
|
+
result = @session.request(
|
12
|
+
'Session.login',
|
13
|
+
params,
|
14
|
+
)
|
15
|
+
|
16
|
+
@session.token = result['token']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
3
|
+
require 'kerio-api/error'
|
4
|
+
|
5
|
+
module Kerio
|
6
|
+
module Api
|
7
|
+
class Session
|
8
|
+
|
9
|
+
attr_writer :token
|
10
|
+
|
11
|
+
def initialize(url)
|
12
|
+
@url = url
|
13
|
+
|
14
|
+
@token = nil
|
15
|
+
@cookie = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def request(method, params)
|
19
|
+
body = {
|
20
|
+
jsonrpc: '2.0',
|
21
|
+
id: Kernel.rand(10**12),
|
22
|
+
method: method,
|
23
|
+
params: params,
|
24
|
+
}
|
25
|
+
body['token'] = @token if not @token.nil?
|
26
|
+
|
27
|
+
headers = {
|
28
|
+
'Accept' => 'application/json-rpc',
|
29
|
+
}
|
30
|
+
headers['X-Token'] = @token if not @token.nil?
|
31
|
+
headers['Cookie'] = @cookie if not @cookie.nil?
|
32
|
+
|
33
|
+
resp = HTTParty.post(
|
34
|
+
@url.to_s,
|
35
|
+
body: JSON.generate(body),
|
36
|
+
headers: headers,
|
37
|
+
verify: false,
|
38
|
+
follow_redirects: true,
|
39
|
+
)
|
40
|
+
@cookie = resp.headers['Set-Cookie'] if not resp.headers['Set-Cookie'].nil?
|
41
|
+
|
42
|
+
raise Kerio::Api::Error.new(resp, headers) if not resp["error"].nil?
|
43
|
+
|
44
|
+
return resp["result"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/kerio-api.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'kerio-api/client'
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kerio-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Petr Baloun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem allows simple access to administration API of Kerio products
|
70
|
+
email: balounp@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/kerio-api.rb
|
76
|
+
- lib/kerio-api/client.rb
|
77
|
+
- lib/kerio-api/error.rb
|
78
|
+
- lib/kerio-api/interface/generic.rb
|
79
|
+
- lib/kerio-api/interface/session.rb
|
80
|
+
- lib/kerio-api/session.rb
|
81
|
+
homepage: https://github.com/balous/ruby-kerio-api
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Client library to access administration API of Kerio products
|
105
|
+
test_files: []
|