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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4d9d024306e053461eb5a659b7303a57d24dbac
4
- data.tar.gz: 9acc3c5fea08bbb1716dfacfe0b4d13b067c66e2
3
+ metadata.gz: 6c00b46bb329ab2417b663b65cd8176334dfcf0d
4
+ data.tar.gz: 7df4debe629b14817e072d820c502db6a5e735e1
5
5
  SHA512:
6
- metadata.gz: 97f8bb34c364fba26b03511bd5f408debe0f1846d0dd01cecb91b51f0e7ecdd6647ea1d00e2fa8e1fedd18fedeee77d1ce151b6510070ff54b2928ad32a8753f
7
- data.tar.gz: d4480f608986fa596f95522f33c29ff9555f62466ea7467da839a3f754b7ba3dd012c1d2b032ca4b9a43325ecc18a6c1f6bdc8db0abea8c7816216678b7dc97c
6
+ metadata.gz: 1c86955f1d57268c937b42af9ab258fc344151d434b2bc6abffa23548fdcd8997502598eca9ce6f5831ac21302680ba95895637a798dbcf129b690a26fcc2cb4
7
+ data.tar.gz: a0fec7713219c1c62d5f02ba312b291e0b13345a86def168965db92bd5fc8412977a9b273fcb8e47046309817cf4f2831f53284f4f418ab13095bbb525494589
@@ -2,6 +2,7 @@ module Kerio
2
2
  module Api
3
3
  module ChainableMethod
4
4
  def next_method(params)
5
+
5
6
  # prefer special implementation over the generic one
6
7
  begin
7
8
  source = "kerio-api/method/#{params[:names].join('/')}.rb".downcase
@@ -12,7 +12,7 @@ module Kerio
12
12
  end
13
13
 
14
14
  def method_missing(method, *args, &block)
15
- return next_method(names: [method], session: @session, args: args)
15
+ return next_method(names: [method], session: @session, args: args, block: block)
16
16
  end
17
17
  end
18
18
  end
@@ -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
@@ -12,6 +12,8 @@ module Kerio
12
12
 
13
13
  @args = params[:args]
14
14
 
15
+ @block = params[:block]
16
+
15
17
  __invoke_method if @args.count > 0
16
18
  end
17
19
 
@@ -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: 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': file,
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.2.2
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-20 00:00:00.000000000 Z
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