Ejemplo n.º 1
0
    def test_do_http_call(self):
        """Try to do an HTTP request
        """

        result = do_http_call(
            'http://youtube.com/crossdomain.xml',
            {
              'test':'value'
            },
            False
        )

        self.assertTrue(result.count('test=value')>0)
Ejemplo n.º 2
0
    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)