sendable 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c619e361de70e41f0e3889ca6440aa60efdf9e3
4
- data.tar.gz: 23fa7b2e0ef14ef817218b191c75c68bcd139c65
3
+ metadata.gz: 4255fa3aa05ec446e17dd9d07f62f669623f725e
4
+ data.tar.gz: 627f5eb96f4d9d69b1eb0747bc3d6e4bf352a50b
5
5
  SHA512:
6
- metadata.gz: cb6a7243a65bb3579f53248f899e80aa5b0c2d52662ddf2ee1c1670c3ab1a414be4a1dd097becb9cf6ea4854631917ccf4aa88a5ac1e99948a193300584f0c23
7
- data.tar.gz: bd877cf72955bac0f2e4bee269c506eb9ff972c3c4dce6be8cce5c9b808c03cc36e27cf42c30ecb294edff6ae48e8ea9a42d3d807df771190183606e3c6be1c2
6
+ metadata.gz: b9098d3980466981f78f6de08081d4af85507f1d39140831a672fef44305de687accc9f54c103fb41b45743f0e8657defdbfa35c28a6839ea3773490467bb692
7
+ data.tar.gz: 36428f907cfcdbabbb8e06e3a61c9c8a0c01a507f4726e2cfaeb5690deed069f0d22124beba50166247255c4ae10a78a08e4d38ac58d19459d83ae2013fa0a6e
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Sendable
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sendable`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Ruby library for sending email via the Sendable REST API.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
- ## Development
64
+ ### Email
28
65
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+ Sends the email using your configured SMTP mailer in Sendable.
30
67
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sendable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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
 
@@ -18,6 +18,6 @@ module Sendable
18
18
  end
19
19
 
20
20
  def self.client
21
- @client ||= Client.new(config.project_id, config.api_key)
21
+ @client ||= Client.new(config.api_key)
22
22
  end
23
23
  end
@@ -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(project_id, api_key)
11
- @project_id = project_id
9
+ def initialize(api_key)
12
10
  @api_key = api_key
13
11
  end
14
12
 
15
- def render(template_id, params = {})
16
- uri = URI("https://api.sendable.io/v1/project/#{project_id}/template/#{template_id}/render")
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, headers)
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(template_id, params = {})
34
- uri = URI("https://api.sendable.io/v1/project/#{project_id}/template/#{template_id}/email")
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, headers)
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Sendable
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.6
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-25 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler