示例#1
0
class Consumer(object):
    
    API_URI = 'http://data.hyves-api.nl/'
    REQUEST_METHOD = 'POST'
    
    HA_FORMAT = 'json'
    HA_FANCYLAYOUT = 'true'
    HA_VERSION = 'beta_2'

    def __init__(self, 
                 consumer_key, consumer_secret, 
                 oauth_token='', oauth_token_secret=''):
        self._oauth_signer = OAuthSigner(consumer_key, consumer_secret)
        self.oauth_token = oauth_token
        self.oauth_token_secret = oauth_token_secret
        for group_name, group_class in METHOD_GROUPS.iteritems():
            setattr(self, group_name, group_class(self))

    def make_call(self, method_name, **kwds):
        post_data = dict(kwds)
        post_data.update({
            'ha_method': method_name,
            'ha_format' : self.HA_FORMAT,
            'ha_fancylayout': self.HA_FANCYLAYOUT,
            'ha_version': self.HA_VERSION,
        })
        post_data = self._oauth_signer.sign_request_data(
            self.API_URI, self.REQUEST_METHOD, post_data, 
            self.oauth_token, self.oauth_token_secret
        )
        url = urllib.urlencode(post_data)
        result = '\n'.join(urllib2.urlopen(self.API_URI, url))
        return json.loads(result)
示例#2
0
 def __init__(self, 
              consumer_key, consumer_secret, 
              oauth_token='', oauth_token_secret=''):
     self._oauth_signer = OAuthSigner(consumer_key, consumer_secret)
     self.oauth_token = oauth_token
     self.oauth_token_secret = oauth_token_secret
     for group_name, group_class in METHOD_GROUPS.iteritems():
         setattr(self, group_name, group_class(self))