Example #1
0
    def post(self, text, token='', secret=''):
        """Do a Twitter profile update."""

        url = self._config['update_url'] % {
            'format': 'json',
        }

        data = {
            'status': text.encode('utf-8'),
        }
        data = urllib.urlencode(data)

        token = oauth.OAuthToken(token, secret)
        request = oauth.OAuthRequest.from_consumer_and_token(
            self._consumer,
            token=token,
            http_url=url,
            http_method='POST',
        )
        request.set_parameter('status', text)
        request.sign_request(
            self._signature_method,
            self._consumer,
            token,
        )

        response = urlfetch.fetch(
            url,
            payload=data,
            method=urlfetch.POST,
            headers=request.to_header(),
        )

        return json.loads(response.content)
Example #2
0
    def get_token(self, method):
        """Return the token for the given method."""

        if not hasattr(self, 'tokens'):
            raise NotImplementedError('User object has no `tokens` attribute.')

        return json.loads(self.tokens or '{}')[method]
Example #3
0
    def get_token(self, method):
        """Return the token for the given method."""

        if not hasattr(self, 'tokens'):
            raise NotImplementedError('User object has no `tokens` attribute.')

        return json.loads(self.tokens or '{}')[method]
Example #4
0
    def post(self, text, token='', secret=''):
        """Do a Twitter profile update."""

        url = self._config['update_url'] % {
            'format': 'json',
        }

        data = {
            'status': text.encode('utf-8'),
        }
        data = urllib.urlencode(data)

        token = oauth.OAuthToken(token, secret)
        request = oauth.OAuthRequest.from_consumer_and_token(
            self._consumer,
            token=token,
            http_url=url,
            http_method='POST',
        )
        request.set_parameter('status', text)
        request.sign_request(
            self._signature_method,
            self._consumer,
            token,
        )

        response = urlfetch.fetch(
            url,
            payload=data,
            method=urlfetch.POST,
            headers=request.to_header(),
        )

        return json.loads(response.content)
Example #5
0
    def lookup_user_info(self, access_token, access_secret):
        """Lookup User Info.

        Same as `get_user_info` except that it uses a stored access_token and
        access_secret.

        """

        response = self._make_protected_request(access_token, access_secret)

        return json.loads(response.content)
Example #6
0
    def lookup_user_info(self, access_token, access_secret):
        """Lookup User Info.

        Same as `get_user_info` except that it uses a stored access_token and
        access_secret.

        """

        response = self._make_protected_request(access_token, access_secret)

        return json.loads(response.content)
Example #7
0
    def set_token(self, method, token=None):
        """Store the token for the user."""

        if not hasattr(self, 'tokens'):
            raise NotImplementedError('User object has no `tokens` attribute.')

        tokens = json.loads(self.tokens or '{}')
        if token is None:
            del tokens[method]
        else:
            tokens[method] = token

        self.tokens = json.dumps(tokens, separators=(',', ':'))

        self.save_user()
Example #8
0
    def set_token(self, method, token=None):
        """Store the token for the user."""

        if not hasattr(self, 'tokens'):
            raise NotImplementedError('User object has no `tokens` attribute.')

        tokens = json.loads(self.tokens or '{}')
        if token is None:
            del tokens[method]
        else:
            tokens[method] = token

        self.tokens = json.dumps(tokens, separators=(',', ':'))

        self.save_user()