Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from bde/master
Browse files Browse the repository at this point in the history
SSL consideration
  • Loading branch information
hmason committed Dec 21, 2012
2 parents 97f1d05 + 6b495e7 commit 924a8fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 8 additions & 3 deletions bitly_api/bitly_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -298,14 +299,15 @@ 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

if self.access_token:
scheme = 'https'
params['access_token'] = self.access_token
host = self.ssl_host
else:
scheme = 'http'
params['login'] = self.login
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions bitly_api/bitly_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}

0 comments on commit 924a8fe

Please sign in to comment.