class Sellsy::CustomField

Attributes

id[RW]
value[RW]

Public Class Methods

all(nb_per_page = 30) click to toggle source
# File lib/sellsy/custom_field.rb, line 44
def self.all(nb_per_page = 30)
  command = {
      'method' => 'CustomFields.getList',
      'params' => {
          'pagination' => {
              'nbperpage' => nb_per_page
          }
      }
  }
  response = MultiJson.load(Sellsy::Api.request command)

  response['status'] == 'success' ? response['response']['result'] : {}
end
linked_type(entity) click to toggle source
# File lib/sellsy/custom_field.rb, line 27
def self.linked_type(entity)
  case entity
  when Customer
    'client'
  when Prospect
    'prospect'
  when Opportunity
    'opportunity'
  when Contact
    'people'
  when Document
    'document'
  else
    nil
  end
end
new(id, value) click to toggle source
# File lib/sellsy/custom_field.rb, line 7
def initialize(id, value)
  @id = id
  @value = value
end
set_values(entity, *custom_fields) click to toggle source
# File lib/sellsy/custom_field.rb, line 12
def self.set_values(entity, *custom_fields)
  command = {
      'method' => 'CustomFields.recordValues',
      'params' => {
          'linkedtype' => linked_type(entity),
          'linkedid' => entity.id,
          'values' => custom_fields.select {|cf| !cf.nil? && !cf.value.blank?}.map {|cf| {'cfid' => cf.id, 'value' => cf.value}}
      }
  }

  response = MultiJson.load(Sellsy::Api.request command)

  response['status'] == 'success'
end