46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
|
package twitterapi
|
||
|
|
||
|
//go:generate mockery --recursive --name Store --output ../generated/mocks
|
||
|
//go:generate mockery --recursive --name APIClient --structname TwitterAPIClient --filename TwitterAPIClient.go --output ../generated/mocks
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
|
||
|
"git.netflux.io/rob/elon-eats-my-tweets/generated/store"
|
||
|
)
|
||
|
|
||
|
// Store is a persistent store.
|
||
|
type Store interface {
|
||
|
CreateUser(context.Context, store.CreateUserParams) (store.User, error)
|
||
|
GetLastElonTweet(context.Context) (store.ElonTweet, error)
|
||
|
UpsertElonTweet(context.Context, store.UpsertElonTweetParams) (store.ElonTweet, error)
|
||
|
}
|
||
|
|
||
|
// APIClient is a client for the Twitter API.
|
||
|
type APIClient interface {
|
||
|
GetLastTweet(string) (*Tweet, error)
|
||
|
GetTweets(string, string) ([]*Tweet, error)
|
||
|
GetMe() (*User, error)
|
||
|
}
|
||
|
|
||
|
// TwitterMetadata contains the metadata returned in Twitter API responses.
|
||
|
type TwitterMetadata struct {
|
||
|
ResultCount int `json:"result_count"`
|
||
|
NewestID string `json:"newest_id"`
|
||
|
}
|
||
|
|
||
|
// User represents a Twitter user as returned from the Twitter API.
|
||
|
type User struct {
|
||
|
ID string `json:"id"`
|
||
|
Name string `json:"name"`
|
||
|
Username string `json:"username"`
|
||
|
}
|
||
|
|
||
|
// Tweet represents a tweet as returned from the Twitter API.
|
||
|
type Tweet struct {
|
||
|
ID string `json:"id"`
|
||
|
Text string `json:"text"`
|
||
|
CreatedAt time.Time `json:"created_at"`
|
||
|
}
|