Api wrapper to communicate with EVRYTHNG's Engine.

Dependencies:   EthernetInterface mbed-rtos

Dependents:   EvrythngApiExample

Committer:
vladounet
Date:
Thu Aug 30 13:25:41 2012 +0000
Revision:
1:7162d0e030f5
Parent:
0:d38d192c2f5f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vladounet 0:d38d192c2f5f 1 /*
vladounet 0:d38d192c2f5f 2 * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich
vladounet 0:d38d192c2f5f 3 * www.evrythng.com
vladounet 0:d38d192c2f5f 4 *
vladounet 0:d38d192c2f5f 5 * --- DISCLAIMER ---
vladounet 0:d38d192c2f5f 6 *
vladounet 0:d38d192c2f5f 7 * EVRYTHNG provides this source code "as is" and without warranty of any kind,
vladounet 0:d38d192c2f5f 8 * and hereby disclaims all express or implied warranties, including without
vladounet 0:d38d192c2f5f 9 * limitation warranties of merchantability, fitness for a particular purpose,
vladounet 0:d38d192c2f5f 10 * performance, accuracy, reliability, and non-infringement.
vladounet 0:d38d192c2f5f 11 *
vladounet 0:d38d192c2f5f 12 * Author: Michel Yerly
vladounet 0:d38d192c2f5f 13 *
vladounet 0:d38d192c2f5f 14 */
vladounet 0:d38d192c2f5f 15 #ifndef EVRYTHNGAPI_H
vladounet 0:d38d192c2f5f 16 #define EVRYTHNGAPI_H
vladounet 0:d38d192c2f5f 17
vladounet 0:d38d192c2f5f 18 #include "EthernetInterface.h"
vladounet 0:d38d192c2f5f 19 #include <string>
vladounet 0:d38d192c2f5f 20
vladounet 0:d38d192c2f5f 21 #include <stdint.h>
vladounet 0:d38d192c2f5f 22
vladounet 0:d38d192c2f5f 23 enum HttpMethod {
vladounet 0:d38d192c2f5f 24 GET, PUT, POST, DELETE
vladounet 0:d38d192c2f5f 25 };
vladounet 0:d38d192c2f5f 26
vladounet 0:d38d192c2f5f 27
vladounet 0:d38d192c2f5f 28 /*
vladounet 0:d38d192c2f5f 29 * Class to communicate with EVRYTHNG engine.
vladounet 0:d38d192c2f5f 30 */
vladounet 0:d38d192c2f5f 31 class EvrythngApi
vladounet 0:d38d192c2f5f 32 {
vladounet 0:d38d192c2f5f 33 public:
vladounet 0:d38d192c2f5f 34
vladounet 0:d38d192c2f5f 35 /*
vladounet 0:d38d192c2f5f 36 * Constructor
vladounet 0:d38d192c2f5f 37 */
vladounet 1:7162d0e030f5 38 EvrythngApi(const std::string& token, const std::string& host = "api.evrythng.com", int port = 80);
vladounet 0:d38d192c2f5f 39
vladounet 0:d38d192c2f5f 40 /*
vladounet 0:d38d192c2f5f 41 * Destructor
vladounet 0:d38d192c2f5f 42 */
vladounet 0:d38d192c2f5f 43 virtual ~EvrythngApi();
vladounet 0:d38d192c2f5f 44
vladounet 0:d38d192c2f5f 45 /*
vladounet 0:d38d192c2f5f 46 * Reads the current value of a thng's property. The value read is put
vladounet 0:d38d192c2f5f 47 * in the value parameter.
vladounet 0:d38d192c2f5f 48 * Returns 0 on success, or an error code on error. Error codes are
vladounet 0:d38d192c2f5f 49 * described in evry_error.h.
vladounet 0:d38d192c2f5f 50 */
vladounet 0:d38d192c2f5f 51 int getThngPropertyValue(const std::string& thngId, const std::string& key, std::string& value);
vladounet 0:d38d192c2f5f 52
vladounet 0:d38d192c2f5f 53 /*
vladounet 0:d38d192c2f5f 54 * Sets the value of a thng's property.
vladounet 0:d38d192c2f5f 55 * Returns 0 on success, or an error code on error. Error codes are
vladounet 0:d38d192c2f5f 56 * described in evry_error.h.
vladounet 0:d38d192c2f5f 57 */
vladounet 0:d38d192c2f5f 58 int setThngPropertyValue(const std::string& thngId, const std::string& key, const std::string& value, int64_t timestamp);
vladounet 0:d38d192c2f5f 59
vladounet 0:d38d192c2f5f 60 private:
vladounet 0:d38d192c2f5f 61 std::string token;
vladounet 0:d38d192c2f5f 62 std::string host;
vladounet 0:d38d192c2f5f 63 int port;
vladounet 0:d38d192c2f5f 64
vladounet 0:d38d192c2f5f 65 int httpRequest(HttpMethod method, const std::string& path, const std::string& content, std::string& out, int& codeOut);
vladounet 0:d38d192c2f5f 66
vladounet 0:d38d192c2f5f 67 int httpPut(const std::string& path, const std::string& json, std::string& out, int& codeOut);
vladounet 0:d38d192c2f5f 68 int httpGet(const std::string& path, std::string& out, int& codeOut);
vladounet 0:d38d192c2f5f 69 int httpPost(const std::string& path, const std::string& json, std::string& out, int& codeOut);
vladounet 0:d38d192c2f5f 70 int httpDelete(const std::string& path, std::string& out, int& codeOut);
vladounet 0:d38d192c2f5f 71 };
vladounet 0:d38d192c2f5f 72
vladounet 0:d38d192c2f5f 73 #endif