Skip to content

Commit

Permalink
Merge pull request #17 from jonocarroll/cran_release
Browse files Browse the repository at this point in the history
CRAN release
  • Loading branch information
jonocarroll authored Nov 6, 2024
2 parents 02a9bc5 + 04d15ac commit 125a3bf
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
^README\.Rmd$
^LICENSE\.md$
^data-raw$
^\.github$
^cran-comments\.md$
^CRAN-SUBMISSION$
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ntfy
Title: Lightweight Wrapper to the ntfy.sh Service
Version: 0.0.5
Title: Lightweight Wrapper to the 'ntfy.sh' Service
Version: 0.0.6
Authors@R:
c(person("Jonathan", "Carroll",
email = "[email protected]",
Expand All @@ -13,14 +13,15 @@ Authors@R:
comment = c(ORCID = "0000-0002-3948-3914"))
)
Maintainer: Jonathan Carroll <[email protected]>
Description: ntfy (pronounce: notify) is a simple HTTP-based pub-sub notification service.
It allows you to send notifications to your phone or desktop via scripts from
any computer, entirely without signup, cost or setup. It's also open source if
you want to run your own. Visit https://ntfy.sh for more details.
Description: The 'ntfy' (pronounce: notify) service is a simple HTTP-based pub-sub
notification service. It allows you to send notifications to your phone or
desktop via scripts from any computer, entirely without signup, cost or
setup. It's also open source if you want to run your own.
Visit <https://ntfy.sh> for more details.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
httr2,
jsonlite
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ntfy 0.0.6

* CRAN release - minor internal changes

# ntfy 0.0.5

* Refactored to use {httr2} with tests, simplified image sending, improved/fixed
Expand Down
6 changes: 6 additions & 0 deletions R/ntfy-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
23 changes: 23 additions & 0 deletions R/ntfy.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ get_image_path <- function(image) {
#' @param password password with access to a protected topic.
#'
#' @return a [httr2::response()] object
#'
#' @examplesIf interactive()
#' # send a message to the default topic ('mytopic')
#' ntfy_send("test from R!")
#'
#' # can use tags (emoji)
#' ntfy_send(message = "sending with tags!",
#' tags = c(tags$cat, tags$dog)
#' )
#'
#' @export
ntfy_send <- function(message = "test",
title = NULL,
Expand Down Expand Up @@ -106,6 +116,10 @@ ntfy_send <- function(message = "test",
#'
#' @seealso \url{https://ntfy.sh/docs/subscribe/api/#json-message-format}
#'
#' @examplesIf interactive()
#' # get the last hour of notifications
#' ntfy_history(since = "1h")
#'
#' @export
ntfy_history <- function(since = "all",
topic = ntfy_topic(),
Expand Down Expand Up @@ -156,6 +170,11 @@ ntfy_history <- function(since = "all",
#' @param ... other arguments passed to [ntfy::ntfy_send()]
#'
#' @return the input x (for further piping) plus a notification will be sent
#'
#' @examplesIf interactive()
#' # report that a process has completed
#' Sys.sleep(3) |> ntfy_done("Woke up")
#'
#' @export
ntfy_done <- function(x,
message = paste0("Process completed at ", Sys.time()),
Expand Down Expand Up @@ -183,6 +202,10 @@ ntfy_done <- function(x,
#'
#' @return the result of evaluating x (for further piping) plus a notification will be sent
#'
#' @examplesIf interactive()
#' # report that a process has completed, and how long it took
#' Sys.sleep(3) |> ntfy_done_with_timing()
#'
#' @export
ntfy_done_with_timing <- function(x,
message = paste0("Process completed in ", time_result, "s"),
Expand Down
7 changes: 6 additions & 1 deletion R/tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@
#' name is not found in `aliases`.
#'
#' @return nothing, just prints the emoji if one or more are found
#'
#' @examples
#' show_emoji("dog")
#' show_emoji("party")
#'
#' @export
show_emoji <- function(name = NULL, search = FALSE) {
if (is.null(name)) stop("`name` must be provided")

data("emoji")
emoji <- ntfy::emoji
if (!name %in% emoji$aliases) {
message("Unable to find that name directly.")
search <- TRUE
Expand Down
8 changes: 4 additions & 4 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.onLoad <- function(libname, pkgname) {
.onAttach <- function(libname, pkgname) {
if (Sys.getenv("NTFY_SERVER") == "") {
Sys.setenv(NTFY_SERVER = "https://ntfy.sh")
}

if (Sys.getenv("NTFY_TOPIC") == "") {
message("Topic not yet set - using a demo topic 'mytopic'")
message("Set one with usethis::edit_r_environ()")
message(" and set NTFY_TOPIC='<yourSecretTopic>'")
packageStartupMessage("{ntfy}: Topic not yet set - using a demo topic 'mytopic'\n",
" Set one with usethis::edit_r_environ()\n",
" and set NTFY_TOPIC='<yourSecretTopic>'")
Sys.setenv(NTFY_TOPIC = "mytopic")
}

Expand Down
24 changes: 19 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ but made to work nicely in an R workflow.

## Installation

You can install the development version of ntfy like so:
You can install the released version of {ntfy} from CRAN

``` r
```r
install.packages("ntfy")
```

You can install the development version of {ntfy} from GitHub:

```r
# install.packages("remotes")
remotes::install_github("jonocarroll/ntfy")
```
Expand Down Expand Up @@ -154,6 +160,12 @@ sends
Process completed in 8.004s
```

This service can also be used as a progress indicator via the
[{progressr}][progressr] package - see
`help("handler_ntfy", package = "progressr")` or
https://progressr.futureverse.org/reference/handler_ntfy.html for more
details.

If you're using a topic on a server that requires authentication, you can pass `auth = TRUE`, along with a username and password:

```r
Expand Down Expand Up @@ -182,7 +194,8 @@ NTFY_PASSWORD='super-secret-password'
ntfy_send("test from R!")
```

The history of the notifications sent can be retrieved as well, with control over how far back to search
The history of the notifications sent can be retrieved as well, with control
over how far back to search (example output shown)

```{r history, eval = FALSE}
ntfy_history(since = "1h")
Expand Down Expand Up @@ -281,11 +294,12 @@ If this package is useful to you, [I also accept donations][jonocarroll_sp] via

[ntfy]:https://ntfy.sh
[ntfy_gh]:https://github.com/binwiederhier/ntfy
[rpushbullet]:https://cran.r-project.org/web/packages/RPushbullet/index.html
[beepr]:https://cran.r-project.org/web/packages/beepr/index.html
[rpushbullet]:https://cran.r-project.org/package=RPushbullet
[beepr]:https://cran.r-project.org/package=beepr
[ifttt]:https://ifttt.com/docs/connect_api
[rviews]:https://rviews.rstudio.com/2020/06/18/how-to-have-r-notify-you/
[nifffty]:https://github.com/hrbrmstr/nifffty
[privacy]:https://ntfy.sh/docs/faq/#will-you-know-what-topics-exist-can-you-spy-on-me
[ntfy_dev_sp]:https://github.com/sponsors/binwiederhier
[progressr]:https://github.com/futureverse/progressr
[jonocarroll_sp]:https://github.com/sponsors/jonocarroll
99 changes: 58 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ntfy <img src="man/figures/logo.png" align="right" height="102" />

<!-- badges: start -->

<!-- badges: end -->

**ntfy** (pronounce: *notify*) is a simple HTTP-based pub-sub
Expand All @@ -22,7 +23,13 @@ but made to work nicely in an R workflow.

## Installation

You can install the development version of ntfy like so:
You can install the released version of {ntfy} from CRAN

``` r
install.packages("ntfy")
```

You can install the development version of {ntfy} from GitHub:

``` r
# install.packages("remotes")
Expand Down Expand Up @@ -64,12 +71,11 @@ appear on your device
``` r
library(ntfy)
ntfy_send("test from R!")
#> Response [https://ntfy.sh/]
#> Date: 2023-07-11 03:57
#> Status: 200
#> Content-Type: application/json
#> Size: 136 B
#> {"id":"cyyxyTbqnyc7","time":1689047847,"expires":1689091047,"event":"message"...
#> <httr2_response>
#> POST https://ntfy.sh/jonocarroll_ntfy_testing
#> Status: 200 OK
#> Content-Type: application/json
#> Body: In memory (152 bytes)
```

This can be used in many ways. One would be to notify the completion of
Expand Down Expand Up @@ -140,7 +146,6 @@ an entire pipeline with `ntfy_done_with_timing()` will work, though

``` r
library(magrittr)
#> Warning: package 'magrittr' was built under R version 4.2.0
ntfy_done_with_timing(
mtcars %>%
head() %>%
Expand All @@ -159,10 +164,16 @@ sends

Process completed in 8.004s

If you're using a topic on a server that requires authentication, you can pass
`auth = TRUE`, along with a username and password:
This service can also be used as a progress indicator via the
[{progressr}](https://github.com/futureverse/progressr) package - see
`help("handler_ntfy", package = "progressr")` or
<https://progressr.futureverse.org/reference/handler_ntfy.html> for more
details.

If you’re using a topic on a server that requires authentication, you
can pass `auth = TRUE`, along with a username and password:

```r
``` r
ntfy_send(
"test from R!",
auth = TRUE,
Expand All @@ -171,10 +182,10 @@ ntfy_send(
)
```

Alternatively, you can set these as environment variables and they'll get used
by `ntfy_send()` automatically:
Alternatively, you can set these as environment variables and they’ll
get used by `ntfy_send()` automatically:

```r
``` r
usethis::edit_r_environ()

[...]
Expand All @@ -184,12 +195,12 @@ NTFY_USERNAME='example'
NTFY_PASSWORD='super-secret-password'
```

```r
``` r
ntfy_send("test from R!")
```

The history of the notifications sent can be retrieved as well, with
control over how far back to search
control over how far back to search (example output shown)

``` r
ntfy_history(since = "1h")
Expand Down Expand Up @@ -221,6 +232,11 @@ file)

``` r
library(ggplot2)
#>
#> Attaching package: 'ggplot2'
#> The following object is masked from 'package:base':
#>
#> is.element
p <- ggplot(mtcars, (aes(mpg, wt))) +
geom_point() +
geom_smooth() +
Expand All @@ -230,12 +246,15 @@ ntfy_send("ggplot2 images in notifications!",
image = p)
#> Saving 7 x 5 in image
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Response [https://ntfy.sh/jonotest]
#> Date: 2023-07-11 03:57
#> Status: 200
#> Content-Type: application/json
#> Size: 319 B
#> {"id":"ML466fCn29AD","time":1689047875,"expires":1689091075,"event":"message"...
#> <httr2_response>
#>
#> POST https://ntfy.sh/jonocarroll_ntfy_testing
#>
#> Status: 200 OK
#>
#> Content-Type: application/json
#>
#> Body: In memory (335 bytes)
```

## Emoji
Expand All @@ -251,15 +270,14 @@ The compatible data is stored as `emoji`
data("emoji")
head(emoji)
#> # A tibble: 6 × 6
#> emoji aliases tags category description unicode_ve…¹
#> <chr> <chr> <list> <chr> <chr> <chr>
#> 1 👎 -1 <chr [2]> People & Body thumbs down 6.0
#> 2 👍 +1 <chr [2]> People & Body thumbs up 6.0
#> 3 💯 100 <chr [2]> Smileys & Emotion hundred points 6.0
#> 4 🔢 1234 <chr [1]> Symbols input numbers 6.0
#> 5 🥇 1st_place_medal <chr [1]> Activities 1st place medal 9.0
#> 6 🥈 2nd_place_medal <chr [1]> Activities 2nd place medal 9.0
#> # … with abbreviated variable name ¹​unicode_version
#> emoji aliases tags category description unicode_version
#> <chr> <chr> <list> <chr> <chr> <chr>
#> 1 👎 -1 <chr [2]> People & Body thumbs down 6.0
#> 2 👍 +1 <chr [2]> People & Body thumbs up 6.0
#> 3 💯 100 <chr [2]> Smileys & Emotion hundred poi… 6.0
#> 4 🔢 1234 <chr [1]> Symbols input numbe… 6.0
#> 5 🥇 1st_place_medal <chr [1]> Activities 1st place m… 9.0
#> 6 🥈 2nd_place_medal <chr [1]> Activities 2nd place m… 9.0
```

with the tags stored as `tags` for easy auto-complete
Expand All @@ -268,12 +286,11 @@ with the tags stored as `tags` for easy auto-complete
ntfy_send(message = "sending with tags!",
tags = c(tags$cat, tags$dog)
)
#> Response [https://ntfy.sh/]
#> Date: 2023-07-11 03:57
#> Status: 200
#> Content-Type: application/json
#> Size: 163 B
#> {"id":"ifkGMIb0l9aU","time":1689047876,"expires":1689091076,"event":"message"...
#> <httr2_response>
#> POST https://ntfy.sh/jonocarroll_ntfy_testing
#> Status: 200 OK
#> Content-Type: application/json
#> Body: In memory (179 bytes)
```

The compatible emoji can be shown with
Expand Down Expand Up @@ -321,10 +338,10 @@ show_emoji("dog", search = TRUE)

## Similar Services

- [{Rpushbullet}](https://cran.r-project.org/web/packages/RPushbullet/index.html)
offers similar functionality, but requires sign-up / an API key
- [{beepr}](https://cran.r-project.org/web/packages/beepr/index.html)
can play a sound when a process completes
- [{Rpushbullet}](https://cran.r-project.org/package=RPushbullet) offers
similar functionality, but requires sign-up / an API key
- [{beepr}](https://cran.r-project.org/package=beepr) can play a sound
when a process completes
- [IFTTT](https://ifttt.com/docs/connect_api) has an API and can be
configured to send messages with
e.g. [nifffty](https://github.com/hrbrmstr/nifffty)
Expand Down
12 changes: 12 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## R CMD check results

0 errors | 0 warnings | 1 note*

* This is a new release.

Tested locally and on win-devel, win-release.

Flagged 'The Title field should be in title case' but
recommends Ntfy.sh over ntfy.sh which is a false-positive.

Added examples and resubmitting.
Loading

0 comments on commit 125a3bf

Please sign in to comment.