Example #1
0
/*
 * A real quick example to get and update a doc.
 */
require_once './src/Sag.php';
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$school = $_POST['school'];
$discipline = $_POST['discipline'];
$sag = new Sag('127.0.0.1', '5984');
// Select the database that holds our blog's data.
$sag->setDatabase('sakib');
try {
    //Get a blog post (a StdClass)...
    $post = $sag->get('postID')->body;
    //...update its info...
    $post->views++;
    //..and send it back to the couch.
    if (!$sag->put($post->_id, $post)->body->ok) {
        error_log('Unable to log a view to CouchDB.');
    }
} catch (SagCouchException $e) {
    //The requested post doesn't exist - oh no!
    if ($e->getCode() == "404") {
        $e = new Exception("That post doesn't exist.");
    }
    throw $e;
} catch (SagException $e) {
    //We sent something to Sag that it didn't expect.
    error_log('Programmer error: ' . $e->getMessage());
}
    $sag->login($myUsername, $myPassword);
    // Now that we are logged in, we can create a database to use
    //$sag->createDatabase("ttpfeedback");
    $sag->setDatabase("ttpfeedback");
    /****feedback document starts ****/
    $namee = $_POST["name"];
    $com = $_POST["com"];
    $tweet = $_POST["tweet"];
    $acc = $_POST["service"];
    $sw = $_POST["topic"];
    $text = $_POST["text"];
    $rating = $_POST["rating"];
    /**test starts**/
    $ch = curl_init();
    $customer = array('EmailID' => $tweet, 'Organization' => $com, 'Rating' => $rating, 'Service' => $acc, 'Topics' => $sw, 'comments' => $text);
    $sag->put('"' . $namee . '"', $customer);
    /** feedback document ends **/
} catch (Exception $e) {
    //We sent something to Sag that it didn't expect.
    echo '<p>There Was an Error Getting Data from Cloudant!!!</p>';
    echo $e->getMessage();
}
echo "Thank you.." . $namee . "..for the Feedback !! ";
//-------------------------------------------------------------------------------
// Copyright IBM Corp. 2014
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// vcap_services Extraction
$services_json = json_decode(getenv('VCAP_SERVICES'), true);
$VcapSvs = $services_json["cloudantNoSQLDB"][0]["credentials"];
//Debug: If you want to see all the variables returned you can use this line of code.
//var_dump($services_json);
// Extract the VCAP_SERVICES variables for Cloudant connection.
$myUsername = $VcapSvs["username"];
$myPassword = $VcapSvs["password"];
try {
    // Let's login to the database.
    $sag = new Sag($myUsername . ".cloudant.com");
    $sag->login($myUsername, $myPassword);
    // Now that we are logged in, we can create a database to use
    $sag->createDatabase("mydatabase");
    $sag->setDatabase("mydatabase");
    if (!$sag->put("myId", '{"myKey":"Hello World from Cloudant!"}')->body->ok) {
        error_log('Unable to post a document to Cloudant.');
    } else {
        // We are now going to read a document from our cloudant database. We are going
        // to retrieve the value associated with myKey from the body of the document.
        //The SAG PHP library takes care of all the gory details and only retrieves the value.
        $resp = $sag->get('myId')->body->myKey;
        echo $resp;
    }
    // Assuming everything above was executed without error, we now are connected to the
    // database and have retrieved the value.
    //NOTE: Since we have a connection to the database, we can query the database for other
    //      documents and retrieve other variables at a later time. We do not need to connect
    //      to the database again.
} catch (Exception $e) {
    //We sent something to Sag that it didn't expect.
Example #4
0
<?php

header('Content-Type:text/plain');
require_once 'check_and_start_session.php';
require_once 'Sag/Sag.php';
$s = new Sag();
$s->setDatabase('slouchin_test');
// requires login, but we've got a cookie!
$s->setAuthSession(session_id());
$doc = new stdClass();
$doc->test = 'doc';
$doc->used_session_id = $s->authSession;
try {
    $res = $s->put(uniqid(), $doc);
    print_r($res);
} catch (SagCouchException $e) {
    print_r($e->getCode());
    print_r($e->getMessage());
}
Example #5
0
 public function test_createDocWithSession()
 {
     $db = new Sag($this->couchIP);
     $db->setDatabase($this->couchDBName);
     $db->login('admin', 'passwd', Sag::$AUTH_COOKIE);
     $doc = new StdClass();
     $doc->sag = 'for couchdb';
     $res = $db->put('sag', $doc);
     $this->assertTrue($res->body->ok);
     $del_res = $db->delete('sag', $res->body->rev);
     $this->assertTrue($del_res->body->ok);
 }
<?php

// Include required classes.
require 'classes/tropo.class.php';
require 'classes/sag/sag.php';
// Grab the raw JSON sent from Tropo.
$json = file_get_contents("php://input");
// Create a new Session object and obtain the session ID value.
$session = new Session($json);
$session_id = $session->getId();
// Insert the Session object into a CouchDB database called sessions.
try {
    $sag = new Sag();
    $sag->setDatabase("sessions");
    $sag->put($session_id, $json);
} catch (SagCouchException $ex) {
    die("*** " . $ex->getMessage() . " ***");
}
// Create a new Tropo object.
$tropo = new Tropo();
// Set options for an Ask.
$options = array("attempts" => 20, "bargein" => true, "choices" => "[5 DIGITS]", "name" => "zip", "timeout" => 5, "allowSignals" => array("tooLong", "farTooLong"));
$tropo->ask("Please enter your 5 digit zip code.", $options);
// Set event handlers
$tropo->on(array("event" => "continue", "next" => "get_zip_code.php?uri=end", "say" => "Please hold."));
$tropo->on(array("event" => "tooLong", "next" => "get_zip_code.php?uri=end&tooLong=true", "say" => "Please hold on."));
$tropo->on(array("event" => "farTooLong", "next" => "get_zip_code.php?uri=end&farTooLong=true", "say" => "Please hold on for dear life."));
// Render JSON for Tropo to consume.
$tropo->renderJSON();
if (!isset($config) || !is_array($config)) {
    die("broken or missing configuration file?");
}
date_default_timezone_set(getConfig($config, 'time_zone', FALSE, 'Europe/Amsterdam'));
$dbName = getConfig($config, 'db_name', TRUE);
require_once "ext/sag/src/Sag.php";
$storage = new Sag();
$storage->setDatabase($dbName);
do {
    $toTranscode = $storage->get("_design/files/_view/get_media_status?limit=1&startkey=[\"WAITING\"]&endkey=[\"WAITING\",{}]")->body->rows;
    if (!empty($toTranscode)) {
        $t = $toTranscode[0];
        $id = $t->id;
        $info = $storage->get($id)->body;
        $info->transcodeStatus = 'PROGRESS';
        $storage->put($id, $info);
        $fileOwner = $info->fileOwner;
        $fileName = getConfig($config, 'file_storage_dir', TRUE) . DIRECTORY_SEPARATOR . base64_encode($fileOwner) . DIRECTORY_SEPARATOR . $info->fileName;
        if (isset($info->video)) {
            $transcodeFileName = getConfig($config, 'cache_dir', TRUE) . DIRECTORY_SEPARATOR . $info->video->transcode->{$videoHeight}->file;
            $newSize = $info->video->transcode->{$videoHeight}->width . "x" . $info->video->transcode->{$videoHeight}->height;
            // -vf transpose=1   (for rotating clockwise 90 degrees)
            $cmd = "ffmpeg -i \"{$fileName}\" -threads 2 -f webm -acodec libvorbis -vcodec libvpx -s {$newSize} -b 524288 -y {$transcodeFileName}";
        } elseif (isset($info->audio)) {
            $transcodeFileName = getConfig($config, 'cache_dir', TRUE) . DIRECTORY_SEPARATOR . $info->audio->transcode->file;
            $cmd = "ffmpeg -i \"{$fileName}\" -threads 2 -f ogg -acodec libvorbis -ab 96000 -y {$transcodeFileName}";
        }
        $returnValue = execCommand($cmd, 'data' . DIRECTORY_SEPARATOR . basename($transcodeFileName) . ".log", "Transcoding {$fileName}");
        $info = $storage->get($id)->body;
        if ($returnValue != 0) {
            $info->transcodeStatus = 'FAILED';