Module: SendGrid4r::REST::Contacts::CustomFields

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/contacts/custom_fields.rb

Overview

SendGrid Web API v3 Contacts - Custom Fields

Defined Under Namespace

Classes: Field, Fields

Constant Summary

Constants included from Request

Request::BASE_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#create_args, #delete, #execute, #get, #patch, #post, #process_array_params, #process_url_params, #put

Class Method Details

.create_field(resp) ⇒ Object



30
31
32
33
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 30

def self.create_field(resp)
  return resp if resp.nil?
  Field.new(resp['id'], resp['name'], resp['type'], resp['value'])
end

.create_fields(resp) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 35

def self.create_fields(resp)
  return resp if resp.nil?
  custom_fields = []
  resp['custom_fields'].each do |field|
    custom_fields.push(
      SendGrid4r::REST::Contacts::CustomFields.create_field(field)
    )
  end
  Fields.new(custom_fields)
end

.url(custom_field_id = nil) ⇒ Object



24
25
26
27
28
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 24

def self.url(custom_field_id = nil)
  url = "#{BASE_URL}/contactdb/custom_fields"
  url = "#{url}/#{custom_field_id}" unless custom_field_id.nil?
  url
end

Instance Method Details

#delete_custom_field(custom_field_id:, &block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 72

def delete_custom_field(custom_field_id:, &block)
  delete(
    @auth,
    SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
    &block
  )
end

#get_custom_field(custom_field_id:, &block) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 63

def get_custom_field(custom_field_id:, &block)
  resp = get(
    @auth,
    SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
    &block
  )
  SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
end

#get_custom_fields(&block) ⇒ Object



56
57
58
59
60
61
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 56

def get_custom_fields(&block)
  resp = get(
    @auth, SendGrid4r::REST::Contacts::CustomFields.url, &block
  )
  SendGrid4r::REST::Contacts::CustomFields.create_fields(resp)
end

#post_custom_field(name:, type:, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/sendgrid4r/rest/contacts/custom_fields.rb', line 46

def post_custom_field(name:, type:, &block)
  params = {}
  params['name'] = name
  params['type'] = type
  resp = post(
    @auth, SendGrid4r::REST::Contacts::CustomFields.url, params, &block
  )
  SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
end