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.

44 lines
1.6 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. _clearaccountconf_mutable PUSHBULLET_DEVICE
  21. else
  22. _saveaccountconf_mutable PUSHBULLET_DEVICE "$PUSHBULLET_DEVICE"
  23. fi
  24. export _H1="Content-Type: application/json"
  25. export _H2="Access-Token: ${PUSHBULLET_TOKEN}"
  26. _content="$(printf "*%s*\n" "$_content" | _json_encode)"
  27. _subject="$(printf "*%s*\n" "$_subject" | _json_encode)"
  28. _data="{\"type\": \"note\",\"title\": \"${_subject}\",\"body\": \"${_content}\",\"device_iden\": \"${PUSHBULLET_DEVICE}\"}"
  29. response="$(_post "$_data" "$PUSHBULLET_URI")"
  30. if [ "$?" != "0" ] || _contains "$response" "\"error_code\""; then
  31. _err "PUSHBULLET send error."
  32. _err "$response"
  33. return 1
  34. fi
  35. _info "PUSHBULLET send success."
  36. return 0
  37. }