PDA

View Full Version : Pushbullet anyone?



KRO74
February 1st, 2016, 06:29 AM
Hi,

Has anyone done any integration with pushbullet.com (http://www.pushbullet.com)?
If yes, possible to see an example of the Lua script?

If not,
What I would like to do in Lua looks like this in curl,

#!/bin/bash

API="YOURKEY"
MSG="$1"

curl -u $API: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="$MSG"

I have found the following Lua script at a different forum doing more or less what I want but it won't work in Girder6 most likely because of the SSL and HTTPS stuff.
Is there any way to modify the script to be able to use it in Girder6?


https = require("ssl.https")

local res = {}
local data = [[
{
"type": "link",
"title": "Link Note Title",
"body": "Note Body",
"url": "http://google.com/"
}
]]
local headers = {
["Authorization"] = "Basic ASDFASDFASDFASDFASDF",
["content-length"] = string.len(data),
["content-type"] = "application/json"
}
local url = { url = "https://api.pushbullet.com/v2/pushes",
protocol = "tlsv1",
method = "POST",
source = ltn12.source.string(data),
sink = ltn12.sink.table(res),
headers = headers }

local one, code, headers, status = https.request(url)

print("ONE:", one)
print("Code:", code)
for k,v in pairs(headers) do
print("Header", k, v)
end
print("Status:",status)

Using Girder6, 6.0.15.1, on a raspberry pi

Thanks in advance for any help.

Regards
Rickard

KRO74
August 26th, 2016, 07:25 AM
Found the answer, the following code will work, just replace with your access token (bold below),


local https = require("lsec.https")

local res = {}
local data = [[
{
"type": "link",
"title": "Girder",
"body": "Alice hemma"
}
]]
local headers = {
["Authorization"] = "Bearer abcdefghijkl",
["content-length"] = string.len(data),
["content-type"] = "application/json"
}
local url = { url = "https://api.pushbullet.com/v2/pushes",
protocol = "tlsv1",
method = "POST",
source = ltn12.source.string(data),
sink = ltn12.sink.table(res),
headers = headers }

local one, code, headers, status = https.request(url)

print("ONE:", one)
print("Code:", code)
for k,v in pairs(headers) do
print("Header", k, v)
end
print("Status:",status)