Skip to content

Instantly share code, notes, and snippets.

View thinkingserious's full-sized avatar

Elmer Thomas thinkingserious

View GitHub Profile
@thinkingserious
thinkingserious / fluent.py
Created March 5, 2016 02:44
Fluent Interface in Python Using Method Chaining and Reflection
class Fluent:
def __init__(self, cache=None):
self._cache = cache or []
# Build the cache, and handle special cases
def _(self, name):
# Enables method chaining
return Fluent(self._cache+[name])
# Final method call
@thinkingserious
thinkingserious / sample-csharp-bcc-unique-args.cs
Created February 4, 2016 21:51
Testing BCC and unique args
using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Linq;
using SendGrid;
namespace Example
{
internal class Program
{
@thinkingserious
thinkingserious / sendgrid_html_text_body.py
Created January 28, 2016 17:03
Improve deliverability by including both a text and HTML email body
import sendgrid
from bs4 import BeautifulSoup
def send_email(self, to_email, from_email, subject, body):
message = sendgrid.Mail()
message.add_to(to_email)
message.set_subject(subject)
soup = BeautifulSoup(body, "html.parser")
message.set_text(soup.get_text())
message.set_html(body)
@thinkingserious
thinkingserious / example-template.rb
Created January 21, 2016 19:58
Sending an email using an template using the sendgrid-ruby library
require 'sendgrid-ruby'
require 'dotenv'
Dotenv.load
sendgrid_apikey = ENV['SENDGRID_APIKEY']
client = SendGrid::Client.new do |c|
c.api_key = sendgrid_apikey
end
@thinkingserious
thinkingserious / python_global_stats_get.py
Created November 18, 2015 04:00
Python Global Stats GET
import sendgrid
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
start_date = '2015-10-01'
@thinkingserious
thinkingserious / sendgrid_python_api_keys_patch_example.py
Created November 17, 2015 08:05
SendGrid Python v3 API Keys Example PATCH
import sendgrid
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
name = "My NEW API Key 3000"
@thinkingserious
thinkingserious / sendgrid_python_api_keys_delete_example.py
Created November 17, 2015 08:05
SendGrid Python v3 API Keys Example DELETE
import sendgrid
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
status, msg = client.apikeys.delete(api_key_id)
@thinkingserious
thinkingserious / sendgrid_python_api_keys_post_example.py
Last active November 17, 2015 08:04
SendGrid Python v3 API Keys Example POST
import sendgrid
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
name = "My Amazing API Key"
@thinkingserious
thinkingserious / sendgrid_python_asm_global_suppressions_example_delete.py
Created October 26, 2015 20:55
SendGrid Python v3 ASM Global Suppressions DELETE Example
import sendgrid
import json
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
@thinkingserious
thinkingserious / suppression_unsubscribes.py
Created October 26, 2015 16:40
Python Suppression Unsubscribes
import sendgrid
import json
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]