Changed to use domain name instead of IP address
Fork of IFTTT by
Diff: ifttt.cpp
- Revision:
- 3:c916e13a269a
- Parent:
- 2:b368358ab24c
- Child:
- 4:6edd192323df
- Child:
- 5:bef11de60a9b
--- a/ifttt.cpp Fri Jul 10 22:12:41 2015 +0000 +++ b/ifttt.cpp Mon Jul 13 17:46:37 2015 +0000 @@ -60,22 +60,24 @@ // Set up Host / Port this->port = IFTTT_PORT; this->host = IFTTT_IP; + + // Initialize ingredient values to empty strings. + v1 = ""; + v2 = ""; + v3 = ""; } // -// Send data to maker.ifttt.org -// currently only uses GET requests, unsecured +// Add ingredients to be sent. // bool -IFTTT::sendMaker( char * value1, char * value2, char * value3) +IFTTT::addIngredients( char * value1, char * value2, char * value3) { // update internal pointers. If variable not given then pass an empty string v1 = (NULL == value1)?"":value1; v2 = (NULL == value2)?"":value2; v3 = (NULL == value3)?"":value3; - int ret = post(); - DBG("Sending Data returned code : %d",ret); - return ret; + return true; } // @@ -100,6 +102,7 @@ } // Prep data to send + // TODO: verify / modify data to be query string compliant (convert spaces to '+', convert non-alpha-numberic characters to the proper encoding... etc) char str[IFTTT_MAX_SIZE_STRING] = {0}; sprintf(str, "GET /trigger/%s/with/key/%s/?value1=%s&value2=%s&value3=%s HTTP/1.1\r\nHost: maker.ifttt.com\r\n\r\n",eventName,secretKey,v1,v2,v3); DBG("String to send is:\n\r%s",str); @@ -123,7 +126,9 @@ return true; } -//TODO: Implement +// +// This function sends JSON encoded data encoded in a POST packet, +// bool IFTTT::post() { // Connect to maker.ifttt.org @@ -183,3 +188,30 @@ return true; } + +// +// Send trigger and any values associated to maker.ifttt.com +// currently unsecured (sends over HTTP, not https) +// +bool +IFTTT::trigger(int triggerType) +{ + int ret = 0; + switch(triggerType) { + case IFTTT_GET: + DBG("Sending Data as GET request"); + ret = get(); + break; + case IFTTT_POST: + DBG("Sending Data as POST request"); + ret = post(); + break; + + default: + WARN("Invalid type, defaulting to sending data as POST request"); + ret = post(); + break; + } + DBG("Sending Data return code : %d",ret); + return ret; +}