Class: ZohoHub::Product

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

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) ⇒ Product

Returns a new instance of Product.



13
14
15
16
17
18
19
20
21
22
# File 'lib/zoho_hub/records/product.rb', line 13

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

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

  @owner_id ||= params.dig(:Owner, :id)
  @vendor_id ||= params.dig(:Vendor_Name, :id)
end

Instance Method Details

#to_paramsObject



24
25
26
27
28
29
30
31
# File 'lib/zoho_hub/records/product.rb', line 24

def to_params
  params = super

  params[:Owner] = { id: @owner_id } if @owner_id
  params[:Vendor_Name] = { id: @vendor_id } if @vendor_id

  params
end