From 2ec340a05455ee54fc6e08822d30f4eff02d79d8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 1 May 2017 17:53:54 +0200 Subject: [PATCH] Add a processing example --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 446ab0e..63b45f5 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,8 @@ WantedBy=multi-user.target If you want to print messages from your application, you can use the external API. -For example, with curl: + +#### With curl ```bash curl \ @@ -80,6 +81,45 @@ curl \ http://127.0.0.1:5000/ext_api/v1/printer/1/print_html?api_key= ``` +#### With Processing + +You'll need an external library named unirest and its dependencies. +You can download it directly from my server : [unirest-java-1.4.10.jar](https://cloud.deuxfleurs.fr/f/685c77efbd/?raw=1) +Or, if you prefer, you can compile it from the source by following this [guide](http://blog.mashape.com/installing-unirest-java-with-the-maven-assembly-plugin/). + +Once you have the `unirest-java-1.4.10.jar` (or another version): + + 1. Create a folder named `code` inside your sketchbook folder, next to your Processing files (use File explorer on Windows, Finder on Mac OS, etc.) + 2. Put `unirest-java-1.4.10.jar` in this folder + +Now restart processing and add the following in your project: + +```processing +import com.mashape.unirest.http.*; +import com.mashape.unirest.http.exceptions.UnirestException; + +boolean little_print(String face, String message, String endpoint, String api_key) { + try { + com.mashape.unirest.http.HttpResponse request = Unirest.post(endpoint+"?api_key="+api_key) + .body("{\"message\": \"" + message.replace("\"", "\\\"") +"\", \"face\": \"" + face.replace("\"", "\\\"") + "\"}") + .asString(); + + println(request.getBody()); + return true; + } catch (Exception e) { + println(e); + return false; + } +} + +``` + +Each time you want to use your little printer to print something, you should write something like this (don't forget to put your API key and update the URL): + +```processing +little_print("noface", "

PROOOOCESSING

", "http://127.0.0.1:5000/ext_api/v1/printer/1/print_html", "xxxxxxxxx"); +``` + ### Environment variables The server can be configured with the following variables: -- 2.47.3