Module: Pipedrive::Util

Defined in:
lib/pipedrive/util.rb

Class Method Summary collapse

Class Method Details

.debug(message) ⇒ Object



21
22
23
# File 'lib/pipedrive/util.rb', line 21

def self.debug(message)
  Pipedrive.logger&.debug(message) if Pipedrive.debug
end

.serialize_response(response, symbolize_names: true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pipedrive/util.rb', line 5

def self.serialize_response(response, symbolize_names: true)
  if response.status == 204
    return {} unless Pipedrive.treat_no_content_as_not_found

    Pipedrive.raise_error(404, error: "HTTP 204 status code received. No content")
  end

  json_body = JSON.parse(response.body, symbolize_names: symbolize_names)

  if response.success?
    json_body
  else
    Pipedrive.raise_error(response.status, json_body)
  end
end