Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from bde/master

SSL consideration
  • Loading branch information...
commit 924a8fea223ac914440b5e94cd4afd8ee0b3cab7 2 parents 97f1d05 + 6b495e7
@hmason hmason authored
Showing with 11 additions and 7 deletions.
  1. +8 −3 bitly_api/bitly_api.py
  2. +3 −4 bitly_api/bitly_http.py
View
11 bitly_api/bitly_api.py
@@ -38,7 +38,8 @@ class Connection(object):
"""
def __init__(self, login=None, api_key=None, access_token=None, secret=None):
- self.host = 'api.bitly.com'
+ self.host = 'api.bit.ly'
+ self.ssl_host = 'api-ssl.bit.ly'
self.login = login
self.api_key = api_key
self.access_token = access_token
@@ -185,7 +186,7 @@ def user_tracking_domain_shorten_counts(self, domain, **kwargs):
params = dict(domain=domain)
data = self._call_oauth2_metrics("v3/user/tracking_domain_shorten_counts", params, **kwargs)
return data["tracking_domain_shorten_counts"]
-
+
def user_link_history(self, created_before=None, created_after=None, archived=None, limit=None, offset=None):
params = dict()
if created_before is not None:
@@ -298,7 +299,7 @@ def _call_oauth2_metrics(self, endpoint, params, unit=None, units=None, tz_offse
def _call_oauth2(self, endpoint, params):
assert self.access_token, "This %s endpoint requires OAuth" % endpoint
- return self._call(self.host, endpoint, params)["data"]
+ return self._call(self.ssl_host, endpoint, params)["data"]
def _call(self, host, method, params, secret=None, timeout=5000):
params['format'] = params.get('format', 'json') # default to json
@@ -306,6 +307,7 @@ def _call(self, host, method, params, secret=None, timeout=5000):
if self.access_token:
scheme = 'https'
params['access_token'] = self.access_token
+ host = self.ssl_host
else:
scheme = 'http'
params['login'] = self.login
@@ -331,6 +333,9 @@ def _call(self, host, method, params, secret=None, timeout=5000):
'method': method,
'params': urllib.urlencode(params, doseq=1)
}
+
+ print request
+
try:
http_response = bitly_http.get(request, timeout, user_agent = self.user_agent)
if http_response['http_status_code'] != 200:
View
7 bitly_api/bitly_http.py
@@ -2,9 +2,8 @@
This class is an abstracted http handler that uses multiple underlying http libraries
it will default to
-a) google urlfetch
-b) pycurl
-c) urllib2
+a) pycurl
+b) urllib2
"""
try:
@@ -70,4 +69,4 @@ def get(url, timeout, user_agent):
code, result = makePycurlHttp(url, timeout, user_agent)
else:
code, result = makeUrllib2Http(url, user_agent)
- return {'http_status_code':code, 'result':result}
+ return {'http_status_code':code, 'result':result}
Please sign in to comment.
Something went wrong with that request. Please try again.