one-email_direct 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -0
- data/lib/emaildirect.secure.wsdl +5224 -0
- data/lib/emaildirect.wsdl +5224 -0
- data/lib/one/email_direct/client.rb +11 -0
- data/lib/one/email_direct/credentials.rb +42 -0
- data/lib/one/email_direct/facade.rb +74 -0
- data/lib/one/email_direct/mixins/email.rb +151 -0
- data/lib/one/email_direct/mixins/list.rb +133 -0
- data/lib/one/email_direct/mixins/publication.rb +91 -0
- data/lib/one/email_direct/mixins/source.rb +90 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_add.rbxml +26 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_add.rbxml.cache +26 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_add_with_fields.rbxml +34 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_add_with_fields.rbxml.cache +34 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_addwithfields.rbxml.cache +34 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_delete.rbxml +10 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_delete.rbxml.cache +10 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_get_properties.rbxml +9 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_get_properties.rbxml.cache +9 -0
- data/lib/one/email_direct/mixins/template/email/soap11_email_getproperties.rbxml.cache +9 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_add.rbxml +10 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_add.rbxml.cache +10 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_delete.rbxml +9 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_delete.rbxml.cache +9 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_get_all.rbxml +8 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_get_all.rbxml.cache +8 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_getall.rbxml.cache +8 -0
- data/lib/one/email_direct/mixins/template/list/soap11_list_getmembers.rbxml +11 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_add.rbxml +10 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_add.rbxml.cache +10 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_delete.rbxml +9 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_delete.rbxml.cache +9 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_get_all.rbxml +7 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_get_all.rbxml.cache +7 -0
- data/lib/one/email_direct/mixins/template/publication/soap11_publication_getall.rbxml.cache +7 -0
- data/lib/one/email_direct/mixins/template/soap11_credentials.rbxml +5 -0
- data/lib/one/email_direct/mixins/template/soap11_credentials.rbxml.cache +5 -0
- data/lib/one/email_direct/mixins/template/soap11_footer.rbxml +2 -0
- data/lib/one/email_direct/mixins/template/soap11_footer.rbxml.cache +2 -0
- data/lib/one/email_direct/mixins/template/soap11_header.rbxml +5 -0
- data/lib/one/email_direct/mixins/template/soap11_header.rbxml.cache +5 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_add.rbxml +10 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_add.rbxml.cache +10 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_delete.rbxml +9 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_delete.rbxml.cache +9 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_get_all.rbxml +7 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_get_all.rbxml.cache +7 -0
- data/lib/one/email_direct/mixins/template/source/soap11_source_getall.rbxml.cache +7 -0
- data/lib/one-email_direct.rb +37 -0
- data/test/unit/one/emaildirect/client_test.rb +49 -0
- data/test/unit/one/emaildirect/credentials_test.rb +36 -0
- data/test/unit/one/emaildirect/email/facade_test.rb +430 -0
- data/test/unit/one/emaildirect/list/facade_test.rb +154 -0
- data/test/unit/one/emaildirect/publication/facade_test.rb +151 -0
- data/test/unit/one/emaildirect/source/facade_test.rb +153 -0
- metadata +175 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
class One::EmailDirect::Client < Savon::Client
|
2
|
+
|
3
|
+
def initialize(soap_action=nil)
|
4
|
+
super() do
|
5
|
+
wsdl.document = 'lib/emaildirect.wsdl'
|
6
|
+
http.proxy = 'http://dev.emaildirect.com/v1/api.asmx'
|
7
|
+
http.headers['SOAPAction'] = %{"#{soap_action}"} if !soap_action.nil?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Class to hold EmailDirect API credentials.
|
2
|
+
#
|
3
|
+
# @author Steenzout <https://github.com/steenzout>
|
4
|
+
#
|
5
|
+
# @attr_reader account [String] EmailDirect account username.
|
6
|
+
# @attr_reader password [String] the API password configured in the EmailDirect web interface.
|
7
|
+
# @attr_reader encrypted_password [String] optional encryped password (future use).
|
8
|
+
#
|
9
|
+
class One::EmailDirect::Credentials
|
10
|
+
|
11
|
+
attr_reader :account, :password, :encrypted_password
|
12
|
+
|
13
|
+
|
14
|
+
# Constructs a Credentials instance.
|
15
|
+
#
|
16
|
+
# @param account [String] the EmailDirect account.
|
17
|
+
# @param password [String] the EmailDirect API password.
|
18
|
+
#
|
19
|
+
def initialize(account, password, encrypted_password='')
|
20
|
+
encrypted_password ||= ''
|
21
|
+
|
22
|
+
@account = account
|
23
|
+
@password = password
|
24
|
+
@encrypted_password = encrypted_password
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# Create credentials from a hash.
|
30
|
+
#
|
31
|
+
# @param config [Hash] a hash which contains the EmailDirect account credentials.
|
32
|
+
#
|
33
|
+
# @return [One::EmailDirect::Credentials] the EmailDirect account credentials.
|
34
|
+
#
|
35
|
+
def self.create_from(config)
|
36
|
+
return One::EmailDirect::Credentials.new(
|
37
|
+
config[:account],
|
38
|
+
config[:password],
|
39
|
+
config[:encrypted_password])
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class One::EmailDirect::Facade
|
2
|
+
extend One::EmailDirect::Mixins::EmailFacade
|
3
|
+
extend One::EmailDirect::Mixins::ListFacade
|
4
|
+
extend One::EmailDirect::Mixins::PublicationFacade
|
5
|
+
extend One::EmailDirect::Mixins::SourceFacade
|
6
|
+
|
7
|
+
class << self; attr_reader :templates end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Loads the SOAP envelope templates.
|
12
|
+
def self.load_templates()
|
13
|
+
@templates ||= {}
|
14
|
+
root_directory = File.dirname(__FILE__)
|
15
|
+
directories = [
|
16
|
+
"#{root_directory}/mixins/template/email/*.rbxml",
|
17
|
+
"#{root_directory}/mixins/template/list/*.rbxml",
|
18
|
+
"#{root_directory}/mixins/template/publication/*.rbxml",
|
19
|
+
"#{root_directory}/mixins/template/source/*.rbxml"
|
20
|
+
]
|
21
|
+
directories.each {|template_directory|
|
22
|
+
Dir.glob(template_directory) {|template|
|
23
|
+
soap_version = File.basename(template)[4..6]
|
24
|
+
template_name = File.basename(template)[7..-7] # remove initial soapxy_ and final .rbxml
|
25
|
+
@templates[template_name.to_sym] ||= {}
|
26
|
+
@templates[template_name.to_sym][soap_version.to_i] = template
|
27
|
+
# TODO move this to log file
|
28
|
+
# TODO log puts "loaded template :#{template_name} => #{template}"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
def self.create_soap_envelope(method, context)
|
36
|
+
raise StandardError, 'There is not template for method %s!' % [method] if !self.templates.has_key? method
|
37
|
+
view = Tenjin::Engine.new().render(self.templates[method][context[:soap_version]], context)
|
38
|
+
# TODO log puts '%s\n\t%s' % [method, view]
|
39
|
+
view
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
# Sends a SOAP request to a web service.
|
45
|
+
#
|
46
|
+
# @param method [String] the symbol that represents the web service to contact.
|
47
|
+
# @param context [Hash] a series of key value pairs to build up the request.
|
48
|
+
# Use a :soap_version key to 11 for SOAP1.1 envelopes or 12 for SOAP1.2.
|
49
|
+
# Use a :soap_action if you want to set a SOAPAction HTTP header.
|
50
|
+
#
|
51
|
+
# @return [Hash] the server response.
|
52
|
+
#
|
53
|
+
def self.send_soap(method, context)
|
54
|
+
context[:soap_version] ||= 11 # by default use SOAP 1.1
|
55
|
+
# TODO validate versions
|
56
|
+
# TODO log method and context
|
57
|
+
action = context.has_key?(:soap_action) ? context[:soap_action] : nil
|
58
|
+
client = One::EmailDirect::Client.new action
|
59
|
+
#client.http.headers['SOAPAction'] = action
|
60
|
+
response = client.request method do |soap|
|
61
|
+
soap.xml = create_soap_envelope(method, context)
|
62
|
+
# TODO log soap envelope @ debug level
|
63
|
+
end
|
64
|
+
|
65
|
+
raise StandardError, 'Failed!\n\t%s' % [response] if !response.success?
|
66
|
+
return response.to_hash["#{method}_response".to_sym]["#{method}_result".to_sym]
|
67
|
+
rescue Savon::SOAP::Fault => fault
|
68
|
+
# TODO puts fault.to_s
|
69
|
+
raise fault
|
70
|
+
end
|
71
|
+
|
72
|
+
load_templates()
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module One::EmailDirect::Mixins::EmailFacade
|
2
|
+
|
3
|
+
# Creates a new email on the given EmailDirect account.
|
4
|
+
#
|
5
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
6
|
+
# @param email [String] the email address to be added.
|
7
|
+
# @param source_id [Fixnum] the source identifier to attach this email to.
|
8
|
+
# @param publications [Array] the publication identifiers to attach this email to.
|
9
|
+
# @param lists [Array] the list identifiers to attach this email to.
|
10
|
+
# @param autoresponder [Fixnum] the auto-responder identifier from the account.
|
11
|
+
# If '0' is provided then nothing will be sent to the email address.
|
12
|
+
# @param force [true,false] Force the addition/update/deletion of an email regardless of it's current state.
|
13
|
+
# This will preform the method called for any email that has Bounced or opted
|
14
|
+
# to be Globaly Removed from your account so please use with caution.
|
15
|
+
#
|
16
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Email_Add
|
17
|
+
#
|
18
|
+
def email_add(credentials, email, source_id, publications, lists, autoresponder=0, force=false)
|
19
|
+
# TODO: validate mandatory arguments and raise ArgumentError
|
20
|
+
response = send_soap(
|
21
|
+
:email_add,
|
22
|
+
{:soap_action => 'http://espapi.net/v1/Email_Add',
|
23
|
+
:credentials => credentials,
|
24
|
+
:email => email,
|
25
|
+
:source_id => source_id,
|
26
|
+
:publications => publications,
|
27
|
+
:lists => lists,
|
28
|
+
:autoresponder => autoresponder,
|
29
|
+
:force => force
|
30
|
+
}
|
31
|
+
)
|
32
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# Creates a new email on the given EmailDirect account.
|
38
|
+
#
|
39
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
40
|
+
# @param email [String] the email address to be added.
|
41
|
+
# @param source_id [Fixnum] the source identifier to attach this email to.
|
42
|
+
# @param publications [Array] the publication identifiers to attach this email to.
|
43
|
+
# @param lists [Array] the list identifiers to attach this email to.
|
44
|
+
# @param autoresponder [Fixnum] the auto-responder identifier from the account.
|
45
|
+
# If '0' is provided then nothing will be sent to the email address.
|
46
|
+
# @param force [true,false] Force the addition/update/deletion of an email regardless of it's current state.
|
47
|
+
# This will preform the method called for any email that has Bounced or opted
|
48
|
+
# to be Globaly Removed from your account so please use with caution.
|
49
|
+
# @param custom_fields [Hash] The CustomFields parameter allows you to pass in 0 or
|
50
|
+
# more CustomField objects to the method.
|
51
|
+
# A CustomField object is a name/value pair representing a field in your database and
|
52
|
+
# the value your are passing in.
|
53
|
+
#
|
54
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Email_AddWithFields
|
55
|
+
#
|
56
|
+
def email_addwithfields(credentials, email, source_id, publications, lists, autoresponder=0, force=false, custom_fields={})
|
57
|
+
# TODO: validate mandatory arguments and raise ArgumentError
|
58
|
+
response = send_soap(
|
59
|
+
:email_add_with_fields,
|
60
|
+
{:soap_action => 'http://espapi.net/v1/Email_AddWithFields',
|
61
|
+
:credentials => credentials,
|
62
|
+
:email => email,
|
63
|
+
:source_id => source_id,
|
64
|
+
:publications => publications,
|
65
|
+
:lists => lists,
|
66
|
+
:autoresponder => autoresponder,
|
67
|
+
:force => force,
|
68
|
+
:custom_fields => custom_fields
|
69
|
+
}
|
70
|
+
)
|
71
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
# Deletes an email from the given EmailDirect account.
|
77
|
+
#
|
78
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
79
|
+
# @param email [String] the email address to be deleted.
|
80
|
+
# @param force [true,false] Force the addition/update/deletion of an email regardless of it's current state.
|
81
|
+
# This will preform the method called for any email that has Bounced or opted
|
82
|
+
# to be Globaly Removed from your account so please use with caution.
|
83
|
+
#
|
84
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Email_Delete
|
85
|
+
#
|
86
|
+
def email_delete(credentials, email, force)
|
87
|
+
response = send_soap(
|
88
|
+
:email_delete,
|
89
|
+
{:soap_action => 'http://espapi.net/v1/Email_Delete',
|
90
|
+
:credentials => credentials,
|
91
|
+
:email => email,
|
92
|
+
:force => force
|
93
|
+
}
|
94
|
+
)
|
95
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
# Returns all all properties associated with an email address.
|
101
|
+
#
|
102
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
103
|
+
#
|
104
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Email_GetProperties
|
105
|
+
#
|
106
|
+
# @return [Hash] Example:
|
107
|
+
# {:date_stamp=>#<DateTime: 1768098599/720,0,2299161>, :ip_address=>nil, :status=>"Active",
|
108
|
+
# :publications=>{:element=>{:element_id=>"579",
|
109
|
+
# :description=>"descriptionf43123305dc9012e06f234159e028042",
|
110
|
+
# :element_name=>"namef43123305dc9012e06f234159e028042"}}, :lists=>{:element=>{:element_id=>"622",
|
111
|
+
# :description=>"descriptionf43123305dc9012e06f234159e028042",
|
112
|
+
# :element_name=>"namef43123305dc9012e06f234159e028042"}},
|
113
|
+
# :email=>"john.doe.f43123305dc9012e06f234159e028042@1on1.com", :email_id=>"108",
|
114
|
+
# :custom_fields=>{:custom_field=>[{:value=>"john.doe.f43123305dc9012e06f234159e028042@1on1.com",
|
115
|
+
# :field_name=>"Email"}, {:value=>nil, :field_name=>"IPAddress"}, {:value=>"5/10/2011",
|
116
|
+
# :field_name=>"DateStamp"}, {:value=>"John", :field_name=>"FirstName"},
|
117
|
+
# {:value=>"Doe", :field_name=>"LastName"}, {:value=>"30", :field_name=>"Age"}]},
|
118
|
+
# :create_date=>#<DateTime: 1768098599/720,0,2299161>, :source=>{:element_id=>"452",
|
119
|
+
# :description=>"descriptionf43123305dc9012e06f234159e028042",
|
120
|
+
# :element_name=>"namef43123305dc9012e06f234159e028042"}}
|
121
|
+
#
|
122
|
+
#
|
123
|
+
def email_getproperties(credentials, email)
|
124
|
+
response = send_soap(
|
125
|
+
:email_get_properties,
|
126
|
+
{:soap_action => 'http://espapi.net/v1/Email_GetProperties',
|
127
|
+
:credentials => credentials,
|
128
|
+
:email => email
|
129
|
+
}
|
130
|
+
)
|
131
|
+
|
132
|
+
if !response.nil?
|
133
|
+
# make response consistent
|
134
|
+
if !response[:lists].nil?
|
135
|
+
lists = response[:lists][:element]
|
136
|
+
response[:lists][:element] = [lists] if lists.instance_of? Hash
|
137
|
+
else
|
138
|
+
response[:lists] = {:element => []}
|
139
|
+
end
|
140
|
+
|
141
|
+
if !response[:publications].nil?
|
142
|
+
publications = response[:publications][:element]
|
143
|
+
response[:publications][:element] = [publications] if publications.instance_of? Hash
|
144
|
+
else
|
145
|
+
response[:publications] = {:element => []}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
response
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module One::EmailDirect::Mixins::ListFacade
|
2
|
+
|
3
|
+
# Creates a new list on the given EmailDirect account.
|
4
|
+
#
|
5
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
6
|
+
# @param name [String] the list name.
|
7
|
+
# @param description [String] the list description.
|
8
|
+
#
|
9
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=List_Add
|
10
|
+
#
|
11
|
+
def list_add(credentials, name, description)
|
12
|
+
response = send_soap(
|
13
|
+
:list_add,
|
14
|
+
{:soap_action => 'http://espapi.net/v1/List_Add',
|
15
|
+
:credentials => credentials,
|
16
|
+
:list_name => name,
|
17
|
+
:list_description => description}
|
18
|
+
)
|
19
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
# Deletes a list from the given EmailDirect account.
|
25
|
+
#
|
26
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
27
|
+
# @param list_id [Fixnum] the unique identifier of the list to be deleted.
|
28
|
+
#
|
29
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=List_Delete
|
30
|
+
#
|
31
|
+
def list_delete(credentials, list_id)
|
32
|
+
response = send_soap(
|
33
|
+
:list_delete,
|
34
|
+
{:soap_action => 'http://espapi.net/v1/List_Delete',
|
35
|
+
:credentials => credentials,
|
36
|
+
:list_id => list_id}
|
37
|
+
)
|
38
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# Returns the whole information of a list on the given EmailDirect account.
|
44
|
+
#
|
45
|
+
# @param credentials [
|
46
|
+
# @param name [String] the name of the list.
|
47
|
+
#
|
48
|
+
# @return [Hash] a hash that describes the list.
|
49
|
+
#
|
50
|
+
def list_get(credentials, name)
|
51
|
+
list_getall(credentials).each {|element| return element if element[:element_name] == name}
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# Returns all lists on the given EmailDirect account.
|
58
|
+
#
|
59
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
60
|
+
#
|
61
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=List_GetAll
|
62
|
+
#
|
63
|
+
# @return [Hash] TODO {:description=>"a description.", :element_name=>"name12353", :element_id=>"170"}
|
64
|
+
#
|
65
|
+
def list_getall(credentials)
|
66
|
+
response = send_soap(
|
67
|
+
:list_get_all,
|
68
|
+
{:soap_action => 'http://espapi.net/v1/List_GetAll',
|
69
|
+
:credentials => credentials}
|
70
|
+
)
|
71
|
+
|
72
|
+
# no elements were returned
|
73
|
+
return [] if response.nil?
|
74
|
+
|
75
|
+
# if it only has one element (Hash) you have to transform it to a single array element
|
76
|
+
return [response[:element]] if response[:element].instance_of? Hash
|
77
|
+
|
78
|
+
# more than 1 element
|
79
|
+
if !block_given?
|
80
|
+
elements = []
|
81
|
+
response[:element].each {|element|
|
82
|
+
elements << element
|
83
|
+
}
|
84
|
+
elements
|
85
|
+
else
|
86
|
+
response[:element].each {|element| yield element }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
# Returns all subscribers associated to a list on the given EmailDirect account.
|
93
|
+
#
|
94
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
95
|
+
# @param list_id [Fixnum] the unique identifier of the list.
|
96
|
+
# @param page_size [Fixnum] the number of subscribers to present per page.
|
97
|
+
# @param page_number [Fixnum] the page number to present.
|
98
|
+
#
|
99
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=List_GetMembers
|
100
|
+
#
|
101
|
+
# @return [Hash] TODO {:description=>"a description.", :element_name=>"name12353", :element_id=>"170"}
|
102
|
+
#
|
103
|
+
def list_getmembers(credentials, list_id, page_size, page_number)
|
104
|
+
response = send_soap(
|
105
|
+
:list_getmembers,
|
106
|
+
{:soap_action => 'http://espapi.net/v1/List_GetMembers',
|
107
|
+
:credentials => credentials,
|
108
|
+
:list_id => list_id,
|
109
|
+
:page_size => page_size,
|
110
|
+
:page_number => page_number}
|
111
|
+
)
|
112
|
+
|
113
|
+
|
114
|
+
# no elements were returned
|
115
|
+
return [] if response.nil?
|
116
|
+
|
117
|
+
# if it only has one element (Hash) you have to transform it to a single array element
|
118
|
+
return [response[:element]] if response[:element].instance_of? Hash
|
119
|
+
|
120
|
+
# more than 1 element
|
121
|
+
if !block_given?
|
122
|
+
elements = []
|
123
|
+
response[:element].each {|element|
|
124
|
+
elements << element
|
125
|
+
}
|
126
|
+
elements
|
127
|
+
else
|
128
|
+
response[:element].each {|element| yield element }
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module One::EmailDirect::Mixins::PublicationFacade
|
2
|
+
|
3
|
+
# Creates a new publication on the given EmailDirect account.
|
4
|
+
#
|
5
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
6
|
+
# @param name [String] the publication name.
|
7
|
+
# @param description [String] the publication description.
|
8
|
+
#
|
9
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Publication_Add
|
10
|
+
#
|
11
|
+
def publication_add(credentials, name, description)
|
12
|
+
response = send_soap(
|
13
|
+
:publication_add,
|
14
|
+
{:soap_action => 'http://espapi.net/v1/Publication_Add',
|
15
|
+
:credentials => credentials,
|
16
|
+
:publication_name => name,
|
17
|
+
:publication_description => description}
|
18
|
+
)
|
19
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
# Deletes a publication on the given EmailDirect account.
|
25
|
+
#
|
26
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
27
|
+
# @param publication_id [Fixnum] the unique identifier of the publication to be deleted.
|
28
|
+
#
|
29
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Publication_Delete
|
30
|
+
#
|
31
|
+
def publication_delete(credentials, publication_id)
|
32
|
+
response = send_soap(
|
33
|
+
:publication_delete,
|
34
|
+
{:soap_action => 'http://espapi.net/v1/Publication_Delete',
|
35
|
+
:credentials => credentials,
|
36
|
+
:publication_id => publication_id}
|
37
|
+
)
|
38
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# Returns the whole information of a publication on the given EmailDirect account.
|
44
|
+
#
|
45
|
+
# @param credentials [
|
46
|
+
# @param name [String] the name of the publication.
|
47
|
+
#
|
48
|
+
# @return [Hash] a hash that describes the publication.
|
49
|
+
#
|
50
|
+
def publication_get(credentials, name)
|
51
|
+
publication_getall(credentials).each {|element| return element if element[:element_name] == name}
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# Returns all publications on the given EmailDirect account.
|
58
|
+
#
|
59
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
60
|
+
#
|
61
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Publication_GetAll
|
62
|
+
#
|
63
|
+
# @return [Array] all of the publications.
|
64
|
+
# [{:description=>"a description.", :element_name=>"name12353", :element_id=>"170"}, ...]
|
65
|
+
#
|
66
|
+
def publication_getall(credentials)
|
67
|
+
response = send_soap(
|
68
|
+
:publication_get_all,
|
69
|
+
{:soap_action => 'http://espapi.net/v1/Publication_GetAll',
|
70
|
+
:credentials => credentials}
|
71
|
+
)
|
72
|
+
|
73
|
+
# no elements were returned
|
74
|
+
return [] if response.nil?
|
75
|
+
|
76
|
+
# if it only has one element (Hash) you have to transform it to a single array element
|
77
|
+
return [response[:element]] if response[:element].instance_of? Hash
|
78
|
+
|
79
|
+
# more than 1 element
|
80
|
+
if !block_given?
|
81
|
+
elements = []
|
82
|
+
response[:element].each {|element|
|
83
|
+
elements << element
|
84
|
+
}
|
85
|
+
elements
|
86
|
+
else
|
87
|
+
response[:element].each {|element| yield element }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module One::EmailDirect::Mixins::SourceFacade
|
2
|
+
|
3
|
+
# Creates a new source on the given EmailDirect account.
|
4
|
+
#
|
5
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
6
|
+
# @param name [String] the source name.
|
7
|
+
# @param description [String] the source description.
|
8
|
+
#
|
9
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Source_Add
|
10
|
+
#
|
11
|
+
def source_add(credentials, name, description)
|
12
|
+
response = send_soap(
|
13
|
+
:source_add,
|
14
|
+
{:soap_action => 'http://espapi.net/v1/Source_Add',
|
15
|
+
:credentials => credentials,
|
16
|
+
:source_name => name,
|
17
|
+
:source_description => description}
|
18
|
+
)
|
19
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
# Deletes a source on the given EmailDirect account.
|
25
|
+
#
|
26
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
27
|
+
# @param source_id [Fixnum] the unique identifier of the source to be deleted.
|
28
|
+
#
|
29
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=Source_Delete
|
30
|
+
#
|
31
|
+
def source_delete(credentials, source_id)
|
32
|
+
response = send_soap(
|
33
|
+
:source_delete,
|
34
|
+
{:soap_action => 'http://espapi.net/v1/Source_Delete',
|
35
|
+
:credentials => credentials,
|
36
|
+
:source_id => source_id}
|
37
|
+
)
|
38
|
+
raise StandardError, '[%s] %s' % [response[:code], response[:message]] if response[:code] != '0'
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# Returns the whole information of a source on the given EmailDirect account.
|
44
|
+
#
|
45
|
+
# @param credentials [
|
46
|
+
# @param name [String] the name of the source.
|
47
|
+
#
|
48
|
+
# @return [Hash] a hash that describes the source.
|
49
|
+
#
|
50
|
+
def source_get(credentials, name)
|
51
|
+
source_getall(credentials).each {|element| return element if element[:element_name] == name}
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# Returns all sources on the given EmailDirect account.
|
58
|
+
#
|
59
|
+
# @param credentials [One::EmailDirect::Credentials] EmailDirect API credentials.
|
60
|
+
#
|
61
|
+
# http://dev.emaildirect.com/v1/api.asmx?op=source_GetAll
|
62
|
+
#
|
63
|
+
# @return [Hash] TODO {:description=>"a description.", :element_name=>"name12353", :element_id=>"170"}
|
64
|
+
#
|
65
|
+
def source_getall(credentials)
|
66
|
+
response = send_soap(
|
67
|
+
:source_get_all,
|
68
|
+
{:soap_action => 'http://espapi.net/v1/Source_GetAll',
|
69
|
+
:credentials => credentials}
|
70
|
+
)
|
71
|
+
|
72
|
+
# no elements were returned
|
73
|
+
return [] if response.nil?
|
74
|
+
|
75
|
+
# if it only has one element (Hash) you have to transform it to a single array element
|
76
|
+
return [response[:element]] if response[:element].instance_of? Hash
|
77
|
+
|
78
|
+
# more than 1 element
|
79
|
+
if !block_given?
|
80
|
+
elements = []
|
81
|
+
response[:element].each {|element|
|
82
|
+
elements << element
|
83
|
+
}
|
84
|
+
elements
|
85
|
+
else
|
86
|
+
response[:element].each {|element| yield element }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_header.rbxml" ?>
|
2
|
+
|
3
|
+
<Email_Add xmlns="http://espapi.net/v1/">
|
4
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_credentials.rbxml" ?>
|
5
|
+
|
6
|
+
<Email>${ @email }</Email>
|
7
|
+
<SourceID>${ @source_id }</SourceID>
|
8
|
+
<?rb if !@publications.nil? and !@publications.empty? ?>
|
9
|
+
<Publications>
|
10
|
+
<?rb for publication in @publications ?>
|
11
|
+
<int>${ publication }</int>
|
12
|
+
<?rb end ?>
|
13
|
+
</Publications>
|
14
|
+
<?rb end ?>
|
15
|
+
<?rb if !@lists.nil? and !@lists.empty? ?>
|
16
|
+
<Lists>
|
17
|
+
<?rb for list in @lists ?>
|
18
|
+
<int>${ list }</int>
|
19
|
+
<?rb end ?>
|
20
|
+
</Lists>
|
21
|
+
<?rb end ?>
|
22
|
+
<AutoResponderID>${ @autoresponder }</AutoResponderID>
|
23
|
+
<Force>${ @force }</Force>
|
24
|
+
</Email_Add>
|
25
|
+
|
26
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_footer.rbxml" ?>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import "#{File.dirname(__FILE__)}/../soap11_header.rbxml"
|
2
|
+
_buf << %Q`
|
3
|
+
<Email_Add xmlns="http://espapi.net/v1/">\n`
|
4
|
+
import "#{File.dirname(__FILE__)}/../soap11_credentials.rbxml"
|
5
|
+
_buf << %Q`
|
6
|
+
<Email>#{escape(( @email ).to_s)}</Email>
|
7
|
+
<SourceID>#{escape(( @source_id ).to_s)}</SourceID>\n`
|
8
|
+
if !@publications.nil? and !@publications.empty?
|
9
|
+
_buf << %Q` <Publications>\n`
|
10
|
+
for publication in @publications
|
11
|
+
_buf << %Q` <int>#{escape(( publication ).to_s)}</int>\n`
|
12
|
+
end
|
13
|
+
_buf << %Q` </Publications>\n`
|
14
|
+
end
|
15
|
+
if !@lists.nil? and !@lists.empty?
|
16
|
+
_buf << %Q` <Lists>\n`
|
17
|
+
for list in @lists
|
18
|
+
_buf << %Q` <int>#{escape(( list ).to_s)}</int>\n`
|
19
|
+
end
|
20
|
+
_buf << %Q` </Lists>\n`
|
21
|
+
end
|
22
|
+
_buf << %Q` <AutoResponderID>#{escape(( @autoresponder ).to_s)}</AutoResponderID>
|
23
|
+
<Force>#{escape(( @force ).to_s)}</Force>
|
24
|
+
</Email_Add>
|
25
|
+
\n`
|
26
|
+
import "#{File.dirname(__FILE__)}/../soap11_footer.rbxml";
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_header.rbxml" ?>
|
2
|
+
|
3
|
+
<Email_AddWithFields xmlns="http://espapi.net/v1/">
|
4
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_credentials.rbxml" ?>
|
5
|
+
|
6
|
+
<Email>${ @email }</Email>
|
7
|
+
<SourceID>${ @source_id }</SourceID>
|
8
|
+
<?rb if !@publications.nil? and !@publications.empty? ?>
|
9
|
+
<Publications>
|
10
|
+
<?rb for publication in @publications ?>
|
11
|
+
<int>${ publication }</int>
|
12
|
+
<?rb end ?>
|
13
|
+
</Publications>
|
14
|
+
<?rb end ?>
|
15
|
+
<?rb if !@lists.nil? and !@lists.empty? ?>
|
16
|
+
<Lists>
|
17
|
+
<?rb for list in @lists ?>
|
18
|
+
<int>${ list }</int>
|
19
|
+
<?rb end ?>
|
20
|
+
</Lists>
|
21
|
+
<?rb end ?>
|
22
|
+
<AutoResponderID>${ @autoresponder }</AutoResponderID>
|
23
|
+
<Force>${ @force }</Force>
|
24
|
+
<CustomFields>
|
25
|
+
<?rb @custom_fields.each {|key, value| ?>
|
26
|
+
<CustomField>
|
27
|
+
<FieldName>${ key }</FieldName>
|
28
|
+
<Value>${ value }</Value>
|
29
|
+
</CustomField>
|
30
|
+
<?rb } ?>
|
31
|
+
</CustomFields>
|
32
|
+
</Email_AddWithFields>
|
33
|
+
|
34
|
+
<?rb import "#{File.dirname(__FILE__)}/../soap11_footer.rbxml" ?>
|