def do_batch_methods( self, methods = None, token = None, http_type = HTTP_TYPE_POST): """Requires an array of methods. Each method is an object with the following properties: * params * ha_method Requires the 'batch.process' API call to be available """ data = [] for method in methods: default_params = { 'ha_method': method['ha_method'], 'ha_fancylayout': GenusApi.DEFAULT_HA_FANCYLAYOUT, 'ha_format': GenusApi.DEFAULT_HA_FORMAT, 'ha_version': self.ha_version } params = method['params'] params.update(default_params) data.append(oauth_util.normalize_key_value_parameters(params)) return self.do_method( 'batch.process', { 'request': ','.join(data) }, token, http_type )
def do_method(self, ha_method, params, token = None, http_type = HTTP_TYPE_POST): """Makes the hyves API call, raises exceptions over bad HTTP status codes and Hyves errors """ default_params = { 'oauth_consumer_key': self.consumer.key, 'oauth_timestamp': self.get_oauth_timestamp(), 'oauth_nonce': self.get_oauth_nonce(), 'oauth_signature_method': GenusApi.DEFAULT_OAUTH_SIGNATURE_METHOD, 'ha_method': ha_method, 'ha_format': GenusApi.DEFAULT_HA_FORMAT, 'ha_fancylayout': GenusApi.DEFAULT_HA_FANCYLAYOUT, 'ha_version': self.ha_version, } oauth_consumer_secret = self.consumer.secret oauth_token_secret = '' if token: default_params['oauth_token'] = token.key oauth_token_secret = token.secret params.update(default_params) params['oauth_signature'] = utils.calculate_oauth_signature( http_type, GenusApi.API_URL, params, oauth_consumer_secret, oauth_token_secret) params = oauth_util.normalize_key_value_parameters(params) try: response = utils.do_http_call( GenusApi.API_URL, params, http_type == GenusApi.HTTP_TYPE_POST ) except IOError, exception: self.logger.exception(exception)