api

package
v0.0.0-...-83d7e21 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Job     ItemType = "job"
	Story            = "story"
	Comment          = "comment"
	Poll             = "poll"
	PollOpt          = "pollopt"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FrontPageItemsRanking

type FrontPageItemsRanking int
const (
	Top FrontPageItemsRanking = iota
	Best
	New
)

func (FrontPageItemsRanking) ToPointer

type HnClient

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

func MakeProdClient

func MakeProdClient() HnClient

func (*HnClient) FetchFrontPageItemIds

func (hn *HnClient) FetchFrontPageItemIds(ranking FrontPageItemsRanking, limit int) ([]ItemId, error)

func (*HnClient) FetchItem

func (hn *HnClient) FetchItem(id ItemId) (*Item, error)

func (*HnClient) FetchItems

func (hn *HnClient) FetchItems(ids []ItemId) ([]Item, error)

func (*HnClient) Search

func (hn *HnClient) Search(request SearchRequest) (*SearchResponse, error)

type HnClientBuilder

type HnClientBuilder interface {
	SetHnUrl(string) HnClientBuilder
	SetSearchPopularityUrl(string) HnClientBuilder
	SetSearchDateUrl(string) HnClientBuilder
	Build() HnClient
}

func NewHnClientBuilder

func NewHnClientBuilder() HnClientBuilder

type Item

type Item struct {
	// The item's unique id.
	Id ItemId `json:"id"`

	// `true` if the item is deleted.
	Deleted *bool `json:"deleted"`

	// The type of the item. One of "job", "story", "comment", "poll", or "pollopt".
	Type ItemType `json:"type"`

	// The username of the item's author.
	By *string `json:"by"`

	// Creation date of the item in Unix time.
	Time *int64 `json:"time"`

	// The comment, story, or poll text in HTML.
	Text *string `json:"text"`

	// `true` if the item is dead.
	Dead *bool `json:"dead"`

	// The comment's parent: either another comment or the relevant story.
	Parent *ItemId `json:"parent"`

	// The pollopt's associated poll.
	Poll *ItemId `json:"poll"`

	// The ids of the item's comments, in ranked display order.
	Kids []ItemId `json:"kids"`

	// The url of the story.
	Url *string `json:"url"`

	// The story's score, or the votes for a pollopt.
	Score *int32 `json:"score"`

	// The title of the story, poll, or job in HTML
	Title *string `json:"title"`

	// A list of related pollopts, in display order.
	Parts []ItemId `json:"parts"`

	// In the case of stories or polls, the total comment count.
	Descendants *int32 `json:"descendants"`
}

type ItemId

type ItemId = int32

type ItemType

type ItemType string

type SearchItemsRanking

type SearchItemsRanking int
const (
	Date SearchItemsRanking = iota
	Popularity
)

func (SearchItemsRanking) ToPointer

func (r SearchItemsRanking) ToPointer() *SearchItemsRanking

type SearchRequest

type SearchRequest struct {
	Query   string
	Tags    string
	Ranking SearchItemsRanking
	Limit   int
}

type SearchResponse

type SearchResponse struct {
	Results []SearchResult
}

type SearchResponseJson

type SearchResponseJson struct {
	Hits []SearchResultJson `json:"hits"`
}

type SearchResult

type SearchResult struct {
	Id                         ItemId
	HighlightResultCommentText string
}

type SearchResultJson

type SearchResultJson struct {
	Id              string `json:"objectID"`
	HighlightResult struct {
		CommentText struct {
			Value string `json:"value"`
		} `json:"comment_text"`
	} `json:"_highlightResult"`
}

Jump to

Keyboard shortcuts

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