Created
February 20, 2014 10:25
-
-
Save chardcastle/9110721 to your computer and use it in GitHub Desktop.
Stash data away into couchdb (build script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get a unique ID for document | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:5984/_uuids'); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-type: application/json', | |
'Accept: */*' | |
)); | |
// No security at present | |
// curl_setopt($ch, CURLOPT_USERPWD, 'myDBusername:myDBpass'); | |
$response = curl_exec($ch); | |
$_response = json_decode($response, true); | |
$UUID = array_shift($_response['uuids']); | |
curl_close($ch); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:5984/{$databaseName}/{$UUID}"); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); /* or PUT */ | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-type: application/json', | |
'Accept: */*' | |
)); | |
// curl_setopt($ch, CURLOPT_USERPWD, 'myDBusername:myDBpass'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment