Created
November 21, 2014 04:10
-
-
Save kpx-dev/f65d088e39d83eff5304 to your computer and use it in GitHub Desktop.
SendGrid filters commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This Python code snippet will show you how to get work with SendGrid filter | |
commands | |
install the amazing requests library | |
$ pip install requests==2.4.3 | |
export your SendGrid credential from command line | |
$ export SG_USERNAME=your_sg_username | |
$ export SG_PASSWORD=your_sg_password | |
save this file as python filter_commands.py and run it | |
$ python filter_commands.py | |
gist link: | |
""" | |
import requests | |
import os | |
SG_URL = "https://api.sendgrid.com/api" | |
def build_url(endpoint, params=None): | |
url = "{}/{}.json?api_user={}&api_key={}".format( | |
SG_URL, | |
endpoint, | |
os.environ['SG_USERNAME'], | |
os.environ['SG_PASSWORD']) | |
if params: | |
for k, v in params.iteritems(): | |
url += "&{}={}".format(k, v) | |
return url | |
if __name__ == '__main__': | |
# get all available filters (apps) | |
print "Getting all available filters..." | |
url = build_url('filter.getavailable') | |
res = requests.get(url) | |
# print res.json() | |
# activate gravatar app | |
print "Activate the gravatar app..." | |
url = build_url('filter.activate') | |
data = {"name": "gravatar"} | |
res = requests.post(url, data) | |
# print res.json() | |
# deactivate gravatar app | |
print "Deactivate the gravatar app..." | |
url = build_url('filter.deactivate') | |
data = {"name": "gravatar"} | |
res = requests.post(url, data) | |
# print res.json() | |
# setup app | |
print "Changing app setting..." | |
url = build_url('filter.setup') | |
data = {"name": "bcc", "email": "[email protected]"} | |
res = requests.post(url, data) | |
# print res.json() | |
# get app settings | |
print "Get app setting..." | |
params = {"name": "bcc"} | |
url = build_url('filter.getsettings', params) | |
res = requests.get(url) | |
# print res.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment