Fix parsing of PayIn response
This commit is contained in:
parent
3498d0da7f
commit
89fa38edd7
19
client.go
19
client.go
@ -107,3 +107,22 @@ 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
|
||||||
|
}
|
||||||
|
|||||||
75
items.go
75
items.go
@ -62,8 +62,16 @@ type ItemsResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PayIn struct {
|
type PayIn struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Item Item `json:"item"`
|
PayerPrivates struct {
|
||||||
|
PayInFailureReason string `json:"payInFailureReason"`
|
||||||
|
PayInBolt11 struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
} `json:"payInBolt11"`
|
||||||
|
Result struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
} `json:"result"`
|
||||||
|
} `json:"payerPrivates"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpsertDiscussionResponse struct {
|
type UpsertDiscussionResponse struct {
|
||||||
@ -226,8 +234,16 @@ 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
|
||||||
item {
|
payerPrivates {
|
||||||
id
|
payInFailureReason
|
||||||
|
payInBolt11 {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
result {
|
||||||
|
... on Item {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
@ -256,12 +272,13 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
item := respBody.Data.UpsertDiscussion.Item
|
payIn := respBody.Data.UpsertDiscussion
|
||||||
if item.Id == 0 {
|
err = c.checkForPayInErrors(payIn)
|
||||||
return -1, fmt.Errorf("API returned no item id")
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.Id, nil
|
return payIn.PayerPrivates.Result.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) {
|
||||||
@ -270,8 +287,16 @@ 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
|
||||||
item {
|
payerPrivates {
|
||||||
id
|
payInFailureReason
|
||||||
|
payInBolt11 {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
result {
|
||||||
|
... on Item {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
@ -301,12 +326,13 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
item := respBody.Data.UpsertLink.Item
|
payIn := respBody.Data.UpsertLink
|
||||||
if item.Id == 0 {
|
err = c.checkForPayInErrors(payIn)
|
||||||
return -1, fmt.Errorf("API returned no item id")
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.Id, nil
|
return payIn.PayerPrivates.Result.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
||||||
@ -315,8 +341,16 @@ 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
|
||||||
item {
|
payerPrivates {
|
||||||
id
|
payInFailureReason
|
||||||
|
payInBolt11 {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
result {
|
||||||
|
... on Item {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
@ -344,12 +378,13 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
item := respBody.Data.UpsertComment.Item
|
payIn := respBody.Data.UpsertComment
|
||||||
if item.Id == 0 {
|
err = c.checkForPayInErrors(payIn)
|
||||||
return -1, fmt.Errorf("API returned no item id")
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.Id, nil
|
return payIn.PayerPrivates.Result.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