api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MediaEndpoint is the endpoint for media uploads
	MediaEndpoint = "/2/media/upload"
)

Variables

View Source
var StreamingEndpoints = map[string]bool{
	"/2/tweets/search/stream":           true,
	"/2/tweets/sample/stream":           true,
	"/2/tweets/sample10/stream":         true,
	"/2/tweets/firehose/stream":         true,
	"/2/tweets/firehose/stream/lang/en": true,
	"/2/tweets/firehose/stream/lang/ja": true,
	"/2/tweets/firehose/stream/lang/ko": true,
	"/2/tweets/firehose/stream/lang/pt": true,
}

StreamingEndpoints is a map of endpoint prefixes that should be streamed

Functions

func ExecuteMediaStatus

func ExecuteMediaStatus(mediaID, authType, username string, verbose, wait, trace bool, headers []string, client Client) error

ExecuteMediaStatus handles the media status command execution

func ExecuteMediaUpload

func ExecuteMediaUpload(filePath, mediaType, mediaCategory, authType, username string, verbose, waitForProcessing, trace bool, headers []string, client Client) error

ExecuteMediaUpload handles the media upload command execution

func ExecuteRequest

func ExecuteRequest(options RequestOptions, client Client) error

ExecuteRequest handles the execution of a regular API request

func ExecuteStreamRequest

func ExecuteStreamRequest(options RequestOptions, client Client) error

ExecuteStreamRequest handles the execution of a streaming API request

func ExtractCommand

func ExtractCommand(url string) string

extracts command from URL

func ExtractMediaID

func ExtractMediaID(url string) string

ExtractMediaID extracts media_id from URL or data

func ExtractSegmentIndex

func ExtractSegmentIndex(data string) string

ExtractSegmentIndex extracts segment_index from URL or data

func HandleMediaAppendRequest

func HandleMediaAppendRequest(options RequestOptions, mediaFile string, client Client) (json.RawMessage, error)

HandleMediaAppendRequest handles a media append request with a file

func HandleRequest

func HandleRequest(options RequestOptions, forceStream bool, mediaFile string, client Client) error

HandleRequest determines the type of request and executes it accordingly

func IsMediaAppendRequest

func IsMediaAppendRequest(url string, mediaFile string) bool

IsMediaAppendRequest checks if the request is a media append request

func IsStreamingEndpoint

func IsStreamingEndpoint(endpoint string) bool

IsStreamingEndpoint checks if an endpoint should be streamed

Types

type ApiClient

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

ApiClient handles API requests

func NewApiClient

func NewApiClient(config *config.Config, auth *auth.Auth) *ApiClient

NewApiClient creates a new ApiClient

func (*ApiClient) BuildMultipartRequest

func (c *ApiClient) BuildMultipartRequest(options MultipartOptions) (*http.Request, error)

BuildMultipartRequest builds an HTTP request with multipart form data

func (*ApiClient) BuildRequest

func (c *ApiClient) BuildRequest(requestOptions RequestOptions) (*http.Request, error)

BuildRequest builds an HTTP request

func (*ApiClient) SendMultipartRequest

func (c *ApiClient) SendMultipartRequest(options MultipartOptions) (json.RawMessage, error)

SendMultipartRequest sends an HTTP request with multipart form data

func (*ApiClient) SendRequest

func (c *ApiClient) SendRequest(options RequestOptions) (json.RawMessage, error)

SendRequest sends an HTTP request

func (*ApiClient) StreamRequest

func (c *ApiClient) StreamRequest(options RequestOptions) error

StreamRequest sends an HTTP request and streams the response

type Client

type Client interface {
	BuildRequest(requestOptions RequestOptions) (*http.Request, error)
	BuildMultipartRequest(options MultipartOptions) (*http.Request, error)
	SendRequest(options RequestOptions) (json.RawMessage, error)
	StreamRequest(options RequestOptions) error
	SendMultipartRequest(options MultipartOptions) (json.RawMessage, error)
}

Client is an interface for API clients

type InitRequest

type InitRequest struct {
	TotalBytes    int64  `json:"total_bytes"`
	MediaType     string `json:"media_type"`
	MediaCategory string `json:"media_category"`
}

type MediaUploader

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

MediaUploader handles media upload operations

func NewMediaUploader

func NewMediaUploader(client Client, filePath string, verbose, trace bool, authType string, username string, headers []string) (*MediaUploader, error)

NewMediaUploader creates a new MediaUploader

func NewMediaUploaderWithoutFile

func NewMediaUploaderWithoutFile(client Client, verbose, trace bool, authType string, username string, headers []string) *MediaUploader

func (*MediaUploader) Append

func (m *MediaUploader) Append() error

Append uploads the media in chunks

func (*MediaUploader) CheckStatus

func (m *MediaUploader) CheckStatus() (json.RawMessage, error)

CheckStatus checks the status of the media upload

func (*MediaUploader) Finalize

func (m *MediaUploader) Finalize() (json.RawMessage, error)

Finalize finalizes the media upload

func (*MediaUploader) GetMediaID

func (m *MediaUploader) GetMediaID() string

GetMediaID returns the media ID

func (*MediaUploader) Init

func (m *MediaUploader) Init(mediaType string, mediaCategory string) error

Init initializes the media upload

func (*MediaUploader) SetMediaID

func (m *MediaUploader) SetMediaID(mediaID string)

SetMediaID sets the media ID

func (*MediaUploader) WaitForProcessing

func (m *MediaUploader) WaitForProcessing() (json.RawMessage, error)

WaitForProcessing waits for media processing to complete

type MultipartOptions

type MultipartOptions struct {
	RequestOptions
	FormFields map[string]string
	FileField  string
	FilePath   string
	FileName   string
	FileData   []byte
}

MultipartOptions contains options specific to multipart requests

type RequestOptions

type RequestOptions struct {
	Method   string
	Endpoint string
	Headers  []string
	Data     string
	AuthType string
	Username string
	Verbose  bool
	Trace    bool
}

RequestOptions contains common options for API requests

Jump to

Keyboard shortcuts

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