sendable 0.1.6 → 0.2.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 +72 -8
- data/lib/sendable.rb +1 -1
- data/lib/sendable/client.rb +9 -21
- data/lib/sendable/config.rb +0 -7
- data/lib/sendable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4255fa3aa05ec446e17dd9d07f62f669623f725e
|
4
|
+
data.tar.gz: 627f5eb96f4d9d69b1eb0747bc3d6e4bf352a50b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9098d3980466981f78f6de08081d4af85507f1d39140831a672fef44305de687accc9f54c103fb41b45743f0e8657defdbfa35c28a6839ea3773490467bb692
|
7
|
+
data.tar.gz: 36428f907cfcdbabbb8e06e3a61c9c8a0c01a507f4726e2cfaeb5690deed069f0d22124beba50166247255c4ae10a78a08e4d38ac58d19459d83ae2013fa0a6e
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Sendable
|
2
2
|
|
3
|
-
|
3
|
+
Ruby library for sending email via the Sendable REST API.
|
4
4
|
|
5
|
-
|
5
|
+
[sendable.io](https://sendable.io)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -20,20 +20,84 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install sendable
|
22
22
|
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Sendable.config do |config|
|
27
|
+
config.api_key = 'YOUR API KEY'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
23
31
|
## Usage
|
24
32
|
|
25
|
-
|
33
|
+
### Render
|
34
|
+
|
35
|
+
Returns the rendered HTML for your template.
|
36
|
+
|
37
|
+
#### render arguments
|
38
|
+
- **template** - *string* - Your email template's id
|
39
|
+
- **params** - *hash* - Object containing the following keys
|
40
|
+
- **data** - *hash* - Any email template data that will be replaced in the `mustache` email template
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
result = Sendable.client.render(1, {
|
44
|
+
data: {
|
45
|
+
first_name: 'John',
|
46
|
+
age: 28
|
47
|
+
}
|
48
|
+
})
|
49
|
+
```
|
50
|
+
|
51
|
+
#### render response
|
52
|
+
```ruby
|
53
|
+
{
|
54
|
+
success: true,
|
55
|
+
email: {
|
56
|
+
html: "<html><head></head><body><h1>Sample HTML</h1></body></html>",
|
57
|
+
plain: "Sample Plain Text",
|
58
|
+
subject: "Sample Subject",
|
59
|
+
preheader: "Sample Preheader"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
26
63
|
|
27
|
-
|
64
|
+
### Email
|
28
65
|
|
29
|
-
|
66
|
+
Sends the email using your configured SMTP mailer in Sendable.
|
30
67
|
|
31
|
-
|
68
|
+
#### email arguments
|
69
|
+
- **template** - *string* - Your email template's id
|
70
|
+
- **params** - *hash* - Object containing the following keys
|
71
|
+
- **to** - *string* - This is the recipient's email address
|
72
|
+
- **from** - *string* - This is the sender's email address
|
73
|
+
- **data** - *hash* - Any email data attributes that will be replaced in the `mustache` email template
|
32
74
|
|
33
|
-
|
75
|
+
```ruby
|
76
|
+
result = Sendable.client.email(1, {
|
77
|
+
to: 'john@doe.com',
|
78
|
+
from: 'me@awesomesite.com',
|
79
|
+
data: {
|
80
|
+
first_name: 'John',
|
81
|
+
age: 28
|
82
|
+
}
|
83
|
+
})
|
84
|
+
```
|
34
85
|
|
35
|
-
|
86
|
+
#### email response
|
87
|
+
```ruby
|
88
|
+
{
|
89
|
+
success: true,
|
90
|
+
email: {
|
91
|
+
html: "<html><head></head><body><h1>Sample HTML</h1></body></html>",
|
92
|
+
plain: "Sample Plain Text",
|
93
|
+
subject: "Sample Subject",
|
94
|
+
preheader: "Sample Preheader"
|
95
|
+
},
|
96
|
+
delivery: {}
|
97
|
+
}
|
98
|
+
```
|
36
99
|
|
100
|
+
The `delivery` key will include the response from your ESP.
|
37
101
|
|
38
102
|
## License
|
39
103
|
|
data/lib/sendable.rb
CHANGED
data/lib/sendable/client.rb
CHANGED
@@ -4,44 +4,32 @@ require 'json'
|
|
4
4
|
|
5
5
|
module Sendable
|
6
6
|
class Client
|
7
|
-
attr_reader :project_id
|
8
7
|
attr_reader :api_key
|
9
8
|
|
10
|
-
def initialize(
|
11
|
-
@project_id = project_id
|
9
|
+
def initialize(api_key)
|
12
10
|
@api_key = api_key
|
13
11
|
end
|
14
12
|
|
15
|
-
def render(
|
16
|
-
uri = URI(
|
17
|
-
|
18
|
-
headers = {
|
19
|
-
'Authorization': "ApiKey #{api_key}",
|
20
|
-
'Content-Type' => 'application/json',
|
21
|
-
}
|
22
|
-
|
13
|
+
def render(params = {})
|
14
|
+
uri = URI('https://api.sendable.io/v1/render')
|
23
15
|
http = Net::HTTP.new(uri.host, uri.port)
|
24
16
|
http.use_ssl = true
|
25
17
|
|
26
|
-
request = Net::HTTP::Post.new(uri.request_uri
|
18
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
19
|
+
request.basic_auth(api_key, '')
|
27
20
|
request.body = params.respond_to?(:to_json) ? params.to_json : JSON.dump(params)
|
28
21
|
response = http.request(request)
|
29
22
|
|
30
23
|
JSON.parse(response.body)
|
31
24
|
end
|
32
25
|
|
33
|
-
def email(
|
34
|
-
uri = URI(
|
35
|
-
|
36
|
-
headers = {
|
37
|
-
'Authorization': "ApiKey #{api_key}",
|
38
|
-
'Content-Type' => 'application/json',
|
39
|
-
}
|
40
|
-
|
26
|
+
def email(params = {})
|
27
|
+
uri = URI('https://api.sendable.io/v1/email')
|
41
28
|
http = Net::HTTP.new(uri.host, uri.port)
|
42
29
|
http.use_ssl = true
|
43
30
|
|
44
|
-
request = Net::HTTP::Post.new(uri.request_uri
|
31
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
32
|
+
request.basic_auth(api_key, '')
|
45
33
|
request.body = params.respond_to?(:to_json) ? params.to_json : JSON.dump(params)
|
46
34
|
response = http.request(request)
|
47
35
|
|
data/lib/sendable/config.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Sendable
|
2
2
|
class Config
|
3
|
-
attr_accessor :project_id
|
4
3
|
attr_accessor :api_key
|
5
4
|
|
6
5
|
def initialize
|
@@ -8,12 +7,6 @@ module Sendable
|
|
8
7
|
end
|
9
8
|
|
10
9
|
def set_defaults
|
11
|
-
if ENV.has_key?("SENDABLE_PROJECT_ID")
|
12
|
-
@project_id = ENV["SENDABLE_PROJECT_ID"]
|
13
|
-
else
|
14
|
-
@project_id = nil
|
15
|
-
end
|
16
|
-
|
17
10
|
if ENV.has_key?("SENDABLE_API_KEY")
|
18
11
|
@api_key = ENV["SENDABLE_API_KEY"]
|
19
12
|
else
|
data/lib/sendable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Umair Siddique
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|