Documentation
¶
Overview ¶
Package api pulls 4chan board and thread data from the JSON API into native Go data structures.
Index ¶
- Constants
- Variables
- func GetThreads(board string) ([][]int64, error)
- type Board
- type Catalog
- type File
- type Post
- type Thread
- func (self *Thread) BumpLimit() bool
- func (self *Thread) Closed() bool
- func (self *Thread) CustomSpoiler() int
- func (self *Thread) CustomSpoilerURL(id int, ssl bool) string
- func (self *Thread) Id() int64
- func (self *Thread) ImageLimit() bool
- func (self *Thread) Images() int
- func (self *Thread) OmittedImages() int
- func (self *Thread) OmittedPosts() int
- func (self *Thread) Replies() int
- func (self *Thread) Sticky() bool
- func (self *Thread) String() (s string)
- func (self *Thread) Update() (new_posts, deleted_posts int, err error)
Examples ¶
Constants ¶
const ( APIURL = "a.4cdn.org" ImageURL = "i.4cdn.org" StaticURL = "s.4cdn.org" )
Variables ¶
var ( // Whether or not to use HTTPS for requests. SSL bool = false // Cooldown time for updating threads using (*Thread).Update(). // If it is set to less than 10 seconds, it will be re-set to 10 seconds // before being used. UpdateCooldown time.Duration = 15 * time.Second )
var Boards []Board
Board names/descriptions will be cached here after a call to LookupBoard or GetBoards
Functions ¶
func GetThreads ¶
GetThreads hits the API for a list of the thread IDs of all the active threads on a given board.
Types ¶
type Board ¶
A Board is the name and title of a single board.
func LookupBoard ¶
LookupBoard returns the Board corresponding to the board name (without slashes)
type Catalog ¶
A Catalog contains a list of (truncated) threads on each page of a board.
func GetCatalog ¶
GetCatalog hits the API for a catalog listing of a board.
type File ¶
type File struct { Id int64 // Id is what 4chan renames images to (UNIX + microtime, e.g. 1346971121077) Name string // Original filename Ext string Size int MD5 []byte Width int Height int ThumbWidth int ThumbHeight int Deleted bool Spoiler bool }
A File represents an uploaded file's metadata.
type Post ¶
type Post struct { // Post info Id int64 Thread *Thread Time time.Time Subject string LastModified int64 // Poster info Name string Trip string Email string Special string Capcode string // Country and CountryName are empty unless the board uses country info Country string CountryName string // Message body Comment string // File info if any, otherwise nil File *File // only when they do this on /q/ CapcodeReplies map[string][]int // contains filtered or unexported fields }
A Post represents all of the attributes of a 4chan post, organized in a more directly usable fashion.
func (*Post) CountryFlagURL ¶
CountryFlagURL returns the URL of the post's country flag icon, if enabled on the board in question.
type Thread ¶
type Thread struct { Posts []*Post OP *Post Board string // without slashes ex. "g" or "ic" // contains filtered or unexported fields }
A Thread represents a thread of posts. It may or may not contain the actual replies.
Example ¶
thread, err := GetThread("a", 77777777) if err != nil { panic(err) } // will block until the cooldown is reached thread.Update() fmt.Println(thread)
Output:
func GetIndex ¶
GetIndex hits the API for an index of thread stubs from the given board and page.
Example ¶
threads, err := GetIndex("a", 0) if err != nil { panic(err) } for _, thread := range threads { fmt.Println(thread) }
Output:
func GetThread ¶
GetThread hits the API for a single thread and all its replies. board is just the board name, without the surrounding slashes. If a thread is being updated, use an existing thread's Update() method if possible because that uses If-Modified-Since in the request, which reduces unnecessary server load.
func ParseIndex ¶
ParseIndex converts a JSON response for multiple threads into a native Go data structure
func ParseThread ¶
ParseThread converts a JSON response for one thread into a native Go data structure.
func (*Thread) BumpLimit ¶
BumpLimit returns true if the thread is at its bump limit, or false otherwise.
func (*Thread) Closed ¶
Closed returns true if the thread is closed for replies, or false otherwise.
func (*Thread) CustomSpoiler ¶
CustomSpoiler returns the ID of its custom spoiler image, if there is one.
func (*Thread) CustomSpoilerURL ¶
CustomSpoilerURL builds and returns the URL of the custom spoiler image, or an empty string if none exists.
func (*Thread) ImageLimit ¶
ImageLimit returns true if the thread can no longer accept image posts, or false otherwise.
func (*Thread) OmittedImages ¶
OmittedImages returns the number of image posts omitted in a thread list overview.
func (*Thread) OmittedPosts ¶
OmittedPosts returns the number of posts omitted in a thread list overview.