Compare commits

..

No commits in common. "791eea60ef1eee3119f951f758c18d615ce412af" and "c80f0060c3ccbb317fb310f45c2d9c7e14f056c3" have entirely different histories.

4 changed files with 60 additions and 92 deletions

2
go.mod
View File

@ -1,5 +1,3 @@
module github.com/ekzyis/snappy
go 1.20
require gopkg.in/guregu/null.v4 v4.0.0 // indirect

2
go.sum
View File

@ -1,2 +0,0 @@
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=

View File

@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"
"time"
"gopkg.in/guregu/null.v4"
)
type Item struct {
@ -16,7 +14,6 @@ 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"`
@ -121,17 +118,42 @@ func (c *Client) Item(id int) (*Item, error) {
item(id: $id) {
id
parentId
title
url
text
sats
createdAt
deletedAt
ncomments
title
url
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{}{
@ -172,17 +194,43 @@ 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
},
}
}`,

View File

@ -1,76 +0,0 @@
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
}