stream

package
v0.0.0-...-17e3d52 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IStream

type IStream interface {
	StartStream(queryParams *url.Values) error
	StopStream()
	GetMessages() <-chan StreamMessage
	SetUnmarshalHook(hook UnmarshalHook)
}

IStream is the interface that the stream struct implements.

func NewStream

func NewStream(httpClient httpclient.IHttpClient, reader IStreamResponseBodyReader) IStream

NewStream creates an instance of `Stream`. This is used to manage the stream with Twitter.

type IStreamQueryParamsBuilder

type IStreamQueryParamsBuilder interface {
	AddBackFillMinutes(minutes uint) *StreamQueryParamBuilder
	AddExpansion(expansion string) *StreamQueryParamBuilder
	AddMediaField(mediaField string) *StreamQueryParamBuilder
	AddPlaceField(placeField string) *StreamQueryParamBuilder
	AddPollField(pollField string) *StreamQueryParamBuilder
	AddTweetField(tweetField string) *StreamQueryParamBuilder
	AddUserField(userField string) *StreamQueryParamBuilder
	Build() *url.Values
}

IStreamQueryParamsBuilder is the interface for StreamQueryParamBuilder.

func NewStreamQueryParamsBuilder

func NewStreamQueryParamsBuilder() IStreamQueryParamsBuilder

NewStreamQueryParamsBuilder creeates a struct that implements IStreamQueryParamsBuilder. It is used to request additional data from a tweet. Read more at https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream.

type IStreamResponseBodyReader

type IStreamResponseBodyReader interface {
	// contains filtered or unexported methods
}

IStreamResponseBodyReader is the interface the streamResponseBodyReader implements.

func NewStreamResponseBodyReader

func NewStreamResponseBodyReader() IStreamResponseBodyReader

NewStreamResponseBodyReader returns an instance of streamResponseBodyReader for the given Twitter stream response body.

type Stream

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

Stream is the struct that manages a long running TCP connection with Twitter. It accepts an 'unamarshalHook' which allows you to unmarshal json in a thread-safe manner. It is highly encouraged to set a unmarshal hook before starting a stream. Unmarshaling json in a separate goroutine is not recommended because the Go bytes.Buffer is not goroutine safe.

func (*Stream) GetMessages

func (s *Stream) GetMessages() <-chan StreamMessage

GetMessages returns the read-only messages channel

func (*Stream) SetUnmarshalHook

func (s *Stream) SetUnmarshalHook(hook UnmarshalHook)

SetUnmarshalHook sets the function that unmarshals json. It is highly encouraged that you unmarshal json with this hook to promote thread-safety. Go's bytes.Buffer is not thread safe and can result in panics when a bytes.Buffer is shared across goroutines.

func (*Stream) StartStream

func (s *Stream) StartStream(optionalQueryParams *url.Values) error

StartStream makes an HTTP GET request to twitter and starts streaming tweets to the Messages channel. Accepts query params described in GET /2/tweets/search/stream to expand the payload that is returned. Query params string must begin with a ?. See available query params here https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream. See an example here: https://developer.twitter.com/en/docs/twitter-api/expansions.

func (*Stream) StopStream

func (s *Stream) StopStream()

StopStream sends a close signal to stop the stream of tweets.

type StreamMessage

type StreamMessage struct {
	Data interface{}
	Err  error
}

StreamMessage is the message that is sent from the messages channel.

type StreamQueryParamBuilder

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

StreamQueryParamBuilder is a struct used for requesting additional data from a tweet. Read more at https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream.

func (*StreamQueryParamBuilder) AddBackFillMinutes

func (s *StreamQueryParamBuilder) AddBackFillMinutes(backFillMinutes uint) *StreamQueryParamBuilder

AddBackFillMinutes will allow you to recover up to 5 minutes worth of data that might have been missed during a disconnection. This feature is currently only available to the academic research product track! Learn more about media fields on twitter docs https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream.

func (*StreamQueryParamBuilder) AddExpansion

func (s *StreamQueryParamBuilder) AddExpansion(expansion string) *StreamQueryParamBuilder

AddExpansion adds an expansion defined in https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream. With expansions, developers can expand objects referenced in the payload. Objects available for expansion are referenced by ID. Add a single expansion for each invoke of `AddExpansion`.

func (*StreamQueryParamBuilder) AddMediaField

func (s *StreamQueryParamBuilder) AddMediaField(mediaField string) *StreamQueryParamBuilder

AddMediaField adds a media field which enables you to select which specific media fields will deliver in each returned tweet. The Tweet will only return media fields if the Tweet contains media and if you've also included `AddExpansion("attachments.media_keys")`. Learn more about media fields on twitter docs https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream. Add a single media field for each invoke of `AddMediaField`.

func (*StreamQueryParamBuilder) AddPlaceField

func (s *StreamQueryParamBuilder) AddPlaceField(placeField string) *StreamQueryParamBuilder

AddPlaceField adds a place field which enables you to select which specific place fields will deliver in each returned tweet. The Tweet will only return place fields if the Tweet contains a place and if you've also included `AddExpansion("geo.place_id")`. Learn more about place fields on twitter docs https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream. Add a single place field for each invoke of `AddPlaceField`.

func (*StreamQueryParamBuilder) AddPollField

func (s *StreamQueryParamBuilder) AddPollField(pollField string) *StreamQueryParamBuilder

AddPollField adds a poll field which enables you to select which specific poll fields will deliver in each returned tweet. The Tweet will only return poll fields if the Tweet contains a place and if you've also included `AddExpansion("attachments.poll_ids")`. Learn more about poll fields on twitter docs https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream. Add a single poll field for each invoke of `AddPollField`.

func (*StreamQueryParamBuilder) AddTweetField

func (s *StreamQueryParamBuilder) AddTweetField(tweetField string) *StreamQueryParamBuilder

AddTweetField This fields parameter enables you to select which specific Tweet fields will deliver in each returned Tweet object. Specify the desired fields in a comma-separated list without spaces between commas and fields. You can also include `AddExpansion("referenced_tweets.id")` to return the specified fields for both the original Tweet and any included referenced Tweets. The requested Tweet fields will display in both the original Tweet data object, as well as in the referenced Tweet expanded data object that will be located in the includes data object. Learn more about tweet fields on twitter docs https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream.

func (*StreamQueryParamBuilder) AddUserField

func (s *StreamQueryParamBuilder) AddUserField(userField string) *StreamQueryParamBuilder

AddUserField This fields parameter enables you to select which specific user fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. While the user ID will be located in the original Tweet object, you will find this ID and all additional user fields in the includes data object. You must also pass one of the user expansions to return the desired user field. `AddExpansion("author_id")` `AddExpansion("entities.mentions.username")` `AddExpansion("in_reply_to_user_id")` `AddExpansion("referenced_tweets.id.author_id")`

func (*StreamQueryParamBuilder) Build

func (s *StreamQueryParamBuilder) Build() *url.Values

Build will build and encode the required query params.

type UnmarshalHook

type UnmarshalHook func([]byte) (interface{}, error)

UnmarshalHook is a function that will unmarshal json.

Jump to

Keyboard shortcuts

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