package chemp.Ifttt; import java.io.*; import java.net.*; import net.arnx.jsonic.JSON; public class Ifttt { public boolean callEvent(String event, String key, String value1, String value2, String value3) { boolean result = false; try { URL url = new URL( "https://maker.ifttt.com/trigger/" + event + "/with/key/" + key ); HttpURLConnection urlCon = (HttpURLConnection)url.openConnection(); urlCon.addRequestProperty("Content-Type", "application/json"); urlCon.setRequestMethod("POST"); urlCon.setDoOutput(true); urlCon.connect(); IftttValues values = new IftttValues(value1, value2, value3); String jsonText = JSON.encode(values); DataOutputStream os = new DataOutputStream(urlCon.getOutputStream()); os.write(jsonText.getBytes("UTF-8")); os.flush(); os.close(); int statusCode = urlCon.getResponseCode(); if ( statusCode == 200 ) { result = true; } urlCon.disconnect(); } catch (IOException e) { e.printStackTrace(); } return result; } }