Compare commits
3 Commits
c80f0060c3
...
791eea60ef
Author | SHA1 | Date | |
---|---|---|---|
791eea60ef | |||
d3f5fce46d | |||
c184d18431 |
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module github.com/ekzyis/snappy
|
||||
|
||||
go 1.20
|
||||
|
||||
require gopkg.in/guregu/null.v4 v4.0.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -0,0 +1,2 @@
|
||||
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
|
||||
gopkg.in/guregu/null.v4 v4.0.0/go.mod h1:YoQhUrADuG3i9WqesrCmpNRwm1ypAgSHYqoOcTu/JrI=
|
72
items.go
72
items.go
@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gopkg.in/guregu/null.v4"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
@ -14,6 +16,7 @@ type Item struct {
|
||||
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"`
|
||||
@ -118,42 +121,17 @@ func (c *Client) Item(id int) (*Item, error) {
|
||||
item(id: $id) {
|
||||
id
|
||||
parentId
|
||||
createdAt
|
||||
deletedAt
|
||||
title
|
||||
url
|
||||
text
|
||||
sats
|
||||
createdAt
|
||||
deletedAt
|
||||
ncomments
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
otsHash
|
||||
position
|
||||
sats
|
||||
boost
|
||||
bounty
|
||||
bountyPaidTo
|
||||
path
|
||||
upvotes
|
||||
meSats
|
||||
meDontLikeSats
|
||||
meBookmark
|
||||
meSubscription
|
||||
outlawed
|
||||
freebie
|
||||
ncomments
|
||||
commentSats
|
||||
lastCommentAt
|
||||
maxBid
|
||||
isJob
|
||||
company
|
||||
location
|
||||
remote
|
||||
subName
|
||||
pollCost
|
||||
status
|
||||
uploadId
|
||||
mine
|
||||
position
|
||||
}
|
||||
}`,
|
||||
Variables: map[string]interface{}{
|
||||
@ -194,43 +172,17 @@ func (c *Client) Items(query *ItemsQuery) (*ItemsCursor, error) {
|
||||
items {
|
||||
id
|
||||
parentId
|
||||
createdAt
|
||||
deletedAt
|
||||
title
|
||||
url
|
||||
text
|
||||
sats
|
||||
createdAt
|
||||
deletedAt
|
||||
ncomments
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
otsHash
|
||||
position
|
||||
sats
|
||||
boost
|
||||
bounty
|
||||
bountyPaidTo
|
||||
path
|
||||
upvotes
|
||||
meSats
|
||||
meDontLikeSats
|
||||
meBookmark
|
||||
meSubscription
|
||||
outlawed
|
||||
freebie
|
||||
ncomments
|
||||
commentSats
|
||||
lastCommentAt
|
||||
maxBid
|
||||
isJob
|
||||
company
|
||||
location
|
||||
remote
|
||||
subName
|
||||
pollCost
|
||||
status
|
||||
uploadId
|
||||
mine
|
||||
position
|
||||
},
|
||||
}
|
||||
}`,
|
||||
|
76
notifications.go
Normal file
76
notifications.go
Normal file
@ -0,0 +1,76 @@
|
||||
package sn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Notification struct {
|
||||
Id int `json:"id,string"`
|
||||
Type string `json:"__typename"`
|
||||
Item Item `json:"item"`
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
type NotificationsCursor struct {
|
||||
LastChecked time.Time
|
||||
Cursor string
|
||||
Notifications []Notification
|
||||
}
|
||||
|
||||
type NotificationsResponse struct {
|
||||
Errors []GqlError `json:"errors"`
|
||||
Data struct {
|
||||
Notifications NotificationsCursor `json:"notifications"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func (c *Client) Notifications() (*NotificationsCursor, error) {
|
||||
body := GqlBody{
|
||||
Query: `
|
||||
query notifications {
|
||||
notifications {
|
||||
notifications {
|
||||
__typename
|
||||
... on Mention {
|
||||
id
|
||||
item {
|
||||
id
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
parentId
|
||||
createdAt
|
||||
deletedAt
|
||||
title
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
Variables: map[string]interface{}{},
|
||||
}
|
||||
|
||||
resp, err := c.callApi(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var respBody NotificationsResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&respBody)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error decoding notifications: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.checkForErrors(respBody.Errors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &respBody.Data.Notifications, nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user