Class: Ask::Linear::ClientProxy

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

Overview

Proxies method calls to a Client, converting authentication errors into Ask::Auth::InvalidCredential.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientProxy

Returns a new instance of ClientProxy.



97
98
99
# File 'lib/ask/linear/client.rb', line 97

def initialize(client)
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ask/linear/client.rb', line 101

def method_missing(name, ...)
  @client.public_send(name, ...)
rescue ::Faraday::UnauthorizedError => e
  response = e.response
  status = response.is_a?(::Hash) ? response[:status] : nil
  if status == 401
    ::Kernel.raise ::Ask::Auth::InvalidCredential, :linear_api_key
  end
  ::Kernel.raise
rescue ::Faraday::ClientError => e
  response = e.response
  status = response.is_a?(::Hash) ? response[:status] : nil
  if status == 401
    ::Kernel.raise ::Ask::Auth::InvalidCredential, :linear_api_key
  end
  ::Kernel.raise
end

Instance Method Details

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

Returns:

  • (Boolean)


119
120
121
# File 'lib/ask/linear/client.rb', line 119

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