Compare commits
No commits in common. "791eea60ef1eee3119f951f758c18d615ce412af" and "c80f0060c3ccbb317fb310f45c2d9c7e14f056c3" have entirely different histories.
791eea60ef
...
c80f0060c3
2
go.mod
2
go.mod
@ -1,5 +1,3 @@
|
|||||||
module github.com/ekzyis/snappy
|
module github.com/ekzyis/snappy
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require gopkg.in/guregu/null.v4 v4.0.0 // indirect
|
|
||||||
|
2
go.sum
2
go.sum
@ -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=
|
|
72
items.go
72
items.go
@ -4,8 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/guregu/null.v4"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
@ -16,7 +14,6 @@ type Item struct {
|
|||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Sats int `json:"sats"`
|
Sats int `json:"sats"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
DeletedAt null.Time `json:"deletedAt"`
|
|
||||||
Comments []Comment `json:"comments"`
|
Comments []Comment `json:"comments"`
|
||||||
NComments int `json:"ncomments"`
|
NComments int `json:"ncomments"`
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
@ -121,17 +118,42 @@ func (c *Client) Item(id int) (*Item, error) {
|
|||||||
item(id: $id) {
|
item(id: $id) {
|
||||||
id
|
id
|
||||||
parentId
|
parentId
|
||||||
title
|
|
||||||
url
|
|
||||||
text
|
|
||||||
sats
|
|
||||||
createdAt
|
createdAt
|
||||||
deletedAt
|
deletedAt
|
||||||
ncomments
|
title
|
||||||
|
url
|
||||||
user {
|
user {
|
||||||
id
|
id
|
||||||
name
|
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{}{
|
Variables: map[string]interface{}{
|
||||||
@ -172,17 +194,43 @@ func (c *Client) Items(query *ItemsQuery) (*ItemsCursor, error) {
|
|||||||
items {
|
items {
|
||||||
id
|
id
|
||||||
parentId
|
parentId
|
||||||
|
createdAt
|
||||||
|
deletedAt
|
||||||
title
|
title
|
||||||
url
|
url
|
||||||
text
|
text
|
||||||
sats
|
|
||||||
createdAt
|
|
||||||
deletedAt
|
|
||||||
ncomments
|
|
||||||
user {
|
user {
|
||||||
id
|
id
|
||||||
name
|
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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
@ -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
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user