sn

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 14 Imported by: 2

README

snappy

stacker.news API client package for Go

How to use

$ go get github.com/ekzyis/snappy

SN_API_KEY must be set in your environment for authenticated API access.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithApiKey

func WithApiKey(apiKey string) func(*Client)

func WithBaseUrl

func WithBaseUrl(baseUrl string) func(*Client)

func WithMediaUrl added in v0.6.0

func WithMediaUrl(mediaUrl string) func(*Client)

Types

type Client

type Client struct {
	BaseUrl  string
	ApiUrl   string
	ApiKey   string
	MediaUrl string
}

func NewClient

func NewClient(options ...func(*Client)) *Client

func (*Client) CreateComment

func (c *Client) CreateComment(parentId int, text string) (int, error)

func (*Client) CreateInvoice added in v0.5.0

func (c *Client) CreateInvoice(args *CreateInvoiceArgs) (*Invoice, error)

func (*Client) Dupes

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

func (*Client) GetRssFeed

func (c *Client) GetRssFeed() (*Rss, error)

func (*Client) HasDupes

func (c *Client) HasDupes(url string) (bool, error)

func (*Client) Item added in v0.5.0

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

func (*Client) Items

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

func (*Client) Me added in v0.7.0

func (c *Client) Me() (*User, error)

func (*Client) Mentions added in v0.6.0

func (c *Client) Mentions() ([]Notification, error)

func (*Client) Notifications added in v0.6.0

func (c *Client) Notifications() (*NotificationsCursor, error)

func (*Client) PostDiscussion

func (c *Client) PostDiscussion(title string, text string, sub string) (int, error)
func (c *Client) PostLink(url string, title string, text string, sub string) (int, error)

func (*Client) Replies added in v0.6.0

func (c *Client) Replies() ([]Notification, error)

func (*Client) UploadImage added in v0.6.0

func (c *Client) UploadImage(img *image.RGBA) (string, error)

type Comment

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

type CreateInvoiceArgs added in v0.5.0

type CreateInvoiceArgs struct {
	Amount      int
	ExpireSecs  int
	HodlInvoice bool
}

type CreateInvoiceResponse added in v0.5.0

type CreateInvoiceResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		CreateInvoice Invoice `json:"createInvoice"`
	} `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 []GqlError `json:"errors"`
	Data   struct {
		Dupes []Dupe `json:"dupes"`
	} `json:"data"`
}

type GetSignedPOST added in v0.6.0

type GetSignedPOST struct {
	Url    string            `json:"url"`
	Fields map[string]string `json:"fields"`
}

type GetSignedPOSTResponse added in v0.6.0

type GetSignedPOSTResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		GetSignedPOST GetSignedPOST `json:"getSignedPOST"`
	} `json:"data"`
}

type GqlBody

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

type GqlError

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

type Invoice added in v0.5.0

type Invoice struct {
	Id                int                    `json:"id,string"`
	Hash              string                 `json:"hash"`
	Hmac              string                 `json:"hmac"`
	Bolt11            string                 `json:"bolt11"`
	SatsRequested     int                    `json:"satsRequested"`
	SatsReceived      int                    `json:"satsReceived"`
	Cancelled         bool                   `json:"cancelled"`
	ConfirmedAt       time.Time              `json:"createdAt"`
	ExpiresAt         time.Time              `json:"expiresAt"`
	Nostr             map[string]interface{} `json:"nostr"`
	IsHeld            bool                   `json:"isHeld"`
	Comment           string                 `json:"comment"`
	Lud18Data         map[string]interface{} `json:"lud18Data"`
	ConfirmedPreimage string                 `json:"confirmedPreimage"`
	ActionState       string                 `json:"actionState"`
	ActionType        string                 `json:"actionType"`
}

type Item

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

type ItemPaidAction added in v0.5.1

type ItemPaidAction struct {
	Result        Item          `json:"result"`
	Invoice       Invoice       `json:"invoice"`
	PaymentMethod PaymentMethod `json:"paymentMethod"`
}

type ItemResponse added in v0.5.0

type ItemResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		Item Item `json:"item"`
	} `json:"data"`
}

type ItemsCursor

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

type ItemsQuery

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 []GqlError `json:"errors"`
	Data   struct {
		Items ItemsCursor `json:"items"`
	} `json:"data"`
}

type MeResponse added in v0.7.0

type MeResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		Me User `json:"me"`
	} `json:"data"`
}

type Notification added in v0.6.0

type Notification struct {
	Id   int    `json:"id,string"`
	Type string `json:"__typename"`
	Item Item   `json:"item"`
}

type NotificationsCursor added in v0.6.0

type NotificationsCursor struct {
	LastChecked   time.Time      `json:"lastChecked"`
	Cursor        string         `json:"cursor"`
	Notifications []Notification `json:"notifications"`
}

type NotificationsResponse added in v0.6.0

type NotificationsResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		Notifications NotificationsCursor `json:"notifications"`
	} `json:"data"`
}

type PaymentMethod added in v0.5.1

type PaymentMethod string
const (
	PaymentMethodFeeCredits  PaymentMethod = "FEE_CREDIT"
	PaymentMethodOptimistic  PaymentMethod = "OPTIMISTIC"
	PaymentMethodPessimistic PaymentMethod = "PESSIMISTIC"
)

type Rss

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

type RssAuthor

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

type RssChannel

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

type RssDate struct {
	time.Time
}

func (*RssDate) UnmarshalXML

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

type RssItem

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 UpsertCommentResponse added in v0.5.2

type UpsertCommentResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		UpsertComment ItemPaidAction `json:"upsertComment"`
	} `json:"data"`
}

type UpsertDiscussionResponse

type UpsertDiscussionResponse struct {
	Errors []GqlError `json:"errors"`
	Data   struct {
		UpsertDiscussion ItemPaidAction `json:"upsertDiscussion"`
	} `json:"data"`
}

type UpsertLinkResponse

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

type User

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

type UserPrivates added in v0.7.0

type UserPrivates struct {
	Sats int `json:"sats"`
}

Jump to

Keyboard shortcuts

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