sfmc_emailer 0.0.2 → 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.
- checksums.yaml +4 -4
- data/README.md +60 -0
- data/lib/sfmc/errors.rb +0 -2
- data/lib/sfmc/sfmc_base.rb +1 -1
- data/lib/sfmc/transactional/email.rb +4 -4
- data/lib/sfmc/transactional/send_definition.rb +6 -6
- metadata +28 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1adf9b8e0dad89341a1112c11f39d4d3a941ac4939aa9765a903b3110ee733fc
|
4
|
+
data.tar.gz: 7d16ea5996dfd53e530a96c6017a9bb26151adb44c8ca7a6f9eb81c6ecb2f1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f707821530e877188f0aa5a1ec4fc67a855aff8340387d40ddf08f005cf2cd9f595a5ee2ec34095819a8c09763585adefbe574618a91487ae33b51c72ad344a
|
7
|
+
data.tar.gz: 72a0150f271142c8be252b58da1a35e62564ff675b8e618d932e690db211de1965fbb2224f098bfca21c440c4a7fb8261165df22e2f27b05a348cbf61500b6df
|
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 take 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(
|
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
|
data/lib/sfmc/sfmc_base.rb
CHANGED
@@ -29,7 +29,7 @@ module SFMC
|
|
29
29
|
end
|
30
30
|
|
31
31
|
received = method(http_method).call(endpoint, body: params, headers: SFMCBase.headers)
|
32
|
-
payload =
|
32
|
+
payload = JSON.parse(received.to_json, object_class: OpenStruct)
|
33
33
|
|
34
34
|
return payload if received.response.is_a? Net::HTTPSuccess
|
35
35
|
|
@@ -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: 0.0
|
4
|
+
version: 1.0.0
|
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,29 @@ 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
|
27
53
|
description: API wrapper for Salesforce Marketing Cloud's Transactional and Triggered
|
28
54
|
Send APIs
|
29
55
|
email: angeljrbt@gmail.com
|
@@ -31,6 +57,7 @@ executables: []
|
|
31
57
|
extensions: []
|
32
58
|
extra_rdoc_files: []
|
33
59
|
files:
|
60
|
+
- README.md
|
34
61
|
- lib/sfmc/assets/asset.rb
|
35
62
|
- lib/sfmc/authentication.rb
|
36
63
|
- lib/sfmc/contacts/contact_key.rb
|