Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c083f0d
Added contacts.py file
YitaoX Sep 8, 2015
90d3c49
updated the version number
YitaoX Sep 8, 2015
dffaffd
Added Contacts client and Contact Lists client
YitaoX Sep 8, 2015
f291ba1
Fixed a bug
YitaoX Sep 9, 2015
2857990
Added two new needed methods
YitaoX Sep 9, 2015
40bcac6
Tests for contacts & contact lists, added some methods to the API tha…
Sep 9, 2015
84b213c
Merge pull request #1 from CBitLabs/tests_contacts_contact_lists
tinyx Sep 10, 2015
0d281b4
change nosetest requirement
Sep 11, 2015
346f71d
change "get_a_contact_lists" to "get_contact_lists"
YitaoX Sep 11, 2015
3d7791c
Removed nose and unittest from package deps
Oct 14, 2016
e4c77b9
Merge pull request #2 from CBitLabs/remove_deps
pjsg Oct 14, 2016
dd87909
Update version to 2.10.5.1
Oct 19, 2016
67d1925
FIx vairaous issues with unicode email addresses
pjsg Nov 1, 2017
a7d07f0
Merge pull request #3 from CBitLabs/fix/unicode
tinyx Nov 2, 2017
e7a6d31
Really fix the unicode problem
pjsg Nov 15, 2017
5a6244d
Merge remote-tracking branch 'origin/master' into fix/unicode
pjsg Nov 15, 2017
8f2859e
Merge pull request #4 from CBitLabs/fix/unicode
tinyx Nov 15, 2017
570d52b
Added a get_contacts_by_list_id method in the client
YitaoX Mar 16, 2018
e9ec9e8
Bump the version
YitaoX Mar 16, 2018
b6e253d
Merge pull request #5 from CBitLabs/feature/get_contacts_by_list
pjsg Mar 16, 2018
0df6cb5
Delete currently unused legacy clients, make the active clients to be…
ruichen-wang Dec 4, 2019
3c51f18
Bump the version
ruichen-wang Dec 4, 2019
f2b9ef0
Reformat codes, add dependencies for python2/3 compatibility in setup.py
ruichen-wang Dec 4, 2019
120093d
Reformat logic of convert arbitrary contents to unicode, make tests f…
ruichen-wang Dec 5, 2019
d5d0a2a
Modify some comments, bump internal version
ruichen-wang Dec 6, 2019
b6d9d25
Override nonzero function, use six.BytesIO for python 2/3 compatibility
ruichen-wang Dec 9, 2019
6957d41
Distinguish between str and unicode, unzip gzipped body in one place,…
ruichen-wang Dec 10, 2019
e3fe350
Get rid of __unicode__ function for python2/3 compatibility
ruichen-wang Dec 10, 2019
da07db6
Replace StringIO with six.BytesIO for python2/3 compatibility
ruichen-wang Dec 11, 2019
d13bdba
Merge pull request #6 from CBitLabs/cmw/RP-60972-make-hapipy-to-be-py…
ruichen-wang Dec 11, 2019
d4b1a58
Change version name to comply with pep 0440
leonidbelyi-bitsight Dec 17, 2019
8302062
Update hubspot api to use access token in header
ritasoldi Feb 14, 2023
2129600
Merge pull request #7 from soldi/access-token-header
cliebBS Feb 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
dist
/build
MANIFEST
.idea
.DS_Store
35 changes: 19 additions & 16 deletions hapi/base.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import urllib
import httplib
from __future__ import print_function
from builtins import object
from past.builtins import basestring
from future.moves.urllib.parse import urlencode
import http.client
import simplejson as json
import utils
from . import utils
import logging
import sys
import time
import traceback
import gzip
import StringIO
import six

from error import HapiError, HapiBadRequest, HapiNotFound, HapiTimeout, HapiServerError, HapiUnauthorized
from .error import HapiError, HapiBadRequest, HapiNotFound, HapiTimeout, HapiServerError, HapiUnauthorized


_PYTHON25 = sys.version_info < (2, 6)
Expand Down Expand Up @@ -45,7 +48,7 @@ def __init__(self, api_key=None, timeout=10, mixins=[], access_token=None, refre
self._prepare_connection_type()

def _prepare_connection_type(self):
connection_types = {'http': httplib.HTTPConnection, 'https': httplib.HTTPSConnection}
connection_types = {'http': http.client.HTTPConnection, 'https': http.client.HTTPSConnection}
parts = self.options['api_base'].split('://')
protocol = (parts[0:-1]+['https'])[0]
self.options['connection_type'] = connection_types[protocol]
Expand All @@ -56,6 +59,7 @@ def _get_path(self, subpath):
raise Exception("Unimplemented get_path for BaseClient subclass!")

def _prepare_request_auth(self, subpath, params, data, opts):
headers = opts.get('headers', {}) if opts else {}
if self.api_key:
params['hapikey'] = params.get('hapikey') or self.api_key
else:
Expand All @@ -64,11 +68,12 @@ def _prepare_request_auth(self, subpath, params, data, opts):
# but one was provided as part of the method invocation, we persist it
if params.get('access_token') and not self.access_token:
self.access_token = params.get('access_token')
params['access_token'] = self.access_token
headers.update({"Authorization": "Bearer %s" % self.access_token})
return headers

def _prepare_request(self, subpath, params, data, opts, doseq=False, query=''):
params = params or {}
self._prepare_request_auth(subpath, params, data, opts)
headers = self._prepare_request_auth(subpath, params, data, opts)

if opts.get('hub_id') or opts.get('portal_id'):
params['portalId'] = opts.get('hub_id') or opts.get('portal_id')
Expand All @@ -78,8 +83,7 @@ def _prepare_request(self, subpath, params, data, opts, doseq=False, query=''):
query = query[1:]
if query and not query.startswith('&'):
query = '&' + query
url = opts.get('url') or '/%s?%s%s' % (self._get_path(subpath), urllib.urlencode(params, doseq), query)
headers = opts.get('headers') or {}
url = opts.get('url') or '/%s?%s%s' % (self._get_path(subpath), urlencode(params, doseq), query)
headers.update({
'Accept-Encoding': 'gzip',
'Content-Type': opts.get('content_type') or 'application/json'})
Expand All @@ -97,7 +101,7 @@ def _create_request(self, conn, method, url, headers, data):
return params

def _gunzip_body(self, body):
sio = StringIO.StringIO(body)
sio = six.BytesIO(body)
gf = gzip.GzipFile(fileobj=sio, mode="rb")
return gf.read()

Expand All @@ -112,7 +116,7 @@ def _execute_request_raw(self, conn, request):
except:
raise HapiTimeout(None, request, traceback.format_exc())

encoding = [i[1] for i in result.getheaders() if i[0] == 'content-encoding']
encoding = [i[1] for i in result.getheaders() if i[0].lower() == 'content-encoding']
result.body = self._process_body(result.read(), len(encoding) and encoding[0] == 'gzip')

conn.close()
Expand All @@ -137,7 +141,6 @@ def _digest_result(self, data):
data = json.loads(data)
except ValueError:
pass

return data

def _call_raw(self, subpath, params=None, method='GET', data=None, doseq=False, query='', retried=False, **options):
Expand Down Expand Up @@ -167,7 +170,7 @@ def _call_raw(self, subpath, params=None, method='GET', data=None, doseq=False,
request_info = self._create_request(connection, method, url, headers, data)
result = self._execute_request_raw(connection, request_info)
break
except HapiUnauthorized, e:
except HapiUnauthorized as e:
self.log.warning("401 Unauthorized response to API request.")
if self.access_token and self.refresh_token and self.client_id and not retried:
self.log.info("Refreshing access token")
Expand All @@ -176,7 +179,7 @@ def _call_raw(self, subpath, params=None, method='GET', data=None, doseq=False,
decoded = json.loads(token_response)
self.access_token = decoded['access_token']
self.log.info('Retrying with new token %' % (self.access_token))
except Exception, e:
except Exception as e:
self.log.error("Unable to refresh access_token: %s" % (e))
raise
return self._call_raw(subpath, params=params, method=method, data=data, doseq=doseq, query=query, retried=True, **options)
Expand All @@ -188,7 +191,7 @@ def _call_raw(self, subpath, params=None, method='GET', data=None, doseq=False,
elif self.access_token and not self.client_id:
self.log.error("In order to enable automated refreshing of your access token, please provide a client_id in addition to a refresh token.")
raise
except HapiError, e:
except HapiError as e:
if try_count > num_retries:
logging.warning("Too many retries for %s", url)
raise
Expand Down
81 changes: 0 additions & 81 deletions hapi/blog.py

This file was deleted.

186 changes: 0 additions & 186 deletions hapi/broadcast.py

This file was deleted.

Loading