Module: One::EmailDirect::Mixins::ListFacade

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

Instance Method Summary collapse

Instance Method Details

#list_add(credentials, name, description) ⇒ Object

Creates a new list on the given EmailDirect account.

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

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • name (String)

    the list name.

  • description (String)

    the list description.

Raises:



11
12
13
14
15
16
17
18
19
20
# File 'lib/one/email_direct/mixins/list.rb', line 11

def list_add(credentials, name, description)
  response = send_soap(
    :list_add,
    {:soap_action => 'http://espapi.net/v1/List_Add',
      :credentials => credentials,
      :list_name => name,
      :list_description => description}
  )
  raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0'
end

#list_delete(credentials, list_id) ⇒ Object

Deletes a list from the given EmailDirect account.

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

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • list_id (Fixnum)

    the unique identifier of the list to be deleted.

Raises:



31
32
33
34
35
36
37
38
39
# File 'lib/one/email_direct/mixins/list.rb', line 31

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

#list_get(credentials, name) ⇒ Hash

Returns the whole information of a list on the given EmailDirect account.

Parameters:

  • credentials

    [

  • name (String)

    the name of the list.

Returns:

  • (Hash)

    a hash that describes the list. => ‘id’, :element_name => ‘name’, :description => ‘description’



51
52
53
54
# File 'lib/one/email_direct/mixins/list.rb', line 51

def list_get(credentials, name)
  list_getall(credentials).each {|element| return element if element[:element_name] == name}
  nil
end

#list_getall(credentials) ⇒ Array

Returns all lists on the given EmailDirect account.

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

Parameters:

Returns:

  • (Array)
    => ‘id’, :element_name => ‘name’, :description => ‘description’


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/one/email_direct/mixins/list.rb', line 66

def list_getall(credentials)
  response = send_soap(
    :list_get_all,
    {:soap_action => 'http://espapi.net/v1/List_GetAll',
     :credentials => credentials}
  )

  # no elements were returned
  return [] if response.nil?

  # if it only has one element (Hash) you have to transform it to a single array element
  return [response[:element]] if response[:element].instance_of? Hash

  # more than 1 element
  if !block_given?
    elements = []
    response[:element].each {|element|
      elements << element
    }
    elements
  else
    response[:element].each {|element| yield element }
  end
end

#list_getmembers(credentials, list_id, page_size, page_number) ⇒ Hash

Returns all subscribers associated to a list on the given EmailDirect account.

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

Parameters:

  • credentials (One::EmailDirect::Credentials)

    EmailDirect API credentials.

  • list_id (Fixnum)

    the unique identifier of the list.

  • page_size (Fixnum)

    the number of subscribers to present per page.

  • page_number (Fixnum)

    the page number to present.

Returns:

  • (Hash)

    TODO description.”, :element_name=>“name12353”, :element_id=>“170”



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/one/email_direct/mixins/list.rb', line 104

def list_getmembers(credentials, list_id, page_size, page_number)
  response = send_soap(
    :list_getmembers,
    {:soap_action => 'http://espapi.net/v1/List_GetMembers',
      :credentials => credentials,
      :list_id => list_id,
      :page_size => page_size,
      :page_number => page_number}
  )


  # no elements were returned
  return [] if response.nil?

  # if it only has one element (Hash) you have to transform it to a single array element
  return [response[:element]] if response[:element].instance_of? Hash

  # more than 1 element
  if !block_given?
    elements = []
    response[:element].each {|element|
      elements << element
    }
    elements
  else
    response[:element].each {|element| yield element }
  end

end