예제 #1
0
    def put(self, path, params, headers=None):
        """Issue a ``PUT /path/resource-sid``.

        :param path: The resource location + the resource's sid
        :param params: The parameters to update the resource with.
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           data = {'state': 'CANCELED'}
           client_response = client.put('/silver/payments/PY...', data)
           assert client_response.response.getcode() == 201
           assert isinstance(client_response.json, dict)
           assert client_response.json['state'] == 'CANCELED'

        """

        data = _url_encode(params)
        current_url = self.base_url + path
        req = urllib2.Request(current_url, data, headers=headers or {})
        req.get_method = lambda: 'PUT'
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
예제 #2
0
    def post(self, path, params, headers=None):
        """Issue a ``POST /path/``.

        :param path: The resource location
        :param params: The parameters to create the resource with.
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           data = {
              'amount': 4000,
              'payer_email_address': '*****@*****.**',
              'recipient_email_address': '*****@*****.**',
              'payer_fee_amount': 100,
              'recipient_fee_amount': 0,
           }
           client_response = client.post('/silver/payments', data)
           assert client_response.response.getcode() == 201
           assert isinstance(client_response.json, dict)
           for key, value in data.iteritems():
               assert client_response.json[key] == value

        """
        data = _url_encode(params)
        current_url = self.base_url + path
        req = urllib2.Request(current_url, data, headers=headers or {})
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
예제 #3
0
    def put(self, path, params, headers=None):
        """Issue a ``PUT /path/resource-sid``.

        :param path: The resource location + the resource's sid
        :param params: The parameters to update the resource with.
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           data = {'state': 'CANCELED'}
           client_response = client.put('/silver/payments/PY...', data)
           assert client_response.response.getcode() == 201
           assert isinstance(client_response.json, dict)
           assert client_response.json['state'] == 'CANCELED'

        """

        data = _url_encode(params)
        current_url = self.base_url + path
        req = urllib2.Request(current_url, data, headers=headers or {})
        req.get_method = lambda: 'PUT'
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
예제 #4
0
    def post(self, path, params, headers=None):
        """Issue a ``POST /path/``.

        :param path: The resource location
        :param params: The parameters to create the resource with.
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           data = {
              'amount': 4000,
              'payer_email_address': '*****@*****.**',
              'recipient_email_address': '*****@*****.**',
              'payer_fee_amount': 100,
              'recipient_fee_amount': 0,
           }
           client_response = client.post('/silver/payments', data)
           assert client_response.response.getcode() == 201
           assert isinstance(client_response.json, dict)
           for key, value in data.iteritems():
               assert client_response.json[key] == value

        """
        data = _url_encode(params)
        current_url = self.base_url + path
        req = urllib2.Request(current_url, data, headers=headers or {})
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
예제 #5
0
    def get(self, path, headers=None, **params):
        """Issue a ``GET /path/``. If the ``/path/`` has a resource-sid
        associated with it, this will return the representation of the
        resource located at ``/path/`` that has that associated resource-sid.

        :param path: The resource location
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :param params: Optional parameters to `urllib.urlencode <http://docs.
           python.org/library/urllib.html#urllib.urlencode>`_ and append to
           ``path`` prefixed with a '?'.
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           # issue an index on all our payments
           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           client_response = client.get('/silver/payments/')
           assert client_response.response.getcode() == 200
           # gives us back a paginated response
           payload = client_response.json
           assert 'num_pages' in payload
           assert 'page_size' in payload
           assert 'payments' in payload   # will be the resource name

           # show a resource with resource-sid PY...
           client_response = client.get('/silver/payments/PY...')
           assert client_response.response.getcode() == 200
           assert isinstance(client_response.json, dict)
           assert client_response.json['sid'] == 'PY...'

        """
        if params:
            params = _url_encode(params)
            path = path.rstrip('/') + '/?' + params
        current_url = self.base_url + path
        req = urllib2.Request(current_url, headers=headers or {})
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
예제 #6
0
    def get(self, path, headers=None, **params):
        """Issue a ``GET /path/``. If the ``/path/`` has a resource-sid
        associated with it, this will return the representation of the
        resource located at ``/path/`` that has that associated resource-sid.

        :param path: The resource location
        :param headers: Optional parameter that should be a dictionary and
           will be passed on the urllib2.Request object
        :param params: Optional parameters to `urllib.urlencode <http://docs.
           python.org/library/urllib.html#urllib.urlencode>`_ and append to
           ``path`` prefixed with a '?'.
        :rtype: A :class:`~poundpay.ClientResponse`.

        ::

           # issue an index on all our payments
           client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
           client_response = client.get('/silver/payments/')
           assert client_response.response.getcode() == 200
           # gives us back a paginated response
           payload = client_response.json
           assert 'num_pages' in payload
           assert 'page_size' in payload
           assert 'payments' in payload   # will be the resource name

           # show a resource with resource-sid PY...
           client_response = client.get('/silver/payments/PY...')
           assert client_response.response.getcode() == 200
           assert isinstance(client_response.json, dict)
           assert client_response.json['sid'] == 'PY...'

        """
        if params:
            params = _url_encode(params)
            path = path.rstrip('/') + '/?' + params
        current_url = self.base_url + path
        req = urllib2.Request(current_url, headers=headers or {})
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())