Skip to content

Commit 29d4ec1

Browse files
authored
Merge pull request #308 from twilio/next-gen-http
Replace Httplib2 with Requests
2 parents 2809d73 + 104228f commit 29d4ec1

File tree

8 files changed

+54
-90
lines changed

8 files changed

+54
-90
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ cover
3333

3434
#htmlcov
3535
*htmlcov*
36+
37+
# PyEnv
38+
.python-version

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: python
22
python:
3+
- "2.6"
34
- "2.7"
4-
- "3.2"
55
- "3.3"
66
- "3.4"
77
- "3.5"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
six
2-
httplib2
2+
requests>=2.0.0
33
socksipy-branch
44
PyJWT==1.4.2

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
#
1414
# You need to have the setuptools module installed. Try reading the setuptools
1515
# documentation: http://pypi.python.org/pypi/setuptools
16-
REQUIRES = ["httplib2 >= 0.7", "six", "pytz", "PyJWT == 1.4.2"]
16+
REQUIRES = ["requests >= 2.0.0", "six", "pytz", "PyJWT >= 1.4.2"]
1717

1818
if sys.version_info < (2, 6):
1919
REQUIRES.append('simplejson')
20-
if sys.version_info >= (3,0):
20+
if sys.version_info < (3, 0):
21+
REQUIRES.extend(["cryptography >= 1.3.4", "idna >= 2.0.0", "pyOpenSSL >= 0.14"])
22+
if sys.version_info >= (3, 0):
2123
REQUIRES.append('pysocks')
2224

2325
setup(
@@ -31,7 +33,6 @@
3133
install_requires = REQUIRES,
3234
# bdist conditional requirements support
3335
extras_require={
34-
':python_version=="3.2"': ['pysocks'],
3536
':python_version=="3.3"': ['pysocks'],
3637
':python_version=="3.4"': ['pysocks'],
3738
':python_version=="3.5"': ['pysocks'],
@@ -45,8 +46,8 @@
4546
"License :: OSI Approved :: MIT License",
4647
"Operating System :: OS Independent",
4748
"Programming Language :: Python",
49+
"Programming Language :: Python :: 2.6",
4850
"Programming Language :: Python :: 2.7",
49-
"Programming Language :: Python :: 3.2",
5051
"Programming Language :: Python :: 3.3",
5152
"Programming Language :: Python :: 3.4",
5253
"Programming Language :: Python :: 3.5",

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26, py27, py32, py33, py34, py35, py36, pypy
2+
envlist = py26, py27, py33, py34, py35, py36, pypy
33

44
[testenv]
55
deps= -r{toxinidir}/tests/requirements.txt

twilio/http/http_client.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from requests import Request, Session
2+
3+
from twilio.http import HttpClient, get_cert_file
4+
from twilio.http.response import Response
5+
6+
7+
class TwilioHttpClient(HttpClient):
8+
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
9+
allow_redirects=False):
10+
"""
11+
General purpose HTTP client to make an HTTP request
12+
13+
:param str method: The HTTP method to use
14+
:param str url: The URL to request
15+
:param dict params: Query parameters to append to the URL
16+
:param dict data: Parameters to go in the body of the HTTP request
17+
:param dict headers: HTTP Headers to send with the request
18+
:param tuple auth: Basic Auth arguments
19+
:param float timeout: Socket/Read timeout for the request
20+
:param boolean allow_redirects: Whether or not to allow redirects
21+
22+
:return: An http response
23+
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
24+
25+
See the requests documentation for explanation of all these parameters
26+
"""
27+
session = Session()
28+
session.verify = get_cert_file()
29+
30+
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)
31+
32+
prepped_request = session.prepare_request(request)
33+
response = session.send(
34+
prepped_request,
35+
allow_redirects=allow_redirects,
36+
timeout=timeout,
37+
)
38+
39+
return Response(int(response.status_code), response.content.decode('utf-8'))

twilio/http/httplib2_client.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

twilio/rest/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
import os
1010
import platform
11+
12+
from twilio.http.http_client import TwilioHttpClient
13+
1114
from twilio import __version__
1215
from twilio.exceptions import TwilioException
13-
from twilio.http.httplib2_client import Httplib2Client
1416
from twilio.rest.api import Api
1517
from twilio.rest.chat import Chat
1618
from twilio.rest.ip_messaging import IpMessaging
@@ -54,7 +56,7 @@ def __init__(self, username=None, password=None, account_sid=None,
5456

5557
self.auth = (self.username, self.password)
5658
""" :type : tuple(str, str) """
57-
self.http_client = http_client or Httplib2Client()
59+
self.http_client = http_client or TwilioHttpClient()
5860
""" :type : HttpClient """
5961

6062
# Domains

0 commit comments

Comments
 (0)