sfmc_emailer 0.0.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -0
- data/lib/sfmc/errors.rb +0 -2
- data/lib/sfmc/transactional/email.rb +4 -4
- data/lib/sfmc/transactional/send_definition.rb +6 -6
- metadata +50 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784c3443d92f1e20640d6df8652b028099b7e88c7db36dfc35655cfb7efd158e
|
4
|
+
data.tar.gz: bc658a904d420d4183a8b06725bf4ea3ff3ef04650fb323c3d15d428191a79a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ab0333fea8c05c3951b6c37ec09b51cccb2e252d209b42207cd4461da1bdc659d8d7e2c21eb922a55305ddcd43198b52042670722eab6e9bd5d45d55732c20b
|
7
|
+
data.tar.gz: 07b1be656a13c724cc1793975b622eac445a2676a803a497a4cccb879e5d44abae993a82d8960d4ce8fdb6bf1b6768cdb74e3c4e1cdd4c3a836c346c9699a292
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Salesforce Marketing Cloud (SFMC) Emailer
|
2
|
+
Supports sending both transactional & triggered send (marketing) emails
|
3
|
+
|
4
|
+
## How to use
|
5
|
+
### Config
|
6
|
+
```ruby
|
7
|
+
# config/initializers/sfmc.rb
|
8
|
+
|
9
|
+
SFMC::SFMCBase.init(
|
10
|
+
subdomain: 'mchf5m7e9wjxn-f2xxn6l5ul1x0q',
|
11
|
+
client_id: 'client_id',
|
12
|
+
client_secret: 'super_secret',
|
13
|
+
default_send_classification: 'Default Send Classification - 293',
|
14
|
+
default_subscriber_list: 'All Subscribers - 9136',
|
15
|
+
default_data_extension: 'C4530F44-5C72-4113-8EA0-5210C9222455',
|
16
|
+
default_bcc: ['example@example.com'] # optional
|
17
|
+
)
|
18
|
+
```
|
19
|
+
|
20
|
+
### Transactional Emails
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
SFMC::Transactional::Email.send_email(
|
24
|
+
email: 'email_name',
|
25
|
+
to: 'example@example.com',
|
26
|
+
params: { # Each attribute should be present in the corresponding data extension in SFMC
|
27
|
+
First_Name: "Bob",
|
28
|
+
}
|
29
|
+
)
|
30
|
+
```
|
31
|
+
|
32
|
+
### Triggered Send Emails
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
SFMC::Triggered::Email.send_email(
|
36
|
+
email: 'email_name',
|
37
|
+
to: 'example@example.com',
|
38
|
+
params: { # Each attribute should be present in the corresponding data extension in SFMC
|
39
|
+
First_Name: "Bob",
|
40
|
+
}
|
41
|
+
)
|
42
|
+
```
|
43
|
+
|
44
|
+
<b>Note:</b> Changes to transactional emails only take effect once its send definition is refreshed:
|
45
|
+
```ruby
|
46
|
+
SFMC::Transactional::SendDefinition.refresh 'email_name'
|
47
|
+
```
|
48
|
+
|
49
|
+
### Creating a Transactional Email Send Definition
|
50
|
+
<b>Note:</b> The first time an email is sent a send definition for it will be created with the default values. This definition takes about a minute to actually become active, so try sending again after that. You can also manually create a send definition using:
|
51
|
+
```ruby
|
52
|
+
SFMC::Transactional::SendDefinition.create(
|
53
|
+
definition_key: 'definition_key',
|
54
|
+
customer_key: 'customer_key',
|
55
|
+
send_classification: 'send_classification',
|
56
|
+
subscriber_list: 'subscriber_list',
|
57
|
+
data_extension: 'data_extension',
|
58
|
+
bcc: ['example@example.com'] # optional
|
59
|
+
)
|
60
|
+
```
|
data/lib/sfmc/errors.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module SFMC
|
2
2
|
module Errors
|
3
|
-
# rubocop:disable Layout/EmptyLineBetweenDefs
|
4
3
|
class BadRequestError < StandardError; end
|
5
4
|
class UnauthorizedError < StandardError; end
|
6
5
|
class ForbiddenError < StandardError; end
|
7
6
|
class NotFoundError < StandardError; end
|
8
7
|
class UnprocessableEntityError < StandardError; end
|
9
8
|
class APIError < StandardError; end
|
10
|
-
# rubocop:enable Layout/EmptyLineBetweenDefs
|
11
9
|
|
12
10
|
def error_class(code)
|
13
11
|
case code.to_i
|
@@ -6,16 +6,16 @@ module SFMC
|
|
6
6
|
# If an email hasn't ever been sent then we will not have an email send definition
|
7
7
|
# We're waiting a minute for the send definition to fully be initialized
|
8
8
|
# Thankfully this is a rare edge case
|
9
|
-
def self.
|
9
|
+
def self.create_email_send_definition(name)
|
10
10
|
asset = SFMC::Assets::Asset.query("name eq '#{name}'", 'customerKey')
|
11
11
|
raise SFMC::Errors::BadRequestError, "No emails found with name #{name}" if asset.count == 0
|
12
12
|
|
13
13
|
consumer_key = asset.items.first["customerKey"]
|
14
14
|
|
15
|
-
SFMC::Transactional::SendDefinition.create(name, consumer_key)
|
15
|
+
SFMC::Transactional::SendDefinition.create(definition_key: name, customer_key: consumer_key)
|
16
16
|
|
17
17
|
# Even though the send def is "Active" it won't function for another minute
|
18
|
-
|
18
|
+
pp "Email send definition inactive. Try again in a minute"
|
19
19
|
end
|
20
20
|
|
21
21
|
# Will attempt once to create a new email send definition if one isn't found
|
@@ -43,7 +43,7 @@ module SFMC
|
|
43
43
|
rescue SFMC::Errors::NotFoundError
|
44
44
|
raise unless create_email_if_needed
|
45
45
|
|
46
|
-
|
46
|
+
create_email_send_definition(email)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -9,12 +9,12 @@ module SFMC
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.create(
|
12
|
-
definition_key
|
13
|
-
customer_key
|
14
|
-
send_classification
|
15
|
-
subscriber_list
|
16
|
-
data_extension
|
17
|
-
bcc
|
12
|
+
definition_key:,
|
13
|
+
customer_key:,
|
14
|
+
send_classification: nil,
|
15
|
+
subscriber_list: nil,
|
16
|
+
data_extension: nil,
|
17
|
+
bcc: []
|
18
18
|
)
|
19
19
|
params = {
|
20
20
|
classification: SFMCBase.default_send_classification || send_classification,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfmc_emailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angel Ruiz-Bates
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.20'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.20'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,49 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.20'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.20'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: webmock
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.18.1
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.18.1
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.18.1
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.18.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.11.0
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.11.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.11.0
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.11.0
|
27
73
|
description: API wrapper for Salesforce Marketing Cloud's Transactional and Triggered
|
28
74
|
Send APIs
|
29
75
|
email: angeljrbt@gmail.com
|
@@ -31,6 +77,7 @@ executables: []
|
|
31
77
|
extensions: []
|
32
78
|
extra_rdoc_files: []
|
33
79
|
files:
|
80
|
+
- README.md
|
34
81
|
- lib/sfmc/assets/asset.rb
|
35
82
|
- lib/sfmc/authentication.rb
|
36
83
|
- lib/sfmc/contacts/contact_key.rb
|
@@ -41,7 +88,7 @@ files:
|
|
41
88
|
- lib/sfmc/transactional/send_definition.rb
|
42
89
|
- lib/sfmc/triggered/email.rb
|
43
90
|
- lib/sfmc_emailer.rb
|
44
|
-
homepage: https://
|
91
|
+
homepage: https://github.com/angeljruiz/SFMC-Email-Client
|
45
92
|
licenses:
|
46
93
|
- MIT
|
47
94
|
metadata: {}
|
@@ -60,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
107
|
- !ruby/object:Gem::Version
|
61
108
|
version: '0'
|
62
109
|
requirements: []
|
63
|
-
rubygems_version: 3.1.
|
110
|
+
rubygems_version: 3.1.4
|
64
111
|
signing_key:
|
65
112
|
specification_version: 4
|
66
113
|
summary: API wrapper for SFMC
|