Sha256: adaf5be91d85629a2e75011e900a343c9fca6cccfc3b0c84a6b365ce668f19db

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require 'multi_json'

module Sellsy
  class CustomField
    attr_accessor :id, :value

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

    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

    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

    def self.all
      command = {
          'method' => 'CustomFields.getList',
          'params' => {
              'pagination' => {
                  'nbperpage' => 30
              }
          }
      }
      response = MultiJson.load(Sellsy::Api.request command)

      response['status'] == 'success' ? response['response']['result'] : {}
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sellsy-client-0.9.0 lib/sellsy/custom_field.rb
sellsy-client-0.8.0 lib/sellsy/custom_field.rb
sellsy-client-0.7.0 lib/sellsy/custom_field.rb
sellsy-client-0.6.0 lib/sellsy/custom_field.rb
sellsy-client-0.5.0 lib/sellsy/custom_field.rb
sellsy-client-0.4.0 lib/sellsy/custom_field.rb
sellsy-client-0.3.0 lib/sellsy/custom_field.rb