def __make_oauth_request__(self,endpoint,data,method): try: access_token = self.authenticator.access_token except: raise TumblrError('This method requires obtaining and access token') #params = urllib.urlencode(data) data = remove_nones(data) log.debug('making %s request to %s with parameters %s' % (method,endpoint,data)) response_text = self.authenticator.make_oauth_request(endpoint, method, parameters=data) log.debug('raw response: %s' % (response_text)) response_text = to_unicode_or_bust(response_text, 'iso-8859-1') #if self.print_json: # print response_text self.__check_for_tumblr_error__(response_text) return response_text
if result['meta'].has_key('status'): if int(result['meta']['status']) >= 400: if result['meta'].has_key('msg'): error_text = result['meta']['msg'] raise TumblrError('An error was returned from Tumblr API: %s' % (error_text)) def __get_request_unauthenticated__(self,endpoint,data): data = remove_nones(data) params = urllib.urlencode(data) full_uri = "%s?%s" % (endpoint,params) try: response = urllib2.urlopen(full_uri) except urllib2.HTTPError, e: raise TumblrError(e.__str__()) response_text = response.read() response_text = to_unicode_or_bust(response_text, 'iso-8859-1') #if self.print_json or log.level < 20: # print response_text self.__check_for_tumblr_error__(response_text) return response_text def __make_authenticated_request__(self,endpoint,data,method): try: data['api_key'] = self.authenticator.oauth_consumer_key except: raise TumblrError('This method requires instantiating the TumblrAPI with an oauth_consumer_key and secret_key or a TumblrAuthenticator') data = remove_nones(data) if method.lower() == 'get': params = urllib.urlencode(data) full_uri = "%s?%s" % (endpoint,params)