sn

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 10 Imported by: 0

README

sn-goapi

Package for stacker.news API access

Install via go get github.com/ekzyis/sn-goapi

Supports:

  • Post of type ...
    • ... Discussion
    • ... Link
    • ... Bounty
    • ... Poll
  • Reply (comments)
  • Tips
  • Checking dupes
  • Checking notifications

SN_AUTH_COOKIE must be set with a valid session cookie.

Documentation

Overview

Package for stacker.news API access

Index

Constants

This section is empty.

Variables

View Source
var (
	// stacker.news URL
	SnUrl = "https://stacker.news"
	// stacker.news API URL
	SnApiUrl = "https://stacker.news/api/graphql"
	// stacker.news session cookie
	SnAuthCookie string
)
View Source
var (
	StackerNewsRssFeedUrl = "https://stacker.news/rss"
)

Functions

func CheckForErrors

func CheckForErrors(graphqlErrors []GraphQLError) error

Returns error if any error was found

func CheckNotifications added in v0.1.1

func CheckNotifications() (bool, error)

Check for new notifications

func CreateComment

func CreateComment(parentId int, text string) (int, error)

Create a new comment

func Dupes

func Dupes(url string) (*[]Dupe, error)

Fetch dupes

func FormatLink(id int) string

Format item id as link

func MakeStackerNewsRequest

func MakeStackerNewsRequest(body GraphQLPayload) (*http.Response, error)

Make GraphQL request using raw payload

func PostLink(url string, title string, sub string) (int, error)

Create a new LINK post

func RefreshSession added in v0.2.0

func RefreshSession() error

Types

type Comment

type Comment struct {
	Id        int       `json:"id,string"`
	ParentId  int       `json:"parentId,string"`
	CreatedAt time.Time `json:"createdAt"`
	Text      string    `json:"text"`
	User      User      `json:"user"`
	Comments  []Comment `json:"comments"`
}

type CreateCommentsResponse

type CreateCommentsResponse struct {
	Errors []GraphQLError `json:"errors"`
	Data   struct {
		CreateComment Comment `json:"createComment"`
	} `json:"data"`
}

type Dupe

type Dupe struct {
	Id        int       `json:"id,string"`
	Url       string    `json:"url"`
	Title     string    `json:"title"`
	User      User      `json:"user"`
	CreatedAt time.Time `json:"createdAt"`
	Sats      int       `json:"sats"`
	NComments int       `json:"ncomments"`
}

type DupesError

type DupesError struct {
	Url   string
	Dupes []Dupe
}

func (*DupesError) Error

func (e *DupesError) Error() string

type DupesResponse

type DupesResponse struct {
	Errors []GraphQLError `json:"errors"`
	Data   struct {
		Dupes []Dupe `json:"dupes"`
	} `json:"data"`
}

type GraphQLError

type GraphQLError struct {
	Message string `json:"message"`
}

type GraphQLPayload

type GraphQLPayload struct {
	Query     string                 `json:"query"`
	Variables map[string]interface{} `json:"variables,omitempty"`
}

type HasNewNotesResponse

type HasNewNotesResponse struct {
	Errors []GraphQLError `json:"errors"`
	Data   struct {
		HasNewNotes bool `json:"hasNewNotes"`
	} `json:"data"`
}

type Item

type Item struct {
	Id        int       `json:"id,string"`
	ParentId  int       `json:"parentId,string"`
	Title     string    `json:"title"`
	Url       string    `json:"url"`
	Sats      int       `json:"sats"`
	CreatedAt time.Time `json:"createdAt"`
	Comments  []Comment `json:"comments"`
	NComments int       `json:"ncomments"`
	User      User      `json:"user"`
}

type ItemsCursor added in v0.3.0

type ItemsCursor struct {
	Items  []Item `json:"items"`
	Cursor string `json:"cursor"`
}

func Items added in v0.3.0

func Items(query *ItemsQuery) (*ItemsCursor, error)

type ItemsQuery added in v0.3.0

type ItemsQuery struct {
	Sub    string
	Sort   string
	Type   string
	Cursor string
	Name   string
	When   string
	By     string
	Limit  int
}

type ItemsResponse

type ItemsResponse struct {
	Errors []GraphQLError `json:"errors"`
	Data   struct {
		Items ItemsCursor `json:"items"`
	} `json:"data"`
}

type Rss added in v0.3.0

type Rss struct {
	Channel RssChannel `xml:"channel"`
}

func RssFeed added in v0.3.0

func RssFeed() (*Rss, error)

Fetch RSS feed

type RssAuthor added in v0.3.0

type RssAuthor struct {
	Name string `xml:"name"`
}

type RssChannel added in v0.3.0

type RssChannel struct {
	Title         string    `xml:"title"`
	Description   string    `xml:"description"`
	Link          string    `xml:"link"`
	Items         []RssItem `xml:"item"`
	LastBuildDate RssDate   `xml:"lastBuildDate"`
}

type RssDate added in v0.3.0

type RssDate struct {
	time.Time
}

func (*RssDate) UnmarshalXML added in v0.3.0

func (c *RssDate) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type RssItem added in v0.3.0

type RssItem struct {
	Guid        string    `xml:"guid"`
	Title       string    `xml:"title"`
	Link        string    `xml:"link"`
	Description string    `xml:"description"`
	PubDate     RssDate   `xml:"pubDate"`
	Author      RssAuthor `xml:"author"`
}

type UpsertLinkResponse

type UpsertLinkResponse struct {
	Errors []GraphQLError `json:"errors"`
	Data   struct {
		UpsertLink Item `json:"upsertLink"`
	} `json:"data"`
}

type User

type User struct {
	Id   int    `json:"id,string"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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