Class: Emarsys::Field

Inherits:
DataObject show all
Defined in:
lib/emarsys/data_objects/field.rb

Overview

Methods for the Field API

Class Method Summary collapse

Methods inherited from DataObject

delete, get, parameterize_params, post, put, #request

Class Method Details

.choice(id, account: nil) ⇒ Hash

Query the choice option for a specific field

Examples:

Emarsys::Field.choice(3)


33
34
35
# File 'lib/emarsys/data_objects/field.rb', line 33

def choice(id, account: nil)
  get , "field/#{id}/choice", {}
end

.collection(account: nil, **params) ⇒ Hash

List data fields

Examples:

Emarsys::Field.collection
Emarsys::Field.collection(:translate => 'en')

Options Hash (**params):

  • :translate (Integer, String)

    translate to another language



18
19
20
21
22
23
24
25
# File 'lib/emarsys/data_objects/field.rb', line 18

def collection(account: nil, **params)
  params = params.stringify_keys
  if params['translate']
    get , "field/translate/#{params['translate'].to_s}", {}
  else
    get , 'field', {}
  end
end

.create(name:, application_type:, string_id: nil, account: nil) ⇒ Hash

Create a new custom field

Examples:

Emarsys::Field.create(
  name: 'New field',
  application_type: 'shorttext',
  string_id: 'string_id_for_the_new_field'
)
Emarsys::Field.create(
  name: 'New number field',
  application_type: 'numeric'
)


53
54
55
56
57
# File 'lib/emarsys/data_objects/field.rb', line 53

def create(name:, application_type:, string_id: nil, account: nil)
  params = { name: name, application_type: application_type }
  params[:string_id] = string_id if string_id
  post , 'field', params
end