Exemple #1
0
        /* def __init__(self, developer_sid, auth_token, api_url=API_URL,

             opener_handlers = opener_handlers if opener_handlers else []
             self.opener = urllib2.build_opener(*opener_handlers)
             authstring = base64.b64encode('%s:%s' % (developer_sid, auth_token))
             self.opener.addheaders.append(('Authorization', 'Basic ' + authstring))
         */
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="path">The resource location</param>
        /// <param name="parameters">Optional parameters to urlencode and append to  ``path`` prefixed with a '?'.</param>
        /// <returns></returns>
        public ClientResponse Get(string path, NameValueCollection parameters = null)
        {
            string url = baseUrl + path;

            if (parameters != null)
            {
                url += "?" + ConstructQueryString(parameters);
            }

            var webRequest = CreateRequest(url);

            var response = new ClientResponse(webRequest.GetResponse());

            return response;
        }
Exemple #2
0
        /*
        def post(self, path, params):
        """Issue a ``POST /path/``.

        :param path: The resource location
        :param params: The parameters to create the resource with.
        :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)
        req = urllib2.Request(self.base_url + path, data)
        resp = self.opener.open(req)
        return ClientResponse(resp, resp.read())
        */
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public ClientResponse Put(string path, NameValueCollection parameters = null)
        {
            string url = baseUrl + path;

            var webRequest = CreateRequest(url);

            webRequest.Method = "PUT";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            if (parameters != null)
            {
                SendPostData(webRequest, parameters);
            }

            var response = new ClientResponse(webRequest.GetResponse());

            return response;
        }
Exemple #3
0
        /*
            def put(self, path, params):
                """Issue a ``PUT /path/resource-sid``.

                :param path: The resource location + the resource's sid
                :param params: The parameters to update the resource with.
                :rtype: A :class:`~poundpay.ClientResponse`.

                ::

                   client = Client('YOUR_DEVELOPER_SID', 'YOUR_AUTH_TOKEN')
                   data = {'status': '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['status'] == 'CANCELED'

                """

                data = _url_encode(params)
                req = urllib2.Request(self.base_url + path, data)
                req.get_method = lambda: 'PUT'
                resp = self.opener.open(req)
                return ClientResponse(resp, resp.read())
                */
        /// <summary>
        /// Issue a ``DELETE /path/resource-sid``.
        /// </summary>
        /// <param name="path">The resource location + the resource's sid</param>
        /// <returns></returns>
        public ClientResponse Delete(string path)
        {
            string url = baseUrl + path;

            var webRequest = CreateRequest(url);

            webRequest.Method = "DELETE";

            var response = new ClientResponse(webRequest.GetResponse());

            return response;
        }