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