Class: KeytechKit::ResponseHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/keytechKit/response_helper.rb

Overview

Helps with common responses

Class Method Summary collapse

Class Method Details

.created_with_location(response) ⇒ Object

Returns a success object with success:true/false. If true it adds a ID parameter extracted from the location header. If false it adds a error response text



17
18
19
20
21
22
23
24
# File 'lib/keytechKit/response_helper.rb', line 17

def self.created_with_location(response)
  if response.success?
    { success: true,
      id: response.headers['location'] }
  else
    { success: false, error: response.headers['x-errordescription'].to_s }
  end
end

.success(response) ⇒ Object

Returns a success object with success:true / false. If false it also adds the x-errordescription object from keytech API



6
7
8
9
10
11
12
# File 'lib/keytechKit/response_helper.rb', line 6

def self.success(response)
  if response.success?
    { success: true }
  else
    { success: false, error: response.headers['x-errordescription'].to_s }
  end
end