emaildirect 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ require 'emaildirect'
2
+
3
+ module EmailDirect::RelaySend
4
+ end
5
+ require 'emaildirect/relay_send/category'
6
+ require 'emaildirect/relay_send/receipt'
7
+ require 'emaildirect/relay_send/email'
@@ -0,0 +1,51 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a relay send category and associated functionality
6
+ class RelaySend::Category
7
+ class << self
8
+ def all
9
+ response = EmailDirect.get '/RelaySends'
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def create(category_name)
14
+ response = EmailDirect.post '/RelaySends', :body => category_name.to_json
15
+ Hashie::Mash.new(response)
16
+ end
17
+ end
18
+
19
+ attr_reader :category_id
20
+
21
+ def initialize(category_id)
22
+ @category_id = category_id
23
+ end
24
+
25
+ def details
26
+ response = get
27
+ Hashie::Mash.new(response)
28
+ end
29
+
30
+ def update(category_name)
31
+ response = EmailDirect.put uri_for, :body => category_name.to_json
32
+ Hashie::Mash.new(response)
33
+ end
34
+
35
+ def delete
36
+ response = EmailDirect.delete uri_for, {}
37
+ Hashie::Mash.new(response)
38
+ end
39
+
40
+ private
41
+
42
+ def get(action = nil)
43
+ EmailDirect.get uri_for(action)
44
+ end
45
+
46
+ def uri_for(action = nil)
47
+ action = "/#{action}" if action
48
+ "/RelaySends/#{category_id}#{action}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a relay send custom email
6
+ class RelaySend::Email
7
+ attr_reader :category_id
8
+
9
+ def initialize(category_id)
10
+ @category_id = category_id
11
+ raise ArgumentError, 'Category ID is required' unless @category_id
12
+ end
13
+
14
+ # Sends a custom message. See the docs for all the possible options
15
+ # @see https://docs.emaildirect.com/#RelaySendCustomEmail
16
+ def send(options)
17
+ response = EmailDirect.post "/RelaySends/#{category_id}", :body => options.to_json
18
+ Hashie::Mash.new(response)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a relay send receipt and associated functionality
6
+ class RelaySend::Receipt
7
+ attr_reader :receipt_id
8
+
9
+ def initialize(receipt_id)
10
+ @receipt_id = receipt_id
11
+ end
12
+
13
+ def details
14
+ response = get
15
+ Hashie::Mash.new(response)
16
+ end
17
+
18
+ def message
19
+ response = get 'Message'
20
+ Hashie::Mash.new(response)
21
+ end
22
+
23
+ def clicks
24
+ response = get 'Clicks'
25
+ Hashie::Mash.new(response)
26
+ end
27
+
28
+ private
29
+
30
+ def get(action = nil)
31
+ EmailDirect.get uri_for(action)
32
+ end
33
+
34
+ def uri_for(action)
35
+ action = "/#{action}" if action
36
+ "/RelaySends/Receipt/#{receipt_id}#{action}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,53 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a short url and associated functionality
6
+ class ShortUrl
7
+ class << self
8
+ def all(options = {})
9
+ response = EmailDirect.get uri, :query => options
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def create(url)
14
+ options = { :Url => url }
15
+ response = EmailDirect.post uri, :body => options.to_json
16
+ Hashie::Mash.new(response)
17
+ end
18
+
19
+ def uri
20
+ '/ShortUrls'
21
+ end
22
+ end
23
+
24
+ attr_reader :short_url
25
+
26
+ def initialize(short_url)
27
+ @short_url = short_url
28
+ end
29
+
30
+ def details
31
+ response = EmailDirect.get self.class.uri, query
32
+ Hashie::Mash.new(response)
33
+ end
34
+
35
+ def update(new_url)
36
+ response = EmailDirect.put self.class.uri, query.merge(:body => new_url.to_json)
37
+ Hashie::Mash.new(response)
38
+ end
39
+
40
+ def clicks(options = {})
41
+ options.merge! :url => short_url
42
+ response = EmailDirect.get '/ShortUrls/Clicks', :query => options
43
+ Hashie::Mash.new(response)
44
+ end
45
+
46
+ private
47
+
48
+ def query
49
+ { :query => { :url => short_url } }
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,65 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a source and associated functionality
6
+ class Source
7
+ class << self
8
+ def all
9
+ response = EmailDirect.get '/Sources'
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def create(name, options = {})
14
+ options.merge! :Name => name
15
+ response = EmailDirect.post '/Sources', :body => options.to_json
16
+ Hashie::Mash.new(response)
17
+ end
18
+ end
19
+
20
+ attr_reader :source_id
21
+
22
+ def initialize(source_id)
23
+ @source_id = source_id
24
+ end
25
+
26
+ def details
27
+ response = get
28
+ Hashie::Mash.new(response)
29
+ end
30
+
31
+ def members(options = {})
32
+ response = get 'Members', options
33
+ Hashie::Mash.new(response)
34
+ end
35
+
36
+ def update(name, options)
37
+ options.merge! :Name => name
38
+ response = EmailDirect.put uri_for, :body => options.to_json
39
+ Hashie::Mash.new(response)
40
+ end
41
+
42
+ def delete
43
+ response = EmailDirect.delete uri_for, {}
44
+ Hashie::Mash.new(response)
45
+ end
46
+
47
+ def add_emails(email_addresses)
48
+ options = { :EmailAddresses => email_addresses.to_a }
49
+ response = EmailDirect.post uri_for('AddEmails'), :body => options.to_json
50
+ Hashie::Mash.new(response)
51
+ end
52
+
53
+ private
54
+
55
+ def get(action = nil, options = {})
56
+ EmailDirect.get uri_for(action), :query => options
57
+ end
58
+
59
+ def uri_for(action = nil)
60
+ action = "/#{action}" if action
61
+ "/Sources/#{source_id}#{action}"
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,90 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a subscriber and associated functionality
6
+ class Subscriber
7
+ class << self
8
+ def active(options = {})
9
+ response = EmailDirect.get '/Subscribers', :query => options
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def removes(options = {})
14
+ response = EmailDirect.get '/Subscribers/Removes', :query => options
15
+ Hashie::Mash.new(response)
16
+ end
17
+
18
+ def bounces(options = {})
19
+ response = EmailDirect.get '/Subscribers/Bounces', :query => options
20
+ Hashie::Mash.new(response)
21
+ end
22
+
23
+ def complaints(options = {})
24
+ response = EmailDirect.get '/Subscribers/Complaints', :query => options
25
+ Hashie::Mash.new(response)
26
+ end
27
+
28
+ def create(email, options = {})
29
+ options.merge! :EmailAddress => email
30
+ response = EmailDirect.post '/Subscribers', :body => options.to_json
31
+ Hashie::Mash.new(response)
32
+ end
33
+ end
34
+
35
+ attr_reader :email
36
+
37
+ def initialize(email)
38
+ @email = email
39
+ end
40
+
41
+ def details
42
+ response = get
43
+ Hashie::Mash.new(response)
44
+ end
45
+
46
+ def properties
47
+ response = get 'Properties'
48
+ Hashie::Mash.new(response)
49
+ end
50
+
51
+ def history
52
+ response = get 'History'
53
+ Hashie::Mash.new(response)
54
+ end
55
+
56
+ def update(options)
57
+ options.merge! :EmailAddress => email
58
+ response = EmailDirect.put uri_for, :body => options.to_json
59
+ Hashie::Mash.new(response)
60
+ end
61
+
62
+ def delete
63
+ response = EmailDirect.delete uri_for, {}
64
+ Hashie::Mash.new(response)
65
+ end
66
+
67
+ def remove
68
+ options = { :EmailAddress => email }
69
+ response = EmailDirect.post '/Subscribers/Remove', :body => options.to_json
70
+ Hashie::Mash.new(response)
71
+ end
72
+
73
+ def change_email(new_email)
74
+ options = { :EmailAddress => new_email }
75
+ response = EmailDirect.post uri_for('ChangeEmail'), :body => options.to_json
76
+ Hashie::Mash.new(response)
77
+ end
78
+
79
+ private
80
+
81
+ def get(action = nil)
82
+ EmailDirect.get uri_for(action)
83
+ end
84
+
85
+ def uri_for(action = nil)
86
+ action = "/#{action}" if action
87
+ "/Subscribers/#{email}#{action}"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,89 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a list and associated functionality
6
+ class SuppressionList
7
+ class << self
8
+ def all
9
+ response = EmailDirect.get '/SuppressionLists'
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def create(name)
14
+ response = EmailDirect.post '/SuppressionLists', :body => name.to_json
15
+ Hashie::Mash.new(response)
16
+ end
17
+ end
18
+
19
+ attr_reader :suppression_list_id
20
+
21
+ def initialize(suppression_list_id)
22
+ @suppression_list_id = suppression_list_id
23
+ end
24
+
25
+ def details
26
+ response = get
27
+ Hashie::Mash.new(response)
28
+ end
29
+
30
+ def emails(options = {})
31
+ response = get 'Emails', :query => options
32
+ Hashie::Mash.new(response)
33
+ end
34
+
35
+ def domains(options = {})
36
+ response = get 'Domains', :query => options
37
+ Hashie::Mash.new(response)
38
+ end
39
+
40
+ def update(name)
41
+ response = EmailDirect.put uri_for, :body => name.to_json
42
+ Hashie::Mash.new(response)
43
+ end
44
+
45
+ def delete
46
+ response = EmailDirect.delete uri_for, {}
47
+ Hashie::Mash.new(response)
48
+ end
49
+
50
+ def add_emails(email_addresses)
51
+ options = { :EmailAddresses => email_addresses.to_a }
52
+ response = post 'AddEmails', :body => options.to_json
53
+ Hashie::Mash.new(response)
54
+ end
55
+
56
+ def remove_emails(email_addresses)
57
+ options = { :EmailAddresses => email_addresses.to_a }
58
+ response = post 'RemoveEmails', :body => options.to_json
59
+ Hashie::Mash.new(response)
60
+ end
61
+
62
+ def add_domains(domain_addresses)
63
+ options = { :DomainNames => domain_addresses.to_a }
64
+ response = post 'AddDomains', :body => options.to_json
65
+ Hashie::Mash.new(response)
66
+ end
67
+
68
+ def remove_domains(domain_addresses)
69
+ options = { :DomainNames => domain_addresses.to_a }
70
+ response = post 'RemoveDomains', :body => options.to_json
71
+ Hashie::Mash.new(response)
72
+ end
73
+
74
+ private
75
+
76
+ def post(action, options)
77
+ EmailDirect.post uri_for(action), options
78
+ end
79
+
80
+ def get(action = nil, options = {})
81
+ EmailDirect.get uri_for(action), options
82
+ end
83
+
84
+ def uri_for(action = nil)
85
+ action = "/#{action}" if action
86
+ "/SuppressionLists/#{suppression_list_id}#{action}"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module EmailDirect
2
+ VERSION = "1.0.0" unless defined?(EmailDirect::VERSION)
3
+ end
@@ -0,0 +1,88 @@
1
+ require 'emaildirect'
2
+ require 'json'
3
+
4
+ module EmailDirect
5
+ # Represents a workflow and associated functionality
6
+ class Workflow
7
+ class << self
8
+ def all
9
+ response = EmailDirect.get '/Workflows'
10
+ Hashie::Mash.new(response)
11
+ end
12
+ end
13
+
14
+ attr_reader :workflow_id
15
+
16
+ def initialize(workflow_id)
17
+ @workflow_id = workflow_id
18
+ end
19
+
20
+ def details
21
+ response = get
22
+ Hashie::Mash.new(response)
23
+ end
24
+
25
+ def members(options = {})
26
+ response = get 'Members', :query => options
27
+ Hashie::Mash.new(response)
28
+ end
29
+
30
+ def stats(options = {})
31
+ response = get 'Stats', :query => options
32
+ Hashie::Mash.new(response)
33
+ end
34
+
35
+ def send_nodes
36
+ response = get 'SendNodes'
37
+ Hashie::Mash.new(response)
38
+ end
39
+
40
+ def send_node_details(send_node_id)
41
+ response = get "SendNodes/#{send_node_id}"
42
+ Hashie::Mash.new(response)
43
+ end
44
+
45
+ def send_node_stats(send_node_id, options = {})
46
+ response = get "SendNodes/#{send_node_id}/Stats", :query => options
47
+ Hashie::Mash.new(response)
48
+ end
49
+
50
+ def start
51
+ response = EmailDirect.put '/Workflows/Start', :body => workflow_id.to_json
52
+ Hashie::Mash.new(response)
53
+ end
54
+
55
+ def stop
56
+ response = EmailDirect.put '/Workflows/Stop', :body => workflow_id.to_json
57
+ Hashie::Mash.new(response)
58
+ end
59
+
60
+ def add_emails(email_addresses)
61
+ options = { :EmailAddresses => email_addresses.to_a }
62
+ response = post 'AddEmails', :body => options.to_json
63
+ Hashie::Mash.new(response)
64
+ end
65
+
66
+ def remove_emails(email_addresses)
67
+ options = { :EmailAddresses => email_addresses.to_a }
68
+ response = post 'RemoveEmails', :body => options.to_json
69
+ Hashie::Mash.new(response)
70
+ end
71
+
72
+ private
73
+
74
+ def post(action, options)
75
+ EmailDirect.post uri_for(action), options
76
+ end
77
+
78
+ def get(action = nil, options = {})
79
+ EmailDirect.get uri_for(action), options
80
+ end
81
+
82
+ def uri_for(action = nil)
83
+ action = "/#{action}" if action
84
+ "/Workflows/#{workflow_id}#{action}"
85
+ end
86
+ end
87
+ end
88
+