This is a Go package for accessing TinySRC API.
Free Tiny URL Shortener Service with a detailed statistic and extended features.
To get started working with TinySRC GO SDK, you need register and get your personal API Key first.
go get github.com/dmitrypro77/tinysrc-api-sdk
var err models.ErrorResponse
client, e := tinysrc.NewClient(context.Background(), "apiKey", http.DefaultClient)
if e != nil {
panic(e.Error())
}
user, err := client.GetCurrentUser()
if len(err.Errors) > 0 {
panic(err)
}
fmt.Println(user.Username)
fmt.Println(user.Email)
fmt.Println(user.ApiKey)
// etc ...
linkRequest := models.LinkRequest{
Url: "http://test.com",
AuthRequired: 0, // if auth required
Password: "", // optional if access to link by password needed
ExpirationTime: "", // optional time.Now().Format(tinysrc.DATE_FORMAT)
}
link, err := client.CreateShortLink(linkRequest)
if len(err.Errors) > 0 {
// You Can access to validation messages like this
fmt.Println(err.Validations)
panic(err)
}
fmt.Print(link.Url)
fmt.Print(link.StatUrl)
fmt.Print(link.StatPassword)
// etc ...
request := models.ListUrlsRequest{
Limit: 10,
Page: 1,
Query: "", // optional if you need search by hash for example
}
urls, err := client.GetListUrls(request)
if len(err.Errors) > 0 {
panic(err)
}
// Total Urls
fmt.Println(urls.Total)
for _, url := range urls.Data {
fmt.Println(url.Url)
//fmt.Println(url.Clicks)
//fmt.Println(url.Bots)
//fmt.Println(url.QRCode)
// etc ...
}
url, err := client.GetUrlByHash("test")
if len(err.Errors) > 0 {
panic(err)
}
fmt.Println(url.Url)
fmt.Println(url.Bots)
fmt.Println(url.Clicks)
// etc...
status, err := client.SetActive("test", &models.LinkActivationRequest{Active: false})
if len(err.Errors) > 0 {
panic(err)
}
fmt.Println(status)
stat, err := client.GetStatByHash("test", models.StatRequest{
Limit: 10,
Page: 1,
DateStart: time.Date(2015, 1,1,1,1,1,1, time.UTC),
DateEnd: time.Now(),
})
if len(err.Errors) > 0 {
panic(err)
}
// Total Records
fmt.Println(stat.Total)
for _, s := range stat.Data {
fmt.Println(s.Ip)
fmt.Println(s.Bot)
fmt.Println(s.Mobile)
fmt.Println(s.Browser)
fmt.Println(s.Os)
fmt.Println(s.Platform)
fmt.Println(s.Created)
// etc...
}
go test --cover
Please note that this package still is in development.
Pull requests are welcome.
[MIT]