Go-dweetio is a simple Go client for dweet.io API
$ go get github.com/vitorleal/go-dweetio
API Support Dweet.io API
- Get last dweet for a thing
- Get last dweet for a LOCKED thing
- Get all dweets for a thing
- Get all dweets for a LOCKED thing
- Post new data for a thing
- Post new data for a LOCKED thing
- Set alert for a LOCKED thing
- Get alert for a LOCKED thing
- Remove alert for a LOCKED thing
- TODO: Real-time Streams for a thing
GET last dweet for a thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{}
res, err := api.GetLastDweetFor("godweetio") //Change this value with the name of your thing
if err != nil {
t.Error("Error in the GetLastDweetFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
GET last dweet for a LOCKED thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myPrivateLockKey"}
res, err := api.GetLastDweetFor("godweetio") //Change this value with the name of your thing
if err != nil {
t.Error("Error in the GetLastDweetFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
GET all dweet for a thing - limited to 500 in the Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{}
res, err := api.GetDweetsFor("godweetio") //Change this value with the name of your thing
if err != nil {
t.Error("Error in the GetDweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
GET all dweet for a LOCKED thing - limited to 500 in the Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myPrivateLockKey"}
res, err := api.GetDweetsFor("godweetio") //Change this value with the name of your thing
if err != nil {
t.Error("Error in the GetDweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
POST a new data for a thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{}
res, err := api.DweetFor("godweetio", "{ \"lorem\": \"ipsum\" }")
if err != nil {
t.Error("Error in the DweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
POST a new data for a LOCKED thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myPrivateLockKey"}
res, err := api.DweetFor("godweetio", "{ \"lorem\": \"ipsum\" }")
if err != nil {
t.Error("Error in the DweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
Set alert for a LOCKED thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myLockKey"}
//First parmeter thing (name of your thing)
//Second parmeter recipients (a list of strings)
//Third parmeter condition (A simple javascript expression to evaluate the data in a dweet and to return whether or not an alert should be sent)
res, err := api.SetAlertFor("godweetio", []string{"test@godweetio.com"}, "if(dweet.alertValue > 10) return 'TEST: Greater than 10'; if(dweet.alertValue < 10) return 'TEST: Less than 10';")
if err != nil {
t.Error("Error in the DweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
Get alert for a LOCKED thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myLockKey"}
res, err := api.GetAlertFor("godweetio")
if err != nil {
t.Error("Error in the GetAlertFor")
fmt.Println(err)
}
fmt.Println(res)
}
Remove alert for a LOCKED thing Dweet.io API
import (
"fmt"
"github.com/vitorleal/go-dweetio"
)
func main() {
api := Dweetio{Key: "myLockKey"}
res, err := api.RemoveAlertFor("godweetio")
if err != nil {
t.Error("Error in the DweetsFor")
fmt.Println(err.Error())
}
fmt.Println(res)
}
Vitor Leal |