Documentation ¶
Overview ¶
Package tldrio provides a simple wrapper around the tldr.io API.
Index ¶
- Constants
- type Category
- type Creator
- type DistributionChannels
- type Domain
- type Gravatar
- type Language
- type Tldr
- type TldrIo
- func (t *TldrIo) Categories() (*[]Category, error)
- func (t *TldrIo) Latest(number int, category string) (*[]Tldr, error)
- func (t *TldrIo) Search(u string) (*Tldr, error)
- func (t *TldrIo) SearchBatch(urls ...string) (*[]Tldr, error)
- func (t *TldrIo) User(user string) (*User, error)
- func (t *TldrIo) UserTldrs(user string) (*[]UserTldr, error)
- type User
- type UserTldr
Examples ¶
Constants ¶
const (
TldrApiUrl = "https://api.tldr.io"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Creator ¶
type Creator struct { Id string Username string UsernameForDisplay string IsAdmin bool Deleted bool TwitterHandle string }
TL;DR creator information
type DistributionChannels ¶
TL;DR distribution channels
type Tldr ¶
type Tldr struct { Title string Slug string Permalink string SummaryBullets []string ReadCount int OriginalUrl string PossibleUrls []string Creator Creator ImageUrl string CreatedAt time.Time UpdatedAt time.Time Moderated bool DistributionChannels DistributionChannels Anonymous bool WordCount int ArticleWordCount int TimeSaved string Language Language Domain Domain Categories []Category Editors []Creator ThankedBy []string }
Struct reprsentation of a single TL;DR
type TldrIo ¶
type TldrIo struct {
// contains filtered or unexported fields
}
func (*TldrIo) Categories ¶
Categories returns a slice of TL;DR categories.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() categories, err := tldrio.Categories() if err != nil { fmt.Println("couldn't fetch the tl;dr category list") } else { fmt.Printf("tl;dr has a bunch of categories: %t\n", len(*categories) > 2) }
Output: tl;dr has a bunch of categories: true
func (*TldrIo) Latest ¶
Latest gets the latest TL;DRs.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() latest, err := tldrio.Latest(3, "world-news") if err != nil { fmt.Printf("couldn't get the three latest World News tl;drs: %s\n", err) } else { fmt.Printf("got three of the latest World News tl;drs: %t\n", len(*latest) == 3) }
Output: got three of the latest World News tl;drs: true
func (*TldrIo) Search ¶
Search for a TL;DR by URL.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() result, err := tldrio.Search("http://jsonapi.org") if err != nil { fmt.Println("search didn't return any results") } else { fmt.Printf("search returned a tl;dr with the title '%s'\n", result.Title) }
Output: search returned a tl;dr with the title 'JSON API'
func (*TldrIo) SearchBatch ¶
SearchBatch searches for multiple TL;DRs.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() results, err := tldrio.SearchBatch("http://42floors.com/blog/yc-without-being-in-yc", "http://jsonapi.org") if err != nil { fmt.Println("search batch didn't return any results") } else { fmt.Printf("search batch found 2 results: %t\n", len(*results) == 2) }
Output: search batch found 2 results: true
func (*TldrIo) User ¶
User gets public data about the given user.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() username := "Louis" user, err := tldrio.User(username) if err != nil { fmt.Printf("user %s doesn't exist\n", username) } else { fmt.Printf("%s was created at %s\n", user.Username, user.CreatedAt) }
Output: Louis was created at 2012-09-05 08:39:24 +0000 UTC
func (*TldrIo) UserTldrs ¶
UserTldrs gets the TL;DRs created by the given user.
Example ¶
var tldrio *TldrIo tldrio = NewTldrIo() username := "Louis" tldrs, err := tldrio.UserTldrs(username) if err != nil { fmt.Printf("user %s doesn't exist\n", username) } else { fmt.Printf("user %s has more than one tldr: %t\n", username, len(*tldrs) > 1) }
Output: user Louis has more than one tldr: true
type User ¶
type User struct { Username string TwitterHandle string Bio string Gravatar Gravatar CreatedAt time.Time LastActive time.Time }
User contains information about a TL;DR user.
type UserTldr ¶
type UserTldr struct { Title string Slug string Permalink string SummaryBullets []string ReadCount int OriginalUrl string PossibleUrls []string Creator string ImageUrl string CreatedAt time.Time UpdatedAt time.Time Moderated bool DistributionChannels DistributionChannels Anonymous bool WordCount int ArticleWordCount int TimeSaved string Language Language Domain Domain Categories []Category Editors []string ThankedBy []string }
Struct reprsentation of a single TL;DR Note that this data structure is almost identical to Tldr but because of a small inconsistency in the API, Creators in the /users/<username>/tldrsCreated call are just a string ID rather than an object.