Compare commits
No commits in common. "develop" and "v0.7.0" have entirely different histories.
11
client.go
11
client.go
@ -23,21 +23,14 @@ func NewClient(options ...func(*Client)) *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
var ok bool
|
|
||||||
if c.BaseUrl == "" {
|
if c.BaseUrl == "" {
|
||||||
c.BaseUrl, ok = os.LookupEnv("SN_BASE_URL")
|
c.BaseUrl = "https://stacker.news"
|
||||||
if !ok {
|
|
||||||
c.BaseUrl = "https://stacker.news"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if c.ApiKey == "" {
|
if c.ApiKey == "" {
|
||||||
c.ApiKey = os.Getenv("SN_API_KEY")
|
c.ApiKey = os.Getenv("SN_API_KEY")
|
||||||
}
|
}
|
||||||
if c.MediaUrl == "" {
|
if c.MediaUrl == "" {
|
||||||
c.MediaUrl, ok = os.LookupEnv("SN_MEDIA_URL")
|
c.MediaUrl = "https://m.stacker.news"
|
||||||
if !ok {
|
|
||||||
c.MediaUrl = "https://m.stacker.news"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.ApiUrl = fmt.Sprintf("%s/api/graphql", c.BaseUrl)
|
c.ApiUrl = fmt.Sprintf("%s/api/graphql", c.BaseUrl)
|
||||||
|
|
||||||
|
51
items.go
51
items.go
@ -226,17 +226,7 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
|
|||||||
Query: `
|
Query: `
|
||||||
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) {
|
||||||
result {
|
result { id }
|
||||||
id
|
|
||||||
}
|
|
||||||
invoice {
|
|
||||||
id
|
|
||||||
hash
|
|
||||||
bolt11
|
|
||||||
satsRequested
|
|
||||||
expiresAt
|
|
||||||
}
|
|
||||||
paymentMethod
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -264,11 +254,6 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := respBody.Data.UpsertDiscussion.Invoice
|
|
||||||
if inv.Id != 0 {
|
|
||||||
return -1, fmt.Errorf("mutation requires %d sats as payment", inv.SatsRequested)
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBody.Data.UpsertDiscussion.Result.Id, nil
|
return respBody.Data.UpsertDiscussion.Result.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,17 +262,7 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
|
|||||||
Query: `
|
Query: `
|
||||||
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) {
|
||||||
result {
|
result { id }
|
||||||
id
|
|
||||||
}
|
|
||||||
invoice {
|
|
||||||
id
|
|
||||||
hash
|
|
||||||
bolt11
|
|
||||||
satsRequested
|
|
||||||
expiresAt
|
|
||||||
}
|
|
||||||
paymentMethod
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -316,11 +291,6 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := respBody.Data.UpsertLink.Invoice
|
|
||||||
if inv.Id != 0 {
|
|
||||||
return -1, fmt.Errorf("mutation requires %d sats as payment", inv.SatsRequested)
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBody.Data.UpsertLink.Result.Id, nil
|
return respBody.Data.UpsertLink.Result.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,17 +299,7 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
|||||||
Query: `
|
Query: `
|
||||||
mutation upsertComment($parentId: ID!, $text: String!) {
|
mutation upsertComment($parentId: ID!, $text: String!) {
|
||||||
upsertComment(parentId: $parentId, text: $text) {
|
upsertComment(parentId: $parentId, text: $text) {
|
||||||
result {
|
result { id }
|
||||||
id
|
|
||||||
}
|
|
||||||
invoice {
|
|
||||||
id
|
|
||||||
hash
|
|
||||||
bolt11
|
|
||||||
satsRequested
|
|
||||||
expiresAt
|
|
||||||
}
|
|
||||||
paymentMethod
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
@ -366,11 +326,6 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := respBody.Data.UpsertComment.Invoice
|
|
||||||
if inv.Id != 0 {
|
|
||||||
return -1, fmt.Errorf("mutation requires %d sats as payment", inv.SatsRequested)
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBody.Data.UpsertComment.Result.Id, nil
|
return respBody.Data.UpsertComment.Result.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user