Class: ZohoHub::Potential

Inherits:
BaseRecord show all
Defined in:
lib/zoho_hub/records/potential.rb

Constant Summary collapse

DEFAULTS =
{
  currency: 'GBP',
  territory: 'UK all',
  campaign_detail: 'Web Sign Up'
}.freeze

Instance Method Summary collapse

Methods inherited from BaseRecord

all, attribute_translation, attributes, #attributes, #build_response, build_response, create, exists?, find, find_by, #get, get, #new_record?, post, #post, put, #put, request_path, #save, #to_input, where, zoho_key_translation

Constructor Details

#initialize(params) ⇒ Potential

Returns a new instance of Potential.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zoho_hub/records/potential.rb', line 45

def initialize(params)
  attributes.each do |attr|
    zoho_key = attr_to_zoho_key(attr)

    send("#{attr}=", params[zoho_key] || params[attr] || DEFAULTS[attr])
  end

  # Setup values as they come from the Zoho API if needed
  @account_id ||= params.dig(:Account_Name, :id)
  @contact_id ||= params.dig(:Contact_Name, :id)
  @campaign_id ||= params.dig(:Campaign_Source, :id)
  @accountant_id ||= params.dig(:Accountant_Name, :id)
end

Instance Method Details

#to_paramsObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/zoho_hub/records/potential.rb', line 59

def to_params
  params = super

  params[:Campaign_Source] = { id: @campaign_id } if @campaign_id
  params[:Account_Name] = { id: @account_id } if @account_id
  params[:Contact_Name] = { id: @contact_id } if @contact_id
  params[:Accountant_Name] = { id: @accountant_id } if @accountant_id

  params
end