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
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
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)
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)
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)
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)
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)
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)
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
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
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
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)
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
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
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')
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
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)
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
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
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
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)
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
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
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
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
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
def encode_uri(request): if not request.params: return request.uri return request.uri + '?' + http.urlencode_any(request.params)
def encode_uri(self, request): if not request.params: return request.uri return request.uri + '?' + our_http.urlencode_any(request.params)
def encode_uri(self, request): if not request.params: return request.uri return request.uri + "?" + our_http.urlencode_any(request.params)