kerio-api 0.2.2 → 0.3.0
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/chainable_method.rb +1 -0
- data/lib/kerio-api/client.rb +1 -1
- data/lib/kerio-api/method/download.rb +18 -0
- data/lib/kerio-api/method/generic.rb +2 -0
- data/lib/kerio-api/session.rb +28 -5
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c00b46bb329ab2417b663b65cd8176334dfcf0d
|
4
|
+
data.tar.gz: 7df4debe629b14817e072d820c502db6a5e735e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c86955f1d57268c937b42af9ab258fc344151d434b2bc6abffa23548fdcd8997502598eca9ce6f5831ac21302680ba95895637a798dbcf129b690a26fcc2cb4
|
7
|
+
data.tar.gz: a0fec7713219c1c62d5f02ba312b291e0b13345a86def168965db92bd5fc8412977a9b273fcb8e47046309817cf4f2831f53284f4f418ab13095bbb525494589
|
data/lib/kerio-api/client.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Kerio
|
4
|
+
module Api
|
5
|
+
module Method
|
6
|
+
class Download < Kerio::Api::Method::Generic
|
7
|
+
|
8
|
+
def __invoke_method
|
9
|
+
if @resp.nil?
|
10
|
+
@resp = @session.download_file(@args[0]) do |fragment|
|
11
|
+
@block.call fragment
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/kerio-api/session.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'httmultiparty'
|
3
|
+
require 'httparty'
|
3
4
|
require 'kerio-api/error'
|
5
|
+
require 'uri'
|
4
6
|
|
5
7
|
module Kerio
|
6
8
|
module Api
|
@@ -15,9 +17,7 @@ module Kerio
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def headers
|
18
|
-
headers = {
|
19
|
-
'Accept' => 'application/json-rpc',
|
20
|
-
}
|
20
|
+
headers = {}
|
21
21
|
headers['X-Token'] = @token if not @token.nil?
|
22
22
|
headers['Cookie'] = @cookie if not @cookie.nil?
|
23
23
|
|
@@ -32,6 +32,9 @@ module Kerio
|
|
32
32
|
|
33
33
|
def json_method(name, params)
|
34
34
|
|
35
|
+
h = headers
|
36
|
+
h['Accept'] = 'application/json-rpc'
|
37
|
+
|
35
38
|
body = {
|
36
39
|
jsonrpc: '2.0',
|
37
40
|
id: Kernel.rand(10**12),
|
@@ -43,7 +46,7 @@ module Kerio
|
|
43
46
|
resp = HTTMultiParty.post(
|
44
47
|
@url.to_s,
|
45
48
|
body: JSON.generate(body),
|
46
|
-
headers:
|
49
|
+
headers: h,
|
47
50
|
verify: false,
|
48
51
|
follow_redirects: true,
|
49
52
|
)
|
@@ -62,13 +65,33 @@ module Kerio
|
|
62
65
|
headers: h,
|
63
66
|
verify: false,
|
64
67
|
query: {
|
65
|
-
'newFile.bin'
|
68
|
+
'newFile.bin' => file,
|
66
69
|
}
|
67
70
|
)
|
68
71
|
|
69
72
|
process_json_response(resp)
|
70
73
|
return resp
|
71
74
|
end
|
75
|
+
|
76
|
+
def download_file(path)
|
77
|
+
h = headers
|
78
|
+
h['Accept'] = '*/*'
|
79
|
+
|
80
|
+
u = URI.parse("#{@url.scheme}://#{@url.host}:#{@url.port}#{path}")
|
81
|
+
|
82
|
+
resp = HTTParty.get(
|
83
|
+
u.to_s,
|
84
|
+
headers: h,
|
85
|
+
verify: false,
|
86
|
+
stream_body: true,
|
87
|
+
) do |fragment|
|
88
|
+
yield fragment
|
89
|
+
end
|
90
|
+
|
91
|
+
raise Kerio::Api::Error.new(resp, headers) if resp.code != 200
|
92
|
+
|
93
|
+
return {"result" => {"code" => resp.code}}
|
94
|
+
end
|
72
95
|
end
|
73
96
|
end
|
74
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kerio-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Baloun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httmultiparty
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.3.16
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.14.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: json
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +104,7 @@ files:
|
|
90
104
|
- lib/kerio-api/chainable_method.rb
|
91
105
|
- lib/kerio-api/client.rb
|
92
106
|
- lib/kerio-api/error.rb
|
107
|
+
- lib/kerio-api/method/download.rb
|
93
108
|
- lib/kerio-api/method/generic.rb
|
94
109
|
- lib/kerio-api/method/session/login.rb
|
95
110
|
- lib/kerio-api/method/session/logout.rb
|