Exemplo n.º 1
0
    def patch(self, obj, alwaysIncludeEmail=None, sendNotifications=None):
        """
        Patch this resource.

        :var obj: a Python object representing the updated resource, usually in
            the same format as returned from `get`. Refer to the upstream
            documentation for details.
        :var alwaysIncludeEmail: Whether to always include a value in the
            "email" field for the organizer, creator and attendees, even
            if no real email is available. The default is False.
        :vartype alwaysIncludeEmail: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()

        params = base.get_params(("alwaysIncludeEmail", "sendNotifications"), locals())
        url = self.get_url()
        if params:
            url += "?" + http.urlencode_any(params)

        request = http.Request("PATCH", url, self.wrap_object(obj))

        return request, parsers.parse_json
Exemplo n.º 2
0
    def patch(self, obj, alwaysIncludeEmail=None, sendNotifications=None):
        """
        Patch this resource.

        :var obj: a Python object representing the updated resource, usually in
            the same format as returned from `get`. Refer to the upstream
            documentation for details.
        :var alwaysIncludeEmail: Whether to always include a value in the
            "email" field for the organizer, creator and attendees, even
            if no real email is available. The default is False.
        :vartype alwaysIncludeEmail: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()

        params = base.get_params(('alwaysIncludeEmail', 'sendNotifications'),
                                 locals())
        url = self.get_url()
        if params:
            url += '?' + http.urlencode_any(params)

        request = http.Request('PATCH', url, self.wrap_object(obj))

        return request, parsers.parse_json
Exemplo n.º 3
0
def encode_data(request):
    if not request.params:
        return b''

    if not isinstance(request.params, dict):
        return port.to_b(request.params)

    return http.urlencode_any(request.params)
Exemplo n.º 4
0
def encode_data(request):
    if not request.params:
        return b''

    if isinstance(request.params, (port.text_type, port.binary_type)):
        return port.to_b(request.params)

    return http.urlencode_any(request.params)
Exemplo n.º 5
0
def encode_data(request):
    if not request.params:
        return b''

    if isinstance(request.params, (port.text_type, port.binary_type)):
        return port.to_b(request.params)

    return http.urlencode_any(request.params)
Exemplo n.º 6
0
    def body_producer(self, params):
        if not params:
            return None

        payload = params
        if isinstance(params, dict):
            payload = our_http.urlencode_any(params)

        return StringBodyProducer(payload)
Exemplo n.º 7
0
    def body_producer(self, params):
        if not params:
            return None

        payload = params
        if not isinstance(params, (port.text_type, port.binary_type)):
            payload = our_http.urlencode_any(params)

        return StringBodyProducer(payload)
Exemplo n.º 8
0
    def body_producer(self, params):
        if not params:
            return None

        payload = params
        if isinstance(params, dict):
            payload = our_http.urlencode_any(params)

        return StringBodyProducer(payload)
Exemplo n.º 9
0
    def body_producer(self, params):
        if not params:
            return None

        payload = params
        if not isinstance(params, (port.text_type, port.binary_type)):
            payload = our_http.urlencode_any(params)

        return StringBodyProducer(payload)
Exemplo n.º 10
0
    def add_auth(self, request):
        request.headers['Content-Type'] = 'application/json'

        params = {'api_token': self.api_token}

        if request.method.upper() in http.URLENCODE_METHODS:
            request.params.update(params)
        else:
            request.params = json.dumps(request.params)
            request.uri += '?' + http.urlencode_any(params)
Exemplo n.º 11
0
    def add_auth(self, request):
        request.headers['Content-Type'] = 'application/json'

        params = {'api_token': self.api_token}

        if request.method.upper() in http.URLENCODE_METHODS:
            request.params.update(params)
        else:
            request.params = json.dumps(request.params)
            request.uri += '?' + http.urlencode_any(params)
Exemplo n.º 12
0
    def add_auth(self, request):
        params = {'key': self.key}

        if self.token:
            params.update({'token': self.token})

        if request.method.upper() in http.URLENCODE_METHODS:
            request.params.update(params)
        else:
            request.params = json.dumps(request.params)
            request.uri += '?' + http.urlencode_any(params)
Exemplo n.º 13
0
    def list_urlmetrics(self, urls, cols):
        # For url-metrics the URLs are passed as POST body, but the remaining
        # parameters should still be in the URL. Work around this by manually
        # generating the signature and then replacing the body.
        request = http.Request('POST', '')
        self.sign_request(request)
        request.nosign = True

        request.params['Cols'] = cols
        uri = '/url-metrics/?' + http.urlencode_any(request.params)
        request.uri = uri
        request.params = json.dumps(urls)

        return request, parsers.parse_json
Exemplo n.º 14
0
    def list_urlmetrics(self, urls, cols):
        # For url-metrics the URLs are passed as POST body, but the remaining
        # parameters should still be in the URL. Work around this by manually
        # generating the signature and then replacing the body.
        request = http.Request('POST', '')
        self.sign_request(request)
        request.nosign = True

        request.params['Cols'] = cols
        uri = '/url-metrics/?' + http.urlencode_any(request.params)
        request.uri = uri
        request.params = json.dumps(urls)

        return request, parsers.parse_json
Exemplo n.º 15
0
    def refund(self, amount_in_cents=None):
        """
        Refund or void a previous, successful transaction.
        """
        self.require_item()

        url = self.get_url()
        params = base.get_params(('amount_in_cents',), locals())
        if params:
            url = url + '?' + http.urlencode_any(params)

        request = http.Request('DELETE', url)

        return request, parsers.parse_empty
Exemplo n.º 16
0
    def refund(self, amount_in_cents=None):
        """
        Refund or void a previous, successful transaction.
        """
        self.require_item()

        url = self.get_url()
        params = base.get_params(('amount_in_cents', ), locals())
        if params:
            url = url + '?' + http.urlencode_any(params)

        request = http.Request('DELETE', url)

        return request, parsers.parse_empty
Exemplo n.º 17
0
 def urlencode_put(self, request):
     # UserVoice adheres to the OAuth 1.0 specification as published on
     # http://oauth.net/core/1.0/ *NOT* to the final version published as
     # RFC5849.
     #
     # This means that they don't include PUT request body in the base
     # signature string. The requests-oauth library that we're using
     # implements the RFC5849 version of OAuth and so for PUT requests it
     # generates signatures that UserVoice rejects.
     #
     # To work around this, for PUT requests we serialize the parameters to
     # a string before handing it off to the executor, which causes
     # requests-oauth to skip the body when calculating the signature.
     if request.method.upper() == 'PUT':
         request.params = http.urlencode_any(request.params)
Exemplo n.º 18
0
 def urlencode_put(self, request):
     # UserVoice adheres to the OAuth 1.0 specification as published on
     # http://oauth.net/core/1.0/ *NOT* to the final version published as
     # RFC5849.
     #
     # This means that they don't include PUT request body in the base
     # signature string. The requests-oauth library that we're using
     # implements the RFC5849 version of OAuth and so for PUT requests it
     # generates signatures that UserVoice rejects.
     #
     # To work around this, for PUT requests we serialize the parameters to
     # a string before handing it off to the executor, which causes
     # requests-oauth to skip the body when calculating the signature.
     if request.method.upper() == 'PUT':
         request.params = http.urlencode_any(request.params)
Exemplo n.º 19
0
    def postpone(self, next_renewal_date):
        """
        Postpone a subscription

        :var next_renewal_date: The next renewal date that will be applied
        :vartype next_renewal_date: str
        """
        self.require_item()

        url = '{0}/postpone'.format(self.get_url())
        params = {'next_renewal_date': next_renewal_date}
        url = url + '?' + http.urlencode_any(params)

        request = http.Request('PUT', url)

        return request, parsers.parse_empty
Exemplo n.º 20
0
    def terminate(self, refund=None):
        """
        Terminate a subsciription, removing any stored billing information.

        :var refund: The type of the refund to perform: 'full' or 'partial'
            Defaults to 'none'.
        :vartype refund: str
        """
        self.require_item()

        url = '{0}/terminate'.format(self.get_url())
        params = {'refund': refund if refund else 'none'}
        url = url + '?' + http.urlencode_any(params)

        request = http.Request('PUT', url)

        return request, parsers.parse_empty
Exemplo n.º 21
0
    def add_authorization(self, request):
        params = {}
        if self.access_token:
            params['access_token'] = self.access_token
        else:
            params['client_id'] = self.client_id

        # executors will only url encode params for the methods
        # in http.URLENCODED_METHODS. That won't work for Instagram API
        # as they expect the token to be part of the url.
        if request.method.upper() == 'DELETE':
            request.uri += '?' + http.urlencode_any(params)
        else:
            request.params.update(params)
            if request.method.upper() not in http.URLENCODE_METHODS:
                request.headers['Content-Type'] = (
                    'application/x-www-form-urlencoded')
Exemplo n.º 22
0
    def quick_add(self, text, sendNotifications=None):
        """
        Import an event.

        :var text: The text describing the event to be created.
        :vartype text: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_collection()
        params = base.get_params(None, locals())
        url = '{0}/quickAdd'.format(self.get_url())
        url += '?' + http.urlencode_any(params)
        request = http.Request('POST', url)

        return request, parsers.parse_json
Exemplo n.º 23
0
    def add_authorization(self, request):
        params = {}
        if self.access_token:
            params['access_token'] = self.access_token
        else:
            params['client_id'] = self.client_id

        # executors will only url encode params for the methods
        # in http.URLENCODED_METHODS. That won't work for Instagram API
        # as they expect the token to be part of the url.
        if request.method.upper() == 'DELETE':
            request.uri += '?' + http.urlencode_any(params)
        else:
            request.params.update(params)
            if request.method.upper() not in http.URLENCODE_METHODS:
                request.headers['Content-Type'] = (
                    'application/x-www-form-urlencoded')
Exemplo n.º 24
0
    def expect(self, method=None, uri=None, params={}):
        if method:
            self.assertEqual(method, self.executor.request.method)

        auth_params = {'key': 'my-key', 'token': 'my-token'}

        if method != 'GET':
            uri += '?' + http.urlencode_any(auth_params)

        self.assertEqual(self.executor.request.uri,
                         'https://api.trello.com/1' + uri)

        if method == 'GET':
            params.update(auth_params)

        if params:
            self.assertEqual(self.executor.request.params, params)
Exemplo n.º 25
0
    def quick_add(self, text, sendNotifications=None):
        """
        Import an event.

        :var text: The text describing the event to be created.
        :vartype text: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_collection()
        params = base.get_params(None, locals())
        url = "{0}/quickAdd".format(self.get_url())
        url += "?" + http.urlencode_any(params)
        request = http.Request("POST", url)

        return request, parsers.parse_json
Exemplo n.º 26
0
    def delete(self, sendNotifications=None):
        """
        Delete this resource.

        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()

        params = base.get_params(None, locals())
        url = self.get_url()
        if params:
            url += "?" + http.urlencode_any(params)

        request = http.Request("DELETE", url)

        return request, parsers.parse_empty
Exemplo n.º 27
0
    def move(self, destination, sendNotifications=None):
        """
        Move an event to another calendar.

        :var destination: Calendar identifier of the target calendar
            where the event is to be moved to.
        :vartype destination: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()
        params = base.get_params(None, locals())
        url = "{0}/move".format(self.get_url())
        url += "?" + http.urlencode_any(params)
        request = http.Request("POST", url)

        return request, parsers.parse_json
Exemplo n.º 28
0
    def expect(self, method=None, uri=None, params={}):
        if method:
            self.assertEqual(method, self.executor.request.method)

        auth_params = {'key': 'my-key', 'token': 'my-token'}

        if method != 'GET':
            uri += '?' + http.urlencode_any(auth_params)

        self.assertEqual(
            self.executor.request.uri,
            'https://api.trello.com/1' + uri)

        if method == 'GET':
            params.update(auth_params)

        if params:
            self.assertEqual(self.executor.request.params, params)
Exemplo n.º 29
0
    def move(self, destination, sendNotifications=None):
        """
        Move an event to another calendar.

        :var destination: Calendar identifier of the target calendar
            where the event is to be moved to.
        :vartype destination: str
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()
        params = base.get_params(None, locals())
        url = '{0}/move'.format(self.get_url())
        url += '?' + http.urlencode_any(params)
        request = http.Request('POST', url)

        return request, parsers.parse_json
Exemplo n.º 30
0
    def delete(self, sendNotifications=None):
        """
        Delete this resource.

        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_item()

        params = base.get_params(None, locals())
        url = self.get_url()
        if params:
            url += '?' + http.urlencode_any(params)

        request = http.Request('DELETE', url)

        return request, parsers.parse_empty
Exemplo n.º 31
0
    def terminate(self, refund=None):
        """
        Terminate a subsciription, removing any stored billing information.

        :var refund: The type of the refund to perform: 'full' or 'partial'
            Defaults to 'none'.
        :vartype refund: str
        """
        self.require_item()

        url = '{0}/terminate'.format(self.get_url())
        params = {
            'refund': refund if refund else 'none'
        }
        url = url + '?' + http.urlencode_any(params)

        request = http.Request('PUT', url)

        return request, parsers.parse_empty
Exemplo n.º 32
0
    def create(self, obj, sendNotifications=None):
        """
        Create a new resource.

        :var obj: a Python object representing the resource to be created,
            usually in the same format as returned from `get`. Refer to the
            upstream documentation for details.
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_collection()

        params = base.get_params(("sendNotifications",), locals())
        url = self.get_url()
        if params:
            url += "?" + http.urlencode_any(params)

        request = http.Request("POST", url, self.wrap_object(obj))

        return request, parsers.parse_empty
Exemplo n.º 33
0
    def create(self, obj, sendNotifications=None):
        """
        Create a new resource.

        :var obj: a Python object representing the resource to be created,
            usually in the same format as returned from `get`. Refer to the
            upstream documentation for details.
        :var sendNotifications: Whether to send notifications.
            The default is False.
        :vartype sendNotifications: str
        """
        self.require_collection()

        params = base.get_params(('sendNotifications', ), locals())
        url = self.get_url()
        if params:
            url += '?' + http.urlencode_any(params)

        request = http.Request('POST', url, self.wrap_object(obj))

        return request, parsers.parse_empty
Exemplo n.º 34
0
def encode_uri(request):
    if not request.params:
        return request.uri

    return request.uri + '?' + http.urlencode_any(request.params)
Exemplo n.º 35
0
    def encode_uri(self, request):
        if not request.params:
            return request.uri

        return request.uri + '?' + our_http.urlencode_any(request.params)
Exemplo n.º 36
0
    def encode_uri(self, request):
        if not request.params:
            return request.uri

        return request.uri + "?" + our_http.urlencode_any(request.params)