tweet

package
v0.0.0-...-e895ae5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package tweet provides primitives for making requests to Twitter API and parsing the tweets.

Example
package main

import (
	"github.com/rodionlim/tweet/library/tweet"
)

func main() {
	// Quick start example - This will query twitter for keywords oil, copper ... and user @Bloomberg Markets
	keywords := []string{"oil", "copper", "rates", "inflation", "gold", "nickel", "powell", "fed", "bonds", "metals", "equities", "energy", "central bank", "commodities", "fx"}
	users := []string{"markets"}

	req := tweet.NewReq(tweet.WithUsers(users), tweet.WithKeywords(keywords))
	req.Get()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLatestSearchTerms

func GetLatestSearchTerms() ([]string, error)

GetLatestSearchTerms fetches the latest keywords stored in disk, which can be useful to inform the user what is the current search term.

func WithEndpoint

func WithEndpoint(endpoint string) func(r *Req) *Req

WithEndpoint changes the twitter api endpoint.

func WithKeywords

func WithKeywords(keywords []string) func(r *Req) *Req

WithKeywords adds a filter for keywords in tweets.

func WithMaxResults

func WithMaxResults(cnt int) func(r *Req) *Req

WithMaxResults adds a filter for maximum results returned.

func WithSinceTweetID

func WithSinceTweetID(id int64) func(r *Req) *Req

WithSinceTweetID adds a filter for only returning tweets greater than tweet id.

func WithUsers

func WithUsers(users []string) func(r *Req) *Req

WithUser adds a filter for twitter users.

Types

type Meta

type Meta struct {
	NewestID    string `json:"newest_id"`
	OldestID    string `json:"oldest_id"`
	ResultCount int    `json:"result_count"`
	NextToken   string `json:"next_token"`
}

Meta is the metadata from the response of a twitter get request.

type Req

type Req struct {
	// contains filtered or unexported fields
}

Req consists of relevant parameters to encapsulate a Twitter API GET request.

func NewReq

func NewReq(opts ...func(r *Req) *Req) *Req

NewReq is a struct that contains the necessary API parameters before firing the call to Twitter endpoints

func (*Req) Get

func (r *Req) Get() (*Tweets, error)

Get prepares the request and fires it to Twitter API, storing the results in Req object.

func (*Req) GetLatestTweetID

func (r *Req) GetLatestTweetID() (string, error)

GetLatestTweetID fetches the latest Twitter ID stored in disk, which can be useful when trying to avoid duplicated queries.

func (*Req) SetSinceTweetID

func (r *Req) SetSinceTweetID(v string)

Allow setting of since tweet ID at runtime to support polling for latest results without duplicates.

func (*Req) StoreLatestSearchTerms

func (r *Req) StoreLatestSearchTerms() error

StoreLatestSearchTerm stores the latest keywords used for querying, persistently to disk, which can be useful to inform the user what is currently being searched.

func (*Req) StoreLatestTweetID

func (r *Req) StoreLatestTweetID() error

StoreLatestTweetID stores the latest Twitter ID queried, persistently to disk, which can be useful when trying to avoid duplicated queries.

type Tweets

type Tweets struct {
	Data []map[string]string `json:"data"`
	Meta Meta                `json:"meta"`
}

Tweets contains a list of tweets and the metadata required for pagination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL