hn

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

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 11 Imported by: 0

README

hn

Go Reference

Package hn provides a client wrapping requests to the hackernews firebase API.

Installation

go get github.com/pkuca/hn

Basic Usage

client := hn.NewClient(nil)
topStories, _ := client.TopStories()

Custom Client

httpClient := &http.Client{
    Timeout: time.Second * 20,
}

hnClient := hn.NewClient(httpClient)
topStories, _ := hnClient.TopStories()

Documentation

Overview

Package hn provides an HTTP client with methods mapped to https://github.com/HackerNews/API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL url.URL
	// contains filtered or unexported fields
}

Client represents the "HN Client" - it's just an http client with a base URL. Methods are mapped to the hackernews firebase API described here: https://github.com/HackerNews/API

func NewClient

func NewClient(c *http.Client) *Client

NewClient creates an "HN Client". Its methods wrap requests to firebase json API endpoints. If an *http.Client is not provided, an *http.DefaultClient is used.

func (Client) AskStories

func (c Client) AskStories() ([]int, error)

func (Client) BestStories

func (c Client) BestStories() ([]int, error)

func (Client) Item

func (c Client) Item(id int) (*Item, error)

func (Client) JobStories

func (c Client) JobStories() ([]int, error)

func (Client) MaxItem

func (c Client) MaxItem() (int, error)

func (Client) NewStories

func (c Client) NewStories() ([]int, error)

func (Client) ShowStories

func (c Client) ShowStories() ([]int, error)

func (Client) TopStories

func (c Client) TopStories() ([]int, error)

func (Client) Updates

func (c Client) Updates() (*Updates, error)

func (Client) User

func (c Client) User(id string) (*User, error)

type Item

type Item struct {
	ID          int
	Type        string
	By          string
	Time        time.Time
	Text        string
	Parent      int
	Poll        int
	Kids        []int
	URL         *url.URL
	Score       int
	Title       string
	Parts       []int
	Descendants int
	Deleted     bool
	Dead        bool
}

Item is based on https://github.com/HackerNews/API#items

func (*Item) UnmarshalJSON

func (i *Item) UnmarshalJSON(b []byte) error

type Updates

type Updates struct {
	Items    []int    `json:"items"`
	Profiles []string `json:"profiles"`
}

Updates is based on the response example here: https://github.com/HackerNews/API#changed-items-and-profiles

type User

type User struct {
	ID        string    `json:"id"`
	Delay     int       `json:"delay"`
	Created   time.Time `json:"created"`
	Karma     int       `json:"karma"`
	About     string    `json:"about"`
	Submitted []int     `json:"submitted"`
}

User is based on https://github.com/HackerNews/API#users

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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