Class: ZohoHub::Response
- Inherits:
-
Object
- Object
- ZohoHub::Response
- Defined in:
- lib/zoho_hub/response.rb
Instance Method Summary collapse
- #authentication_failure? ⇒ Boolean
- #data ⇒ Object
- #empty? ⇒ Boolean
-
#error_code?(code) ⇒ Boolean
Error response examples: “data”:[{“code”:“INVALID_DATA”,“details”:{,“message”:“the id given…”,“status”:“error”}]} :details=>{, :message=>“invalid oauth token”, :status=>“error”}.
-
#initialize(params) ⇒ Response
constructor
A new instance of Response.
- #internal_error? ⇒ Boolean
- #invalid_data? ⇒ Boolean
- #invalid_module? ⇒ Boolean
- #invalid_token? ⇒ Boolean
- #mandatory_not_found? ⇒ Boolean
- #msg ⇒ Object
- #no_permission? ⇒ Boolean
- #record_in_blueprint? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/zoho_hub/response.rb', line 5 def initialize(params) @params = params || {} end |
Instance Method Details
#authentication_failure? ⇒ Boolean
21 22 23 |
# File 'lib/zoho_hub/response.rb', line 21 def authentication_failure? error_code?('AUTHENTICATION_FAILURE') end |
#data ⇒ Object
45 46 47 48 |
# File 'lib/zoho_hub/response.rb', line 45 def data data = @params[:data] if @params[:data] data || @params end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/zoho_hub/response.rb', line 41 def empty? @params.empty? end |
#error_code?(code) ⇒ Boolean
Error response examples: “data”:[{“code”:“INVALID_DATA”,“details”:{,“message”:“the id given…”,“status”:“error”}]} :details=>{, :message=>“invalid oauth token”, :status=>“error”}
69 70 71 72 73 74 75 76 77 |
# 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? ⇒ Boolean
17 18 19 |
# File 'lib/zoho_hub/response.rb', line 17 def internal_error? error_code?('INTERNAL_ERROR') end |
#invalid_data? ⇒ Boolean
9 10 11 |
# File 'lib/zoho_hub/response.rb', line 9 def invalid_data? error_code?('INVALID_DATA') end |
#invalid_module? ⇒ Boolean
25 26 27 |
# File 'lib/zoho_hub/response.rb', line 25 def invalid_module? error_code?('INVALID_MODULE') end |
#invalid_token? ⇒ Boolean
13 14 15 |
# File 'lib/zoho_hub/response.rb', line 13 def invalid_token? error_code?('INVALID_TOKEN') end |
#mandatory_not_found? ⇒ Boolean
33 34 35 |
# File 'lib/zoho_hub/response.rb', line 33 def mandatory_not_found? error_code?('MANDATORY_NOT_FOUND') end |
#msg ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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? ⇒ Boolean
29 30 31 |
# File 'lib/zoho_hub/response.rb', line 29 def error_code?('NO_PERMISSION') end |
#record_in_blueprint? ⇒ Boolean
37 38 39 |
# File 'lib/zoho_hub/response.rb', line 37 def record_in_blueprint? error_code?('RECORD_IN_BLUEPRINT') end |