onlyoffice_api 0.10.0 → 0.11.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
  SHA256:
3
- metadata.gz: 58536681a16a0e9cd5d20506a8d6549f87747914d0252cd5c6fed30165eaa022
4
- data.tar.gz: 1ea712d7ee0f71a79f1a8390dd6ce31e06f1ad250ac044ada511562ccbb4b746
3
+ metadata.gz: 4da6935cc3d256a7b5b39d6b02f7a4a038e908cd8a7949c34f89e124da984a9a
4
+ data.tar.gz: f7baefc1910689ff41da8deaab16c70a8776a1cd40878876993ab072cfbd2c20
5
5
  SHA512:
6
- metadata.gz: 5c835194dba1d3d8edb26e3559065fcabed8698a4242ed825ecbf2119447af11f59705315e11cf03c295f8d7e2ab8449b61a18822f8a237ce8d8ef31ce90d950
7
- data.tar.gz: 2ff09f5ab0e21ee974ecb7b5dedee3c929ac620686ed47bf02c6aa4fbcdd454a8c97562ffdbf9ec61f084a8f7364faba7565c599da0385fff7d1b12953c71ab2
6
+ metadata.gz: a3e475df99ffaaef22bb7d140d3e18968f735a666142cf6722909402e43c54d5bb26a3efc3db6964434d8499afef36fa449549d248c477c29c9e9d77464b641c
7
+ data.tar.gz: 036ac1d16df32299bf439f5e04c4e5b4dd5f31d1bbb27d8dca654d98c6a1c3b1c59b176aa650d63b3ab97f8daf050e4a7bbba2fa19964a30f3023129177e39d4
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Teamlab
4
+ # Exception if in response no JSON body
5
+ class NoJsonInResponce < StandardError; end
6
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'responce/custom_exceptions'
4
+
3
5
  module Teamlab
4
6
  class Response
5
7
  attr_reader :body, :error, :code, :success
@@ -9,7 +11,7 @@ module Teamlab
9
11
  @success = @code < 400
10
12
  err_msg = generate_err_msg(http_response) if @code >= 400
11
13
  if @success
12
- @body = http_response.to_hash
14
+ handle_success_responce(http_response)
13
15
  else
14
16
  raise TimeoutError, 'Portal is warming up' if http_response.parsed_response.include?('portal is being warmed')
15
17
  raise "Error #{@code}\n#{err_msg}" if @code >= 400
@@ -37,5 +39,42 @@ module Teamlab
37
39
  def data
38
40
  @body['response']
39
41
  end
42
+
43
+ private
44
+
45
+ # Sometime in strange situation, like maybe nginx errors
46
+ # API requests return not JSON, but html or other data
47
+ # @param [Teamlab::Responce] responce to check
48
+ # @return [Nil] is body responce correct and raise exception in any other situation
49
+ def check_responce_body(responce)
50
+ return if stream_data_request?(responce)
51
+
52
+ JSON.parse(responce.body)
53
+ rescue JSON::ParserError => e
54
+ request_info = "#{responce.request.http_method} #{responce.request.uri}"
55
+ raise NoJsonInResponce, "Request `#{request_info}` responce body is not a json\n "\
56
+ "Parsing error: \n#{e}\n"
57
+ end
58
+
59
+ # Handle success responce
60
+ # @param [Teamlab::Responce] responce to handle
61
+ # @return [nil] if everything is fine or exception
62
+ def handle_success_responce(responce)
63
+ check_responce_body(responce)
64
+ @body = responce.to_hash
65
+ end
66
+
67
+ # Check if request for stream data
68
+ # Those request has no body, but data stream in responce
69
+ # @param [Teamlab::Responce] responce to check
70
+ # @return [Boolean] result of check
71
+ def stream_data_request?(responce)
72
+ calendar_ical_request_regexp = %r{.*/calendar/\d*/ical/\S*}
73
+ uri = responce.request.uri.to_s
74
+
75
+ return true if calendar_ical_request_regexp.match?(uri)
76
+
77
+ false
78
+ end
40
79
  end
41
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teamlab
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-04-29 00:00:00.000000000 Z
14
+ date: 2021-06-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -236,6 +236,7 @@ files:
236
236
  - lib/teamlab/modules/settings.rb
237
237
  - lib/teamlab/name.rb
238
238
  - lib/teamlab/request.rb
239
+ - lib/teamlab/responce/custom_exceptions.rb
239
240
  - lib/teamlab/response.rb
240
241
  - lib/teamlab/version.rb
241
242
  homepage: https://github.com/ONLYOFFICE/onlyoffice_api_gem