Tedd OKANO / IFTTT

Fork of IFTTT by Austin Blackstone

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ifttt.h Source File

ifttt.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef IFTTT_H
00017 #define IFTTT_H
00018 
00019 #include "mbed.h"
00020 #include "TCPSocketConnection.h"
00021 
00022 #define IFTTT_FAIL -1
00023 #define IFTTT_SUCCESS 0
00024 
00025 #define IFTTT_MAX_RETRY 5
00026 #define IFTTT_MAX_SIZE_SECRETKEY 50
00027 #define IFTTT_MAX_SIZE_EVENTNAME 50
00028 #define IFTTT_MAX_SIZE_STRING 512
00029 
00030 //#define IFTTT_IP "50.16.216.115"
00031 #define IFTTT_IP "maker.ifttt.com"
00032 #define IFTTT_PORT 80
00033 
00034 #define IFTTT_GET 0
00035 #define IFTTT_POST 1
00036 
00037 
00038 /**
00039 * The IFTTT class (if this then that)
00040 */
00041 class IFTTT
00042 {
00043 
00044 public:
00045 
00046     /**
00047     * Constructor, initialize the Event Name and Secret Key to be used
00048     *
00049     * @param event event name of trigger
00050     * @param key secret key provided by the maker channel for your event
00051     */
00052     IFTTT(const char * event, const char * key, TCPSocketConnection * s = NULL);
00053 
00054     /**
00055     * Add ingredients (values) to be sent to maker.ifttt.com
00056     *
00057     * @param v1 value 1 to send
00058     * @param v2 value 2 to send
00059     * @param v3 value 3 to send
00060     *
00061     * @return true if successful, false if failed
00062     */
00063     bool addIngredients(char * v1 = NULL, char * v2 = NULL, char * v3 = NULL);
00064 
00065     /**
00066     * Add ingredients (values) to be sent to maker.ifttt.com
00067     *
00068     * @param v1 value 1 to send
00069     * @param v2 value 2 to send
00070     * @param v3 value 3 to send
00071     *
00072     * @return true if successful, false if failed
00073     */
00074     bool addIngredients(int v1 = NULL, int v2 = NULL, int v3 = NULL);
00075 
00076     /**
00077     * Send data via POST or GET to maker.ifttt.com
00078     *
00079     * @param iftttType specifies how to send the data. POST by default, GET optional.
00080     *
00081     * @return true if successful, false if failed
00082     */
00083     bool trigger(int triggerType = IFTTT_POST);
00084 
00085 private:
00086 
00087     /**
00088     * Send data to maker.ifttt.com via GET Query parameters
00089     *
00090     * @param name explanation
00091     *
00092     * @return true if successful, false if failed
00093     */
00094     bool get();
00095 
00096     /**
00097     * Send data to maker.ifttt.com via POST payload, encoded as JSON
00098     *
00099     * @param name explanation
00100     *
00101     * @return true if successful, false if failed
00102     */
00103     bool post();
00104 
00105     TCPSocketConnection * socket;
00106     char eventName[IFTTT_MAX_SIZE_EVENTNAME];
00107     char secretKey[IFTTT_MAX_SIZE_SECRETKEY];
00108     const char * v1;
00109     const char * v2;
00110     const char * v3;
00111     const char * host;
00112     int port;
00113 
00114 };
00115 
00116 #endif // IFTTT_H