Skip to content

Commit f2f1834

Browse files
author
Matt Bernier
authored
Merge branch 'master' into master
2 parents f7d52f8 + 01bba17 commit f2f1834

File tree

13 files changed

+169
-32
lines changed

13 files changed

+169
-32
lines changed

.env_sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export SENDGRID_API_KEY=''

.github/PULL_REQUEST_TEMPLATE

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
**Description of the change**:
1+
<!--
2+
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below.
23

3-
**Reason for the change**:
44

5+
Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
6+
e.g.
7+
Fixes #1
8+
Closes #2
9+
-->
10+
# Fixes #
511

12+
### Checklist
13+
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
14+
- [ ] I have read the [Contribution Guide] and my PR follows them.
15+
- [ ] I updated my branch with the master branch.
16+
- [ ] I have added tests that prove my fix is effective or that my feature works
17+
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
18+
- [ ] I have added in line documentation to the code I modified
19+
20+
### Short description of what this PR does:
21+
-
22+
-
23+
24+
If you have questions, please send an email to [Sendgrid](mailto:[email protected]), or file a Github Issue in this repository.

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ python:
66
- '2.7'
77
- '3.4'
88
- '3.5'
9+
fail_fast: true
10+
before_install:
11+
- pip install pycodestyle
912
install:
1013
- if [[ "$TRAVIS_PYTHON_VERSION" == 2.6* ]]; then travis_retry pip install unittest2; fi
1114
- if [[ "$TRAVIS_PYTHON_VERSION" == 2.6* ]]; then travis_retry pip uninstall -y pbr; fi
1215
- if [[ "$TRAVIS_PYTHON_VERSION" == "3.2" ]]; then travis_retry pip install coverage==3.7.1; fi
1316
- if [[ "$TRAVIS_PYTHON_VERSION" != "3.2" ]]; then travis_retry pip install coverage; fi
1417
- python setup.py install
1518
script:
19+
# Run pycodestyle
20+
- pycodestyle
1621
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then unit2 discover; else python -m unittest discover; fi
1722
notifications:
1823
hipchat:

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 SendGrid, Inc.
3+
Copyright (c) 2012 - 2017 SendGrid, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ or
4545
easy_install python_http_client
4646
```
4747

48+
## API Key
49+
50+
Store your SendGrid API key in a .env file
51+
52+
```bash
53+
cp .env_sample .env
54+
```
55+
56+
Edit the `.env` file and add your API key.
57+
4858
<a name="quick-start"></a>
4959
# Quick Start
5060

examples/live_sendgrid_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@
6666
response = client.api_keys._(api_key_id).delete()
6767
print(response.status_code)
6868
print(response.headers)
69-

python_http_client/client.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ def _build_url(self, query_params):
119119
if query_params:
120120
url_values = urlencode(sorted(query_params.items()), True)
121121
url = '{0}?{1}'.format(url, url_values)
122-
url = self._build_versioned_url(
123-
url) if self._version else self.host + url
122+
123+
if self._version:
124+
url = self._build_versioned_url(url)
125+
else:
126+
url = self.host + url
127+
124128
return url
125129

126130
def _update_headers(self, request_headers):
@@ -210,27 +214,41 @@ def http_request(*_, **kwargs):
210214
if 'request_body' not in kwargs:
211215
data = None
212216
else:
213-
# Don't serialize to a JSON formatted str if we don't have a JSON Content-Type
217+
218+
# Don't serialize to a JSON formatted str
219+
# if we don't have a JSON Content-Type
214220
if 'Content-Type' in self.request_headers:
215-
if self.request_headers['Content-Type'] != 'application/json':
221+
if self.request_headers['Content-Type'] != 'application\
222+
/json':
216223
data = kwargs['request_body'].encode('utf-8')
217224
else:
218225
data = json.dumps(
219226
kwargs['request_body']).encode('utf-8')
220227
else:
221228
data = json.dumps(
222229
kwargs['request_body']).encode('utf-8')
223-
params = kwargs['query_params'] if 'query_params' in kwargs else None
230+
231+
if 'query_params' in kwargs:
232+
params = kwargs['query_params']
233+
else:
234+
params = None
235+
224236
opener = urllib.build_opener()
225237
request = urllib.Request(self._build_url(params), data=data)
226238
if self.request_headers:
227239
for key, value in self.request_headers.items():
228240
request.add_header(key, value)
229-
if data and not ('Content-Type' in self.request_headers):
241+
if data and ('Content-Type' not in self.request_headers):
230242
request.add_header('Content-Type', 'application/json')
231243
request.get_method = lambda: method
232244
return Response(self._make_request(opener, request))
233245
return http_request
234246
else:
235247
# Add a segment to the URL
236248
return self._(name)
249+
250+
def __getstate__(self):
251+
return self.__dict__
252+
253+
def __setstate__(self, state):
254+
self.__dict__ = state

register.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import pypandoc
22
import os
33

4+
45
output = pypandoc.convert('README.md', 'rst')
5-
f = open('README.txt','w+')
6-
f.write(output)
7-
f.close()
8-
9-
readme_rst = open('./README.txt').read()
10-
replace = '[SendGrid Logo]\n(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)'
11-
replacement = '|SendGrid Logo|\n\n.. |SendGrid Logo| image:: https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png\n :target: https://www.sendgrid.com'
12-
final_text = readme_rst.replace(replace,replacement)
6+
7+
with open('README.txt', 'w+') as f:
8+
f.write(output)
9+
10+
with open('./README.txt') as f:
11+
readme_rst = f.read()
12+
13+
replace = ('[SendGrid Logo]\n'
14+
'(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)')
15+
16+
replacement = ('|SendGrid Logo|\n\n.. |SendGrid Logo| image:: '
17+
'https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png'
18+
'\n :target: https://www.sendgrid.com')
19+
20+
final_text = readme_rst.replace(replace, replacement)
21+
1322
with open('./README.txt', 'w') as f:
14-
f.write(final_text)
23+
f.write(final_text)

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
import os
33
from setuptools import setup
44

5+
56
long_description = 'Please see our GitHub README'
67
if os.path.exists('README.txt'):
78
long_description = open('README.txt').read()
89

10+
911
def getRequires():
1012
deps = []
1113
if (2, 6) <= sys.version_info < (2, 7):
1214
deps.append('unittest2')
1315
return deps
1416

17+
1518
base_url = 'https://github.com/sendgrid/'
1619
version = '3.0.0'
1720
setup(

tests/profile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,6 @@ def static_version():
160160
version=3)
161161
run_tested_code(client, 10)
162162

163+
163164
dynamic_result = dynamic_version()
164165
static_result = static_version()

0 commit comments

Comments
 (0)