class ZohoHub::Response

Public Class Methods

new(params) click to toggle source
# File lib/zoho_hub/response.rb, line 5
def initialize(params)
  @params = params || {}
end

Public Instance Methods

authentication_failure?() click to toggle source
# File lib/zoho_hub/response.rb, line 21
def authentication_failure?
  error_code?('AUTHENTICATION_FAILURE')
end
data() click to toggle source
# File lib/zoho_hub/response.rb, line 45
def data
  data = @params[:data] if @params[:data]
  data || @params
end
empty?() click to toggle source
# File lib/zoho_hub/response.rb, line 41
def empty?
  @params.empty?
end
error_code?(code) click to toggle source

Error response examples: {“data”:[{“code”:“INVALID_DATA”,“details”:{},“message”:“the id given…”,“status”:“error”}]} {:code=>“INVALID_TOKEN”, :details=>{}, :message=>“invalid oauth token”, :status=>“error”}

# File lib/zoho_hub/response.rb, line 69
def error_code?(code)
  if data.is_a?(Array)
    return false if data.size > 1

    return data.first[:code] == code
  end

  data[:code] == code
end
internal_error?() click to toggle source
# File lib/zoho_hub/response.rb, line 17
def internal_error?
  error_code?('INTERNAL_ERROR')
end
invalid_data?() click to toggle source
# File lib/zoho_hub/response.rb, line 9
def invalid_data?
  error_code?('INVALID_DATA')
end
invalid_module?() click to toggle source
# File lib/zoho_hub/response.rb, line 25
def invalid_module?
  error_code?('INVALID_MODULE')
end
invalid_token?() click to toggle source
# File lib/zoho_hub/response.rb, line 13
def invalid_token?
  error_code?('INVALID_TOKEN')
end
mandatory_not_found?() click to toggle source
# File lib/zoho_hub/response.rb, line 33
def mandatory_not_found?
  error_code?('MANDATORY_NOT_FOUND')
end
msg() click to toggle source
# File lib/zoho_hub/response.rb, line 50
def msg
  first_data = data.is_a?(Array) ? data.first : data
  msg = first_data[:message]

  if first_data.dig(:details, :expected_data_type)
    expected = first_data.dig(:details, :expected_data_type)
    field = first_data.dig(:details, :api_name)
    parent_api_name = first_data.dig(:details, :parent_api_name)

    msg << ", expected #{expected} for '#{field}'"
    msg << " in #{parent_api_name}" if parent_api_name
  end

  msg
end
no_permission?() click to toggle source
# File lib/zoho_hub/response.rb, line 29
def no_permission?
  error_code?('NO_PERMISSION')
end
record_in_blueprint?() click to toggle source
# File lib/zoho_hub/response.rb, line 37
def record_in_blueprint?
  error_code?('RECORD_IN_BLUEPRINT')
end