예제 #1
0
 def consumer(self):
     """Setups consumer"""
     consumer = getattr(self, '_consumer', None)
     if consumer is None:
         consumer = OAuthConsumer(*self.get_key_and_secret())
         setattr(self, '_consumer', consumer)
     return consumer
예제 #2
0
    def make_request(self,
                     url,
                     base_uri=None,
                     params=None,
                     auth=REQUIRED,
                     method="GET",
                     silo=False,
                     **kwargs):
        """
            Makes a request to Photobucket API.
            @url: The REST path to be requested after the [identifier]. By default this
                  value is appended to self.URI.
                  E.g. 
                    self.URI = /album/!
                    url = /share/all
                    The uri to request will be /album/!/share/all
            @base_uri: Allows for a quick override of self.URI per call.
            @params: A dictionary of parameters to send with the request.
            @auth: An Integer that determines whether this request needs to be authenticated.
            @method: The HTTP method to be used.
            @silo: Boolean. If True then this request will be sent to a specific silo/subdomain.

        """

        params = params or dict()
        body = kwargs.get('body', '')
        headers = {
            'User-Agent': 'python-photobucket/0.2 (Language=Python)',
            'Content-type': 'application/x-www-form-urlencoded'
        }
        headers.update(kwargs.get('extra_headers', {}))
        # Unless explicitly provided, set the default response format to json.
        params.setdefault('format', 'json')
        if 'id' in params:
            params['id'] = self.clean_identifier(params['id'])
        # Remove all params with a value of "None"
        params = remove_empty(params)

        # Begin auth stuff...
        token = None
        consumer = OAuthConsumer(key=self.key, secret=self.secret)
        if auth in (REQUIRED, OPTIONAL):
            # Setup the oauth token
            try:
                token = Token(key=self.token, secret=self.token_secret)
            except ValueError, e:
                if auth == REQUIRED:
                    # Only raise the exception if auth is required.
                    raise PhotobucketAPIError(
                        "Token and Token secret must be set.")
예제 #3
0
def build_consumer_oauth_request(backend, token, url, redirect_uri='/',
                                 oauth_verifier=None, extra_params=None):
    """Builds a Consumer OAuth request."""
    params = {'oauth_callback': redirect_uri}
    if extra_params:
        params.update(extra_params)

    if oauth_verifier:
        params['oauth_verifier'] = oauth_verifier

    consumer = OAuthConsumer(*backend.get_key_and_secret())
    request = OAuthRequest.from_consumer_and_token(consumer,
                                                   token=token,
                                                   http_url=url,
                                                   parameters=params)
    request.sign_request(SignatureMethod_HMAC_SHA1(), consumer, token)
    return request
예제 #4
0
 def consumer(self):
     """Setups consumer"""
     return OAuthConsumer(*self.get_key_and_secret())
예제 #5
0
 def get_consumer(self):
     return OAuthConsumer(self.FLICKR_KEY, self.FLICKR_SECRET)