tldrio

package module
v0.0.0-...-d3a0759 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2013 License: MIT Imports: 8 Imported by: 0

README

tldriogo

A Go library for the tldr.io API.

Build Status

Overview

tldriogo is a client library for the tl;dr API. It currently supports all 6 API calls.

Summary


var tldrio *TldrIo
tldrio = NewTldrIo()

categories, err := tldrio.Categories()
// &[{Name:Tech News Slug:tech-news} {Name:World News Slug:world-news} ...]

// Get the three latest World News TL;DRs 
latest, err := tldrio.Latest(3, "world-news")

// Search for a TL;DR for a particular URL
result, err := tldrio.Search("http://i.want.a.summary")

// Search for a bunch of TL;DRs
results, err := tldrio.SearchBatch("http://i.want.a.summary", "http://and.another")

// Get the scoop on a TL;DR user
user, err := tldrio.User("fredjonez")

// See all of fredjonez TL;DRs
results, err := tldrio.UserTldrs("fredjonez")

Docs

See the godoc at http://godoc.org/github.com/joshrotenberg/tldriogo and the API docs at http://tldr.io/api-documentation for more information.

Documentation

Overview

Package tldrio provides a simple wrapper around the tldr.io API.

Index

Examples

Constants

View Source
const (
	TldrApiUrl = "https://api.tldr.io"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Name string
	Slug string
}

type Creator

type Creator struct {
	Id                 string
	Username           string
	UsernameForDisplay string
	IsAdmin            bool
	Deleted            bool
	TwitterHandle      string
}

TL;DR creator information

type DistributionChannels

type DistributionChannels struct {
	LatestTldrs        bool
	LatestTldrsRSSFeed bool
}

TL;DR distribution channels

type Domain

type Domain struct {
	Name string
	Slug string
}

TL;DR Domain

type Gravatar

type Gravatar struct {
	Url string
}

type Language

type Language struct {
	Language   string
	Confidence float64
}

TL;DR language

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 NewTldrIo

func NewTldrIo() *TldrIo

NewTldrIo creates a new handle for making API calls.

func (*TldrIo) Categories

func (t *TldrIo) Categories() (*[]Category, error)

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

func (t *TldrIo) Latest(number int, category string) (*[]Tldr, error)

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

func (t *TldrIo) Search(u string) (*Tldr, error)

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

func (t *TldrIo) SearchBatch(urls ...string) (*[]Tldr, error)

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

func (t *TldrIo) User(user string) (*User, error)

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

func (t *TldrIo) UserTldrs(user string) (*[]UserTldr, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL