Compare commits
No commits in common. "develop" and "v0.8.1" have entirely different histories.
@ -1,11 +1,14 @@
|
|||||||
# snappy
|
# snappy
|
||||||
|
|
||||||
<p align="center">
|
<div style="text-align: center">
|
||||||
|
|
||||||
<img src="https://stacker.news/favicon.png" width="64" height="64" />
|
<img src="https://stacker.news/favicon.png" width="64" height="64" />
|
||||||
<img src="https://go.dev/blog/go-brand/Go-Logo/PNG/Go-Logo_Blue.png" width="64" height="64" />
|
<img src="https://go.dev/blog/go-brand/Go-Logo/PNG/Go-Logo_Blue.png" width="64" height="64" />
|
||||||
</p>
|
|
||||||
|
|
||||||
<p align="center">A Go client for the <a href="https://stacker.news" target="_blank">Stacker News</a> GraphQL API</p>
|
[stacker.news](https://stacker.news) API client package for Go
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
|
|||||||
19
client.go
19
client.go
@ -107,22 +107,3 @@ func (c *Client) checkForErrors(err []GqlError) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) checkForPayInErrors(payIn PayIn) error {
|
|
||||||
privates := payIn.PayerPrivates
|
|
||||||
if privates.PayInFailureReason != "" {
|
|
||||||
return fmt.Errorf("mutation failed: %s", privates.PayInFailureReason)
|
|
||||||
}
|
|
||||||
|
|
||||||
bolt11 := privates.PayInBolt11
|
|
||||||
if bolt11.Id != 0 {
|
|
||||||
return fmt.Errorf("mutation failed: bolt11 payment required")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := privates.Result
|
|
||||||
if result.Id == 0 {
|
|
||||||
return fmt.Errorf("mutation failed: no result id")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
67
items.go
67
items.go
@ -63,15 +63,7 @@ type ItemsResponse struct {
|
|||||||
|
|
||||||
type PayIn struct {
|
type PayIn struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
PayerPrivates struct {
|
Item Item `json:"item"`
|
||||||
PayInFailureReason string `json:"payInFailureReason"`
|
|
||||||
PayInBolt11 struct {
|
|
||||||
Id int `json:"id"`
|
|
||||||
} `json:"payInBolt11"`
|
|
||||||
Result struct {
|
|
||||||
Id int `json:"id,string"`
|
|
||||||
} `json:"result"`
|
|
||||||
} `json:"payerPrivates"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpsertDiscussionResponse struct {
|
type UpsertDiscussionResponse struct {
|
||||||
@ -234,17 +226,9 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
|
|||||||
mutation upsertDiscussion($title: String!, $text: String, $sub: String) {
|
mutation upsertDiscussion($title: String!, $text: String, $sub: String) {
|
||||||
upsertDiscussion(title: $title, text: $text, sub: $sub) {
|
upsertDiscussion(title: $title, text: $text, sub: $sub) {
|
||||||
id
|
id
|
||||||
payerPrivates {
|
item {
|
||||||
payInFailureReason
|
|
||||||
payInBolt11 {
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
result {
|
|
||||||
... on Item {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -272,13 +256,12 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payIn := respBody.Data.UpsertDiscussion
|
item := respBody.Data.UpsertDiscussion.Item
|
||||||
err = c.checkForPayInErrors(payIn)
|
if item.Id == 0 {
|
||||||
if err != nil {
|
return -1, fmt.Errorf("API returned no item id")
|
||||||
return -1, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return payIn.PayerPrivates.Result.Id, nil
|
return item.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) PostLink(url string, title string, text string, sub string) (int, error) {
|
func (c *Client) PostLink(url string, title string, text string, sub string) (int, error) {
|
||||||
@ -287,17 +270,9 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
|
|||||||
mutation upsertLink($url: String!, $title: String!, $text: String, $sub: String!) {
|
mutation upsertLink($url: String!, $title: String!, $text: String, $sub: String!) {
|
||||||
upsertLink(url: $url, title: $title, text: $text, sub: $sub) {
|
upsertLink(url: $url, title: $title, text: $text, sub: $sub) {
|
||||||
id
|
id
|
||||||
payerPrivates {
|
item {
|
||||||
payInFailureReason
|
|
||||||
payInBolt11 {
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
result {
|
|
||||||
... on Item {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -326,13 +301,12 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payIn := respBody.Data.UpsertLink
|
item := respBody.Data.UpsertLink.Item
|
||||||
err = c.checkForPayInErrors(payIn)
|
if item.Id == 0 {
|
||||||
if err != nil {
|
return -1, fmt.Errorf("API returned no item id")
|
||||||
return -1, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return payIn.PayerPrivates.Result.Id, nil
|
return item.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
||||||
@ -341,17 +315,9 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
|||||||
mutation upsertComment($parentId: ID!, $text: String!) {
|
mutation upsertComment($parentId: ID!, $text: String!) {
|
||||||
upsertComment(parentId: $parentId, text: $text) {
|
upsertComment(parentId: $parentId, text: $text) {
|
||||||
id
|
id
|
||||||
payerPrivates {
|
item {
|
||||||
payInFailureReason
|
|
||||||
payInBolt11 {
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
result {
|
|
||||||
... on Item {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -378,13 +344,12 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payIn := respBody.Data.UpsertComment
|
item := respBody.Data.UpsertComment.Item
|
||||||
err = c.checkForPayInErrors(payIn)
|
if item.Id == 0 {
|
||||||
if err != nil {
|
return -1, fmt.Errorf("API returned no item id")
|
||||||
return -1, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return payIn.PayerPrivates.Result.Id, nil
|
return item.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Dupes(url string) (*[]Dupe, error) {
|
func (c *Client) Dupes(url string) (*[]Dupe, error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user