Class: Sellsy::CustomField

Inherits:
Object
  • Object
show all
Defined in:
lib/sellsy/custom_field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, value) ⇒ CustomField

Returns a new instance of CustomField.



7
8
9
10
# File 'lib/sellsy/custom_field.rb', line 7

def initialize(id, value)
  @id = id
  @value = value
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sellsy/custom_field.rb', line 5

def id
  @id
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/sellsy/custom_field.rb', line 5

def value
  @value
end

Class Method Details

.all(nb_per_page = 30) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

.set_values(entity, *custom_fields) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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