Module: Omdb::Api::Utils

Included in:
PublicApi
Defined in:
lib/omdb/api/utils.rb

Instance Method Summary collapse

Instance Method Details

#_handle_response(resp, klass) ⇒ Object



25
26
27
28
29
# File 'lib/omdb/api/utils.rb', line 25

def _handle_response(resp, klass)
  resp.deep_transform_keys! { |k| k.underscore.to_sym }

  resp.fetch(:response) == 'True' ? klass.new(resp) : Omdb::Api::Types::Error.new(resp)
end

#_response_handler(klass) ⇒ Object



20
21
22
23
# File 'lib/omdb/api/utils.rb', line 20

def _response_handler(klass)
  _handle_response(yield, klass)
  # rescue Errno::ECONNREFUSED => e
end

#perform_get(options) ⇒ Object



8
9
10
# File 'lib/omdb/api/utils.rb', line 8

def perform_get(options)
  perform_request(:get, options)
end

#perform_request(request_method, options) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/omdb/api/utils.rb', line 12

def perform_request(request_method, options)
  klass = options.delete(:klass)

  _response_handler(klass) do
    Omdb::Api::Request.new(self, request_method, options).perform
  end
end