Module: One::EmailDirect::Mixins::EmailFacade

Included in:
Facade
Defined in:
lib/one/email_direct/mixins/email.rb

Instance Method Summary collapse

Instance Method Details

#email_add(credentials, email, source_id, publications, lists, autoresponder = 0, force = false) ⇒ Object

Creates a new email on the given EmailDirect account.

dev.emaildirect.com/v1/api.asmx?op=Email_Add

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • email (String)

    the email address to be added.

  • source_id (Fixnum)

    the source identifier to attach this email to.

  • publications (Array)

    the publication identifiers to attach this email to.

  • lists (Array)

    the list identifiers to attach this email to.

  • autoresponder (Fixnum) (defaults to: 0)

    the auto-responder identifier from the account. If ‘0’ is provided then nothing will be sent to the email address.

  • force (true, false) (defaults to: false)

    Force the addition/update/deletion of an email regardless of it’s current state. This will preform the method called for any email that has Bounced or opted to be Globaly Removed from your account so please use with caution.

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/one/email_direct/mixins/email.rb', line 18

def email_add(credentials, email, source_id, publications, lists, autoresponder=0, force=false)
  # TODO: validate mandatory arguments and raise ArgumentError
  response = send_soap(
    :email_add,
    {:soap_action => 'http://espapi.net/v1/Email_Add',
      :credentials => credentials,
      :email => email,
      :source_id => source_id,
      :publications => publications,
      :lists => lists,
      :autoresponder => autoresponder,
      :force => force
    }
  )
  raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0'
end

#email_addwithfields(credentials, email, source_id, publications, lists, autoresponder = 0, force = false, custom_fields = {}) ⇒ Object

Creates a new email on the given EmailDirect account.

dev.emaildirect.com/v1/api.asmx?op=Email_AddWithFields

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • email (String)

    the email address to be added.

  • source_id (Fixnum)

    the source identifier to attach this email to.

  • publications (Array)

    the publication identifiers to attach this email to.

  • lists (Array)

    the list identifiers to attach this email to.

  • autoresponder (Fixnum) (defaults to: 0)

    the auto-responder identifier from the account. If ‘0’ is provided then nothing will be sent to the email address.

  • force (true, false) (defaults to: false)

    Force the addition/update/deletion of an email regardless of it’s current state. This will preform the method called for any email that has Bounced or opted to be Globaly Removed from your account so please use with caution.

  • custom_fields (Hash) (defaults to: {})

    The CustomFields parameter allows you to pass in 0 or more CustomField objects to the method. A CustomField object is a name/value pair representing a field in your database and the value your are passing in.

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/one/email_direct/mixins/email.rb', line 56

def email_addwithfields(credentials, email, source_id, publications, lists, autoresponder=0, force=false, custom_fields={})
  # TODO: validate mandatory arguments and raise ArgumentError
  response = send_soap(
    :email_add_with_fields,
    {:soap_action => 'http://espapi.net/v1/Email_AddWithFields',
      :credentials => credentials,
      :email => email,
      :source_id => source_id,
      :publications => publications,
      :lists => lists,
      :autoresponder => autoresponder,
      :force => force,
      :custom_fields => custom_fields
    }
  )
  raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0'
end

#email_delete(credentials, email, force) ⇒ Object

Deletes an email from the given EmailDirect account.

dev.emaildirect.com/v1/api.asmx?op=Email_Delete

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • email (String)

    the email address to be deleted.

  • force (true, false)

    Force the addition/update/deletion of an email regardless of it’s current state. This will preform the method called for any email that has Bounced or opted to be Globaly Removed from your account so please use with caution.

Raises:



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/one/email_direct/mixins/email.rb', line 86

def email_delete(credentials, email, force)
  response = send_soap(
    :email_delete,
    {:soap_action => 'http://espapi.net/v1/Email_Delete',
      :credentials => credentials,
      :email => email,
      :force => force
    }
  )
  raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0'
end

#email_getproperties(credentials, email) ⇒ Hash

Returns all all properties associated with an email address.

dev.emaildirect.com/v1/api.asmx?op=Email_GetProperties

Parameters:

Returns:

  • (Hash)

    Example: 1768098599/720,0,2299161>, :ip_address=>nil, :status=>“Active”,

    :publications=>{:element=>{:element_id=>"579",
    :description=>"descriptionf43123305dc9012e06f234159e028042",
    :element_name=>"namef43123305dc9012e06f234159e028042"}, :lists=>:description=>"descriptionf43123305dc9012e06f234159e028042",
    :element_name=>"namef43123305dc9012e06f234159e028042"},
    :email=>"[email protected]", :email_id=>"108",
    :custom_fields=>:field_name=>"Email", :field_name=>"IPAddress", :field_name=>"DateStamp", :field_name=>"FirstName",
    :field_name=>"LastName", :field_name=>"Age"]},
    :create_date=>#<DateTime: 1768098599/720,0,2299161>, :source=>:description=>"descriptionf43123305dc9012e06f234159e028042",
    :element_name=>"namef43123305dc9012e06f234159e028042"}
    


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/one/email_direct/mixins/email.rb', line 123

def email_getproperties(credentials, email)
  response = send_soap(
    :email_get_properties,
    {:soap_action => 'http://espapi.net/v1/Email_GetProperties',
      :credentials => credentials,
      :email => email
    }
  )

  if !response.nil?
    # make response consistent
    if !response[:lists].nil?
      lists = response[:lists][:element]
      response[:lists][:element] = [lists] if lists.instance_of? Hash
    else
      response[:lists] = {:element => []}
    end

    if !response[:publications].nil?
      publications = response[:publications][:element]
      response[:publications][:element] = [publications] if publications.instance_of? Hash
    else
      response[:publications] = {:element => []}
    end
  end
  response
end