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

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/marketing_campaigns/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, #finish, #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/marketing_campaigns/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
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb', line 35

def self.create_fields(resp)
  return resp if resp.nil?
  custom_fields = resp['custom_fields'].map do |field|
    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/marketing_campaigns/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



67
68
69
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb', line 67

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

#get_custom_field(custom_field_id:, &block) ⇒ Object



60
61
62
63
64
65
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb', line 60

def get_custom_field(custom_field_id:, &block)
  resp = get(@auth, Contacts::CustomFields.url(custom_field_id), &block)
  finish(resp, @raw_resp) do |r|
    Contacts::CustomFields.create_field(r)
  end
end

#get_custom_fields(&block) ⇒ Object



53
54
55
56
57
58
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb', line 53

def get_custom_fields(&block)
  resp = get(@auth, Contacts::CustomFields.url, &block)
  finish(resp, @raw_resp) do |r|
    Contacts::CustomFields.create_fields(r)
  end
end

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



43
44
45
46
47
48
49
50
51
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb', line 43

def post_custom_field(name:, type:, &block)
  params = {}
  params['name'] = name
  params['type'] = type
  resp = post(@auth, Contacts::CustomFields.url, params, &block)
  finish(resp, @raw_resp) do |r|
    Contacts::CustomFields.create_field(r)
  end
end