You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. #!/usr/bin/env sh
  2. #Support for pushbullet.com's api. Push notification, notification sync and message platform for multiple platforms
  3. #PUSHBULLET_TOKEN="" Required, pushbullet application token
  4. #PUSHBULLET_DEVICE="" Optional, Specific device, ignore to send to all devices
  5. PUSHBULLET_URI="https://api.pushbullet.com/v2/pushes"
  6. pushbullet_send() {
  7. _subject="$1"
  8. _content="$2"
  9. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  10. _debug "_statusCode" "$_statusCode"
  11. PUSHBULLET_TOKEN="${PUSHBULLET_TOKEN:-$(_readaccountconf_mutable PUSHBULLET_TOKEN)}"
  12. if [ -z "$PUSHBULLET_TOKEN" ]; then
  13. PUSHBULLET_TOKEN=""
  14. _err "You didn't specify a Pushbullet application token yet."
  15. return 1
  16. fi
  17. _saveaccountconf_mutable PUSHBULLET_TOKEN "$PUSHBULLET_TOKEN"
  18. PUSHBULLET_DEVICE="${PUSHBULLET_DEVICE:-$(_readaccountconf_mutable PUSHBULLET_DEVICE)}"
  19. if [ -z "$PUSHBULLET_DEVICE" ]; then
  20. _saveaccountconf_mutable PUSHBULLET_TOKEN "$PUSHBULLET_TOKEN"
  21. fi
  22. export _H1="Content-Type: application/json"
  23. export _H2="Access-Token: ${PUSHBULLET_TOKEN}"
  24. _content="$(printf "*%s*\n" "$_content" | _json_encode)"
  25. _subject="$(printf "*%s*\n" "$_subject" | _json_encode)"
  26. _data="{\"type\": \"note\",\"title\": \"${_subject}\",\"body\": \"${_content}\",\"device_iden\": \"${PUSHBULLET_DEVICE}\"}"
  27. response="$(_post "$_data" "$PUSHBULLET_URI")"
  28. if [ "$?" != "0" ] || _contains "$response" "\"error_code\""; then
  29. _err "PUSHBULLET send error."
  30. _err "$response"
  31. return 1
  32. fi
  33. _info "PUSHBULLET send success."
  34. return 0
  35. }