Skip to content

Instantly share code, notes, and snippets.

View sidchilling's full-sized avatar

Siddharth Saha sidchilling

View GitHub Profile
@sidchilling
sidchilling / sane_response
Created October 29, 2012 08:47
Sane Stripe response
{
u'customer': None,
u'amount_refunded': 0,
u'fee': 259,
u'disputed': False,
u'description': u'CanvasOnDemand: VFS\u2013COD1022\u20131026$52Canvas(UNIQUECODES): OrderID=508569a7375e886cbd000041: OfferRef=canvasondemand_email',
u'created': 1350920815,
u'refunded': False,
u'livemode': True,
u'failure_message': None,
@sidchilling
sidchilling / incorrect_response
Created October 29, 2012 08:51
Incorrect Stripe response
{
u'account_balance': 0,
u'description': u'104627-johnnymarmolejo',
u'created': 1351305591,
u'livemode': True,
u'object': u'customer',
u'email': u'mstaniaraquel@aol.com',
u'active_card': {
u'address_city': None,
u'exp_month': 8,
@sidchilling
sidchilling / gist:4177746
Created November 30, 2012 18:56
CURL method to make GET request
<?php
$url = 'http://localhost/tests/test_get'; # URL to the service
$data = array(
'first_name' => 'siddharth',
'last_name' => 'saha',
'city' => 'pune'
);
# Making the URL with the parameters to be sent with the request
@sidchilling
sidchilling / gist:4177798
Created November 30, 2012 19:06
CURL method to make POST request
<?php
$url = 'http://localhost/tests/test_post'; # URL for the POST request
$request = curl_init($url);
$post_options = array(
CURLOPT_POST => 1, # signifies it is a POST request
CURLOPT_POSTFIELDS => $data, # $data is the data that you want to POST
CURLOPT_RETURNTRANSFER => true # required if you want to capture the response data as a string instead of just printing to the console
);
@sidchilling
sidchilling / gist:4177891
Created November 30, 2012 19:19
CURL method to make POST request with file upload
<?php
$url = 'http://localhost/tests/upload_file'; #URL for the service
$file_path = '/home/siddharthsaha/Desktop/production.html'; # File to be uploaded
$data = array(
'owner' => 'siddharth saha',
'test_file' => '@' . $file_path # For files, you have to append a @ before the filepath.
);
# Make the curl request exactly as in the POST example above.
@sidchilling
sidchilling / gist:4177963
Created November 30, 2012 19:29
HttpRequest for GET
<?php
$request = new HttpRequest($url, HttpRequest::METH_GET); #METH_GET indicates that it is a GET request
$request->addQueryData($data); # $data is the array with the parameters to send
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
# we have the response from the web-service
}
@sidchilling
sidchilling / gist:4177970
Created November 30, 2012 19:29
HttpRequest for GET
<?php
$request = new HttpRequest($url, HttpRequest::METH_GET); #METH_GET indicates that it is a GET request
$request->addQueryData($data); # $data is the array with the parameters to send
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
# we have the response from the web-service
}
@sidchilling
sidchilling / gist:4177985
Created November 30, 2012 19:32
HttpRequest for GET
<?php
$request = new HttpRequest($url, HttpRequest::METH_GET); # METH_GET signifies it is a GET request
$request->addQueryData($data); # $data is the array with the parameters to send
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
}
?>
@sidchilling
sidchilling / gist:4178024
Created November 30, 2012 19:38
HttpRequest for GET
<?php
$request = new HttpRequest($url, HttpRequest::METH_GET); # METH_GET signifies it is a GET request
$request->addQueryData($data); # $data is the array with the parameters to send
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
}
?>
@sidchilling
sidchilling / gist:4178045
Created November 30, 2012 19:42
HttpRequest for POST
<?php
$request = new HttpRequest($url, HttpRequest::METH_POST); # METH_POST indicates a POST request
$request->addPostFields($data); # use this method to add data to the POST request
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
}
?>