unsent 1.0.0 → 1.0.1
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 +15 -0
- data/lib/unsent/client.rb +16 -11
- data/lib/unsent/emails.rb +12 -6
- data/lib/unsent/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3654dd5977b62530b4cde2e028eb70aa08a29dbc09c0ff41d59127a831c61db0
|
|
4
|
+
data.tar.gz: d90d594fdb4db827a8cffc65f8373f53d1ccb4bf6e11e580da858a6689271775
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f32d82928ae27864e81968b6d95e508e1c5ffc0eb8601a9456ea73f7be70fee4292e7fc134b0c5a8c2db774ea4babddcf90e67a91773c8ec2a43ba8a71e7d212
|
|
7
|
+
data.tar.gz: 97a1c68b5e3845cc052c863e6cbdcc1b5203adb187c801106c37c3ea70bfb6e81d970a25eaa5122726732b6150e721805da1c1f2f1d8396decebd291e1fcb454
|
data/README.md
CHANGED
|
@@ -109,6 +109,21 @@ data, error = client.emails.batch(emails)
|
|
|
109
109
|
puts "Sent #{data['emails'].length} emails" if data
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
#### Idempotent Retries
|
|
113
|
+
|
|
114
|
+
To prevent duplicate emails when retrying failed requests, you can provide an idempotency key.
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
data, error = client.emails.send({
|
|
118
|
+
to: 'user@example.com',
|
|
119
|
+
from: 'no-reply@yourdomain.com',
|
|
120
|
+
subject: 'Welcome',
|
|
121
|
+
html: '<strong>Hello!</strong>'
|
|
122
|
+
}, {
|
|
123
|
+
idempotency_key: 'unique-key-123'
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
112
127
|
### Managing Emails
|
|
113
128
|
|
|
114
129
|
#### Get Email
|
data/lib/unsent/client.rb
CHANGED
|
@@ -26,7 +26,7 @@ module Unsent
|
|
|
26
26
|
@domains = Domains.new(self)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def request(method, path, body = nil)
|
|
29
|
+
def request(method, path, body = nil, headers = {})
|
|
30
30
|
uri = URI("#{@url}#{path}")
|
|
31
31
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
32
32
|
http.use_ssl = uri.scheme == "https"
|
|
@@ -42,6 +42,11 @@ module Unsent
|
|
|
42
42
|
|
|
43
43
|
request["Authorization"] = "Bearer #{@key}"
|
|
44
44
|
request["Content-Type"] = "application/json"
|
|
45
|
+
|
|
46
|
+
headers.each do |key, value|
|
|
47
|
+
request[key] = value
|
|
48
|
+
end
|
|
49
|
+
|
|
45
50
|
request.body = body.to_json if body
|
|
46
51
|
|
|
47
52
|
response = http.request(request)
|
|
@@ -67,24 +72,24 @@ module Unsent
|
|
|
67
72
|
end
|
|
68
73
|
end
|
|
69
74
|
|
|
70
|
-
def post(path, body)
|
|
71
|
-
request("POST", path, body)
|
|
75
|
+
def post(path, body, headers = {})
|
|
76
|
+
request("POST", path, body, headers)
|
|
72
77
|
end
|
|
73
78
|
|
|
74
|
-
def get(path)
|
|
75
|
-
request("GET", path)
|
|
79
|
+
def get(path, headers = {})
|
|
80
|
+
request("GET", path, nil, headers)
|
|
76
81
|
end
|
|
77
82
|
|
|
78
|
-
def put(path, body)
|
|
79
|
-
request("PUT", path, body)
|
|
83
|
+
def put(path, body, headers = {})
|
|
84
|
+
request("PUT", path, body, headers)
|
|
80
85
|
end
|
|
81
86
|
|
|
82
|
-
def patch(path, body)
|
|
83
|
-
request("PATCH", path, body)
|
|
87
|
+
def patch(path, body, headers = {})
|
|
88
|
+
request("PATCH", path, body, headers)
|
|
84
89
|
end
|
|
85
90
|
|
|
86
|
-
def delete(path, body = nil)
|
|
87
|
-
request("DELETE", path, body)
|
|
91
|
+
def delete(path, body = nil, headers = {})
|
|
92
|
+
request("DELETE", path, body, headers)
|
|
88
93
|
end
|
|
89
94
|
end
|
|
90
95
|
end
|
data/lib/unsent/emails.rb
CHANGED
|
@@ -6,11 +6,11 @@ module Unsent
|
|
|
6
6
|
@client = client
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def send(payload)
|
|
10
|
-
create(payload)
|
|
9
|
+
def send(payload, options = {})
|
|
10
|
+
create(payload, options)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def create(payload)
|
|
13
|
+
def create(payload, options = {})
|
|
14
14
|
# Normalize from_ to from
|
|
15
15
|
payload = payload.dup
|
|
16
16
|
payload[:from] = payload.delete(:from_) if payload.key?(:from_) && !payload.key?(:from)
|
|
@@ -20,10 +20,13 @@ module Unsent
|
|
|
20
20
|
payload[:scheduledAt] = payload[:scheduledAt].iso8601
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
headers = {}
|
|
24
|
+
headers["Idempotency-Key"] = options[:idempotency_key] if options[:idempotency_key]
|
|
25
|
+
|
|
26
|
+
@client.post("/emails", payload, headers)
|
|
24
27
|
end
|
|
25
28
|
|
|
26
|
-
def batch(emails)
|
|
29
|
+
def batch(emails, options = {})
|
|
27
30
|
items = emails.map do |email|
|
|
28
31
|
email = email.dup
|
|
29
32
|
email[:from] = email.delete(:from_) if email.key?(:from_) && !email.key?(:from)
|
|
@@ -31,7 +34,10 @@ module Unsent
|
|
|
31
34
|
email
|
|
32
35
|
end
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
headers = {}
|
|
38
|
+
headers["Idempotency-Key"] = options[:idempotency_key] if options[:idempotency_key]
|
|
39
|
+
|
|
40
|
+
@client.post("/emails/batch", items, headers)
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def get(email_id)
|
data/lib/unsent/version.rb
CHANGED