Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hrbrmstr/nifffty
Small R package to post events to IFTTT Maker channel/recipes
https://github.com/hrbrmstr/nifffty
Last synced: 2 months ago
JSON representation
Small R package to post events to IFTTT Maker channel/recipes
- Host: GitHub
- URL: https://github.com/hrbrmstr/nifffty
- Owner: hrbrmstr
- License: other
- Created: 2015-06-19T13:33:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-18T11:46:49.000Z (over 6 years ago)
- Last Synced: 2024-10-12T21:25:00.749Z (3 months ago)
- Language: R
- Homepage:
- Size: 117 KB
- Stars: 40
- Watchers: 6
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output:
md_document:
variant: markdown_github
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```![img](nifffty.png)
nifffty is a simple package to post events/data to an IFTTT Maker channel/recipe *and* receive events (via Maker) from IFTTT actions.
Inspired by a [blog post by Brian Connelly](http://bconnelly.net/2015/06/connecting-r-to-everything-with-ifttt/).
Here is a [sample public recipe](https://ifttt.com/recipes/300804-post-maker-event-values-to-dropbox-file) for posting the contents of a `maker` request to a file on Dropbox. The example below, which calls `maker("rtest", "this", "is a", "test")` will create a file in a Dropbox folder (in an `IFTTT/Maker/rtest` directory) that has the contents:
Value 1: this
Value 2: is a
Value 3: test
(How the contents is formatted is entirely up to you.)Brian's example posts an iOS notification, but you can do many, many things with this capability.
Future enhancements will include the ability to have Shiny use Maker web POST calls as inputs.
The following functions are implemented:
- `ifttt_api_key`: Get or set IFTTT_KEY value
- `maker`: Issue IFTTT maker channel POST event
- `receiver`: Listen and react to IFTTT Maker web calls### Installation
```{r ex, eval=FALSE}
devtools::install_github("hrbrmstr/nifffty")
``````{r setup, echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```### Usage
```{r usage}
library(nifffty)# current verison
packageVersion("nifffty")maker("rtest", "this", "is a", "test")
```
To setup a receiver, create a script on a server that can receive requests from the internet (I named the following `listen.R`):
```{r usage2, eval=FALSE}
library(nifffty)do_it <- function(req) {
require(jsonlite)
print(fromJSON(names(req$POST())))
writeLines(names(req$POST()), "/tmp/bob.txt")
}# you can change the port to match what you put into IFTTT
rcvr <- receiver(port=10999, handler=do_it)
print(rcvr)
while (TRUE) Sys.sleep(24 * 60 * 60)
```For this example, I created an Apple Watch IFFFT "DO Button" to send my coordinates & timestamp when pressed:
![](do_button_r_nifffty.png)
Once that's setup, just call the script from the command-line:
bob@server:~$ Rscript listen.R
Loading required package: methods
Loading required package: Rook
Server started on 0.0.0.0:10999
[1] nifffty http://0.0.0.0:10999/custom/niffftyCall browse() with an index number or name to run an application.
Loading required package: jsonliteAttaching package: ‘jsonlite’
The following object is masked from ‘package:utils’:
View
When it receives an event it will print the following to the console:$latitude
[1] 43.25931$longitude
[1] -70.80062$timestamp
[1] "June 19, 2015 at 04:45PM"and, write the following to `/tmp/bob.txt`
bob@server:~$ cat /tmp/bob.txt
{ "latitude": 43.2593566552207, "longitude": -70.8004647307757, "timestamp": "June 19, 2015 at 04:46PM" }This same setup will work with any IFTTT action, not just "DO" buttons.
### Test Results
```{r test}
library(nifffty)
library(testthat)date()
test_dir("tests/")
```### Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).
By participating in this project you agree to abide by its terms.