Пример #1
0
    def send_request(self, client=None, url=None, method='GET', params=None, **kwargs):

        url, body = self.normalize_url_and_params(url, params)
        response, content = client.request(url, method, body=body, **kwargs)
        if response['status'] == '200':
            return dict(cgi.parse_qsl(content))
        else:
            raise OAuthError('response is %s' % response)
Пример #2
0
 def send_request(self,
                  client=None,
                  url=None,
                  method='GET',
                  params=None,
                  **kwargs):
     url, body = self.normalize_url_and_params(url, params)
     response, content = client.request(url, method, body=body, **kwargs)
     if response['status'] == '200':
         parsed_response = dict(cgi.parse_qsl(content))
         #todo: validate parsed response. For now
         #a simple check for the dictionary emptiness
         if parsed_response:
             return parsed_response
         else:
             raise OAuthError(
                 'error obtaining request token {}'.format(content))
     else:
         raise OAuthError('response is {}'.format(response))
Пример #3
0
 def get_linked_in_user_id(data):
     consumer = oauth.Consumer(data['consumer_key'], data['consumer_secret'])
     token = oauth.Token(data['oauth_token'], data['oauth_token_secret'])
     client = oauth.Client(consumer, token=token)
     url = 'https://api.linkedin.com/v1/people/~:(first-name,last-name,id)'
     response, content = client.request(url, 'GET')
     if response['status'] == '200':
         id_re = re.compile(r'<id>([^<]+)</id>')
         matches = id_re.search(content)
         if matches:
             return matches.group(1)
     raise OAuthError()