Class: Ask::Notion::ClientProxy

Inherits:
BasicObject
Defined in:
lib/ask/notion/client.rb

Overview

Proxies method calls to a ::Notion::Client, converting authentication, timeout, and network errors into ask-rb exceptions with automatic retry for transient failures.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientProxy

Returns a new instance of ClientProxy.



41
42
43
# File 'lib/ask/notion/client.rb', line 41

def initialize(client)
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ask/notion/client.rb', line 45

def method_missing(name, ...)
  retries = 0
  begin
    @client.public_send(name, ...)
  rescue ::Notion::Api::Errors::Unauthorized
    ::Kernel.raise ::Ask::Auth::InvalidCredential, :notion_token
  rescue ::Notion::Api::Errors::TooManyRequests,
         ::Notion::Api::Errors::UnavailableError,
         ::Notion::Api::Errors::ServerError,
         ::Timeout::Error,
         ::Errno::ECONNREFUSED,
         ::Errno::ECONNRESET
    retries += 1
    if retries <= ::Ask::Notion::DEFAULT_RETRIES
      ::Kernel.sleep(2 ** retries * 0.1)
      retry
    end
    ::Kernel.raise
  end
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ask/notion/client.rb', line 66

def respond_to_missing?(name, include_private = false)
  @client.respond_to?(name, include_private) || super
end