Module: Logan::ResponseHandler

Included in:
Client, Event, Person, Project
Defined in:
lib/logan/response_handler.rb

Instance Method Summary collapse

Instance Method Details

#handle_error(response) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/logan/response_handler.rb', line 13

def handle_error(response)
  if response.kind_of? Net::HTTPUnauthorized
    raise Logan::AccessDeniedError
  else
    raise Logan::InvalidRequestError
  end
end

#handle_response(response, block) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/logan/response_handler.rb', line 3

def handle_response(response, block)
  if success?(response.response)
    response.parsed_response.map do |h|
      block.call( h.merge({json_raw: h.to_json}) )
    end
  else
    handle_error(response.response)
  end
end

#success?(response) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/logan/response_handler.rb', line 21

def success?(response)
  response.kind_of? Net::HTTPSuccess
end