Class: DotMailer::DataField

Inherits:
Object
  • Object
show all
Defined in:
lib/dot_mailer/data_field.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ DataField

Returns a new instance of DataField.



22
23
24
# File 'lib/dot_mailer/data_field.rb', line 22

def initialize(attributes)
  self.attributes = attributes
end

Class Method Details

.all(account) ⇒ Object



3
4
5
6
7
# File 'lib/dot_mailer/data_field.rb', line 3

def self.all()
  fields = .client.get '/data-fields'

  fields.map { |attributes| new(attributes) }
end

.create(account, name, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dot_mailer/data_field.rb', line 9

def self.create(, name, options = {})
  options[:type]       ||= 'String'
  options[:visibility] ||= 'Public'

  .client.post_json(
    '/data-fields',
    'name'         => name,
    'type'         => options[:type],
    'visibility'   => options[:visibility],
    'defaultValue' => options[:default]
  )
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/dot_mailer/data_field.rb', line 50

def ==(other)
  attributes == other.attributes
end

#date?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/dot_mailer/data_field.rb', line 54

def date?
  type == 'Date'
end

#defaultObject



38
39
40
# File 'lib/dot_mailer/data_field.rb', line 38

def default
  attributes['defaultValue']
end

#nameObject



26
27
28
# File 'lib/dot_mailer/data_field.rb', line 26

def name
  attributes['name']
end

#to_json(options = {}) ⇒ Object



42
43
44
# File 'lib/dot_mailer/data_field.rb', line 42

def to_json(options = {})
  attributes.to_json
end

#to_sObject



46
47
48
# File 'lib/dot_mailer/data_field.rb', line 46

def to_s
  %{#{self.class.name} name: "#{name}", type: "#{type}", visibility: "#{visibility}", default: "#{default}"}
end

#typeObject



30
31
32
# File 'lib/dot_mailer/data_field.rb', line 30

def type
  attributes['type']
end

#visibilityObject



34
35
36
# File 'lib/dot_mailer/data_field.rb', line 34

def visibility
  attributes['visibility']
end