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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f33843055272aaabc1ddbaa0528b64cc375815a
4
- data.tar.gz: 3ca7ed5d050f30fad86d41ee4b17c2499683f81f
3
+ metadata.gz: ed1d374f7e67728c9f81ee24c8c484adb617d85c
4
+ data.tar.gz: 5cc20455c029cc1c11b9e3bf447f3079eff7aca6
5
5
  SHA512:
6
- metadata.gz: 7b28b48ac50dc786cd61d4dbfe1755811980a078d06cf20d684fe979d08e9a083ef26527500f1de3610ea90ab5ad0e9ce7f0b47af7897a2331570e72f03bf379
7
- data.tar.gz: bb3daf474faca0629831d297c50d78469a34027cdb2a1a5a76c8be2501b47cb3b826aa4255284d3b9afe5f0d99d90f3c0f60afe46f34b366274131053f0a5d32
6
+ metadata.gz: a05b48afc2d4064f818befd652001380d7bf173f92794ad8e9387dbcdee72fe9d1e97101e712ecf84011dd21ecffd5917af0868dbcc20e1fa4bc1cdfd71468cf
7
+ data.tar.gz: 22dac90f622f009efccb0f843f186afd77a782ac11f155be876984e487af8cd77584af2a83aa98444d35a817bbf37051e1576d803dd342ae41da3df078e4cae6
@@ -7,12 +7,13 @@ module Kerio
7
7
  class Client
8
8
  include Kerio::Api::ChainableMethod
9
9
 
10
- def initialize (params)
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
- verify_ssl = true
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)
@@ -2,15 +2,32 @@ module Kerio
2
2
  module Api
3
3
  class Error < StandardError
4
4
 
5
- attr_reader :resp, :headers
5
+ # Returns HTTP response as returned by used http library
6
+ attr_reader :resp
6
7
 
7
- def initialize resp, headers
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
- return @resp["error"]["message"]
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
- __invoke_method if @args.count > 0
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
 
@@ -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, headers) if ((not resp["error"].nil?) || (resp.code != 200))
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, headers) if resp.code != 200
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.1
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
@@ -1,16 +0,0 @@
1
- module Kerio
2
- module Api
3
- module Method
4
- module Session
5
- class Logout < Kerio::Api::Method::Generic
6
-
7
- #make sure the method is invoked immediately
8
- def initialize(params)
9
- super
10
- __invoke_method
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end