hnapi

package
v0.0.0-...-e098d3e Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxItem

func MaxItem(ctx context.Context) (int64, error)

MaxItem returns the current max item number on hn.

Types

type Item

type Item struct {
	// Fields we care about in https-bot
	ID      int64  `json:"id"`
	By      string `json:"by"`
	Text    string `json:"text,omitempty"`
	URL     string `json:"url,omitempty"`
	Deleted bool   `json:"deleted,omitempty"`
	Dead    bool   `json:"dead,omitempty"`

	// Fields we don't care about in https-bot
	Type        string          `json:"type"`
	Time        TimestampSecond `json:"time"`
	Parent      int64           `json:"parent,omitempty"`
	Poll        int64           `json:"poll,omitempty"`
	Kids        []int64         `json:"kids,omitempty"`
	Score       int64           `json:"score,omitempty"`
	Title       string          `json:"title,omitempty"`
	Parts       []int64         `json:"parts,omitempty"`
	Descendants int64           `json:"descendants,omitempty"`
}

Item defines a firebase hacker news API item's json format.

Ref: https://github.com/HackerNews/API/blob/master/README.md#items.

func GetItem

func GetItem(ctx context.Context, id int64) (*Item, error)

GetItem gets an item from hn by its id.

func (*Item) URLs

func (i *Item) URLs() []string

URLs returns all the urls from this item.

This could include the URL field, and the URLs in Text field.

type Session

type Session struct {
	// contains filtered or unexported fields
}

A Session is a logged in hn session that's able to reply.

func NewSession

func NewSession(ctx context.Context, Username, Password string) (*Session, error)

NewSession logs in.

func (*Session) Reply

func (s *Session) Reply(ctx context.Context, id int64, content string) error

Reply sends a reply to the given id.

type TimestampSecond

type TimestampSecond time.Time

TimestampSecond implements json encoding/decoding using seconds since EPOCH.

func (TimestampSecond) MarshalJSON

func (ts TimestampSecond) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (TimestampSecond) String

func (ts TimestampSecond) String() string

func (TimestampSecond) ToTime

func (ts TimestampSecond) ToTime() time.Time

ToTime converts TimestampSecond back to time.Time.

func (*TimestampSecond) UnmarshalJSON

func (ts *TimestampSecond) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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