class Freshworks::Base

Constants

BASE_URI
REQUIRED_PARAMS
VERSION_URI

Attributes

raw_response[R]

Public Class Methods

endpoint(*params) click to toggle source
# File lib/freshworks/base.rb, line 18
def self.endpoint(*params)
  params = [endpoint_path, params, Freshworks.api_key_uri].flatten.compact.map(&:to_s)
  Freshworks.full_endpoint_uri(BASE_URI, VERSION_URI, params)
end
endpoint_path() click to toggle source
# File lib/freshworks/base.rb, line 23
def self.endpoint_path
  raise NotImplementedError.new( 'This method needs to be overridden in a child class.  Proper implementation '\
      'should return an array where each index contains a different part of the path.  For example: '\
      '[\'test\', \'best\'] becomes \'/test/best/\'.' )
end
json_data(body) click to toggle source
# File lib/freshworks/base.rb, line 29
def self.json_data(body)
  { body: body, headers: json_headers }
end
json_headers() click to toggle source
# File lib/freshworks/base.rb, line 33
def self.json_headers
  { 'Content-Type': 'application/json' }
end
new(params, raw_response = nil) click to toggle source
# File lib/freshworks/base.rb, line 41
def initialize(params, raw_response = nil)
  missing_params = REQUIRED_PARAMS - params.keys
  raise ArgumentError.new("Missing required params #{missing_params.join(', ')}") unless missing_params.empty?

  load_model_properties
  clean_params(params)
  populate_properties(params)

  @raw_response = raw_response
end
request_helper() click to toggle source
# File lib/freshworks/base.rb, line 37
def self.request_helper
  Freshworks::RequestHelper.new(self)
end

Public Instance Methods

to_json() click to toggle source
# File lib/freshworks/base.rb, line 52
def to_json
  serialize
end

Private Instance Methods

clean_params(params) click to toggle source
# File lib/freshworks/base.rb, line 62
def clean_params(params)
  params.each { |_, value| value.gsub!(/"/, '') if value.respond_to?(:gsub!) }
end
load_model_properties() click to toggle source
# File lib/freshworks/base.rb, line 58
def load_model_properties
  model_config[:properties].each { |prop| self.class.class_eval { attr_accessor prop.to_sym } }
end
model_config() click to toggle source
# File lib/freshworks/base.rb, line 70
def model_config
  YAML::load(File.read("#{Freshworks.gem_root}/config/model_properties.yml"))[self.class.name.to_s].with_indifferent_access
end
populate_properties(params) click to toggle source
# File lib/freshworks/base.rb, line 66
def populate_properties(params)
  params.each { |key, value| instance_variable_set("@#{key}", value) }
end