Skip to content

Instantly share code, notes, and snippets.

@brandonmwest
brandonmwest / create template
Last active August 29, 2015 14:01
SendGrid web api v3 curl example
curl -X POST -d '{"name":"example_name"}' -H "Content-Type: application/json" -u sendgrid_username https://api.sendgrid.com/v3/templates
@brandonmwest
brandonmwest / html2markdown.rb
Created July 2, 2014 17:25
convert jekyll html with custom liquid tags and codeblocks to well-structured markdown
require 'rubygems'
require 'json'
require 'nokogiri'
require 'nokogiri-pretty'
require 'iconv'
require 'pandoc-ruby'
require 'fileutils'
#convert HTML to markdown
html_files = File.join("/Users/brandonwest/SendGrid/docs/source", "**", "*.html")
@brandonmwest
brandonmwest / no_tables.rb
Last active August 29, 2015 14:03
Convert tables to {% parameters %} liquid blocks
require 'rubygems'
require 'json'
require 'nokogiri'
require 'nokogiri-pretty'
require 'iconv'
require 'fileutils'
html_files = File.join("/Users/brandonwest/SendGrid/docs/source/API_Reference", "**", "*.{md,html}")
Dir.glob html_files do |html_file|
@brandonmwest
brandonmwest / webhook.rb
Last active August 29, 2015 14:15
Log a JSON payload in Sinatra
post '/event' do
status 204 #successful request with no body content
request.body.rewind
request_payload = JSON.parse(request.body.read)
#append the payload to a file
File.open("events.txt", "a") do |f|
f.puts(request_payload)
end
{
"email"=>"john.doe@sendgrid.com",
"sg_event_id"=>"VzcPxPv7SdWvUugt-xKymw",
"sg_message_id"=>"142d9f3f351.7618.254f56.filter-147.22649.52A663508.0",
"timestamp"=>1386636112, "smtp-id"=>"<142d9f3f351.7618.254f56@sendgrid.com>",
"event"=>"processed",
"category"=>["category1", "category2", "category3"],
"id"=>"001",
"purchase"=>"PO1452297845",
"uid"=>"123456"
$ ack MANDRILL_APP
models/email.rb
186: user_name: ENV['MANDRILL_USERNAME'],
187: password: ENV['MANDRILL_APIKEY'],
/code {
"from": {
"name": "B West",
"email": "brandon@sendgrid.com"
},
"subject": "Mail v3 test",
"personalizations": [{
"to": [{
"name": "{{random_string(6)}} {random_string(12)}}",
"email": "{{random_string(6)}}@example.com"
{
"from": {
"name": "B West",
"email": "brandon@sendgrid.com"
},
"subject": "Mail v3 test",
"personalizations": [{
"to": [{
"name": "gYDXLV jeZLCy0VdiuU",
"email": "DuxWsA@sink.sendgrid.net"
{
"personalizations": [{
"to": [{
"email": "anna@example.com"
}],
"cc": [{
"email": "bill@example.com"
}, {
"email": "connie@example.com"
}, {
@brandonmwest
brandonmwest / node+ra.md
Last active June 21, 2017 15:36
RA + Node.js tutorial draft

Introduction

Today we're going to build a node.js application to collect email addresses using Kickbox. We'll be using Express and Request on the server side, and jQuery on the client.

We'll be using Glitch during this tutorial, because it provides an environment, editor, and hosting in one convenient package. There's an example of the completed project too. If you want to follow along in your own environment, all of the code will work.

What is Recipient Authentication?

Recipient Authentication makes it easy to collect email addresses the right way. We handle account activation, double email opt-in subscriptions, and password resets. We make sure the email gets delivered, send drip reminders, expire old links, handle opt-outs, and automatically add authenticated addresses to your email service provider or marketing platform.