Showing posts with label Ralapanawa. Show all posts
Showing posts with label Ralapanawa. Show all posts

Ralapanawa Android Module Open Sourced!




Ralapanawa Android Module is one of the Mobility modules we have developed for Ralapanawa RND project. This project has used wide variety of features and functionalites on Android Technology. So finally we thought to Open Source the whole source code for the sake of other newbie developers specially for educational purposes.

Some major functionality.
  • Graphical illustrations (Charts)
  • Data tables to populate bulk data.
  • Handling KSOAP client to fetch SOAP web services within Android.
  • Handling REST web services.
  • SMS based services.
  • Feedback Functions. (Consumer to Dev)
  • Showing Progress bars while handling UI Threads
  • Grid views for menu.
  • UI theming
  • and many more..

-------------------------------------------------
 Ralapanawa.Mobile.Module - README
-------------------------------------------------

Android Derivative of the Ralapanawa Centralized Web Service

Released Under: MIT License 2012 Harsha Siriwardena

@authors: harshadura, dewmal

Download App from Google Play Market:
https://play.google.com/store/apps/details?id=org.ralapanawa.mobile.android

For more info visit project blog:
http://www.ralapanawa.org/






Please note we have wasted our good precious time to create this wonderful product. So if you gonna reuse our work in someway, please mind to give proper credit to us. Thanks!

- Harsha

 

How to write REST Web Services using PHP

<?php

function getStatusCodeMessage($status)
{
    $codes = Array(
        100 => 'Continue',
        101 => 'Switching Protocols',
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        306 => '(Unused)',
        307 => 'Temporary Redirect',
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported'
    );

    return (isset($codes[$status])) ? $codes[$status] : '';
}

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}

class RalapanawaAPI {

    private $db;

    function __construct() {
        $this->db = new mysqli('localhost', 'USER', 'PASS', 'ralapanawa');
    }

    function __destruct() {
        $this->db->close();
    }

    function rala() {

        if (isset($_POST["tank_id"]) && isset($_POST["water_level"]) ) {
            try{
                $tank_id = $_POST["tank_id"];
                $water_level = $_POST["water_level"];

                $stmt = $this->db->prepare("INSERT INTO water_level (tankid, Depth) VALUES (?, ?)");
                $stmt->bind_param("ss", $tank_id, $water_level);
                $stmt->execute();
                $stmt->close();

                sendResponse(200, 'Water Level Saved!');
                return true;
            } catch (Exception $e) {
                $err = 'Caught exception: '.  $e->getMessage().  "\n";
                sendResponse(200, $err);
                return false;
            }
        }

        if (isset($_POST["tank_id"]) ) {

            $depth = "";
            $tank_id = $_POST["tank_id"];

            $stmt = $this->db->prepare("SELECT Depth FROM water_level WHERE tankid=?");
            $stmt->bind_param("s", $tank_id);
            $stmt->execute();
            $stmt->bind_result($depth);

            while ($stmt->fetch()) {
                break;
            }
            $stmt->close();

            $result = array(
                "water_level" => $depth
            );
            sendResponse(200, json_encode($result));
            return true;
        }

        sendResponse(400, 'Invalid request');
        return false;

    }
}

$api = new RalapanawaAPI;
$api->rala();

?>

curl -F "rw_app_id=1" -F "code=test" -F "device_id=test" http://www.wildfables.com/promos/


https://gist.github.com/3041075

REF:
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app