client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package client provides a configurable Twitter API HTTP client used by higher level service wrappers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse inspects the response status code and returns an APIError when the call did not succeed.

func SafeClose

func SafeClose(closer io.ReadCloser)

SafeClose closes a response body while ignoring errors.

Types

type APIError

type APIError struct {
	StatusCode int
	Errors     []Error
}

APIError represents one or more Twitter API errors.

func (APIError) Error

func (e APIError) Error() string

type Client

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

Client wraps HTTP concerns for talking to the Twitter v2 API.

func New

func New(cfg Config) (*Client, error)

New constructs a Client using the supplied configuration taking sensible defaults from environment variables when values are omitted.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, query map[string]string) (*http.Response, error)

Delete issues a DELETE request against the supplied path.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do forwards the request to the underlying http.Client while adding headers.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, query map[string]string) (*http.Response, error)

Get issues a GET request against the supplied path.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, query map[string]string, body interface{}) (*http.Request, error)

NewRequest builds an *http.Request using the configured base URL.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, query map[string]string) (*http.Response, error)

Post issues a POST request against the supplied path with a JSON payload.

type Config

type Config struct {
	BaseURL     string
	BearerToken string
	UserAgent   string
	HTTPClient  *http.Client
	Timeout     time.Duration
}

Config describes how to construct a Client.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error captures a single entry in the Twitter error payload.

type RateLimitSnapshot

type RateLimitSnapshot struct {
	Limit     int
	Remaining int
	Reset     int
}

RateLimitSnapshot captures the rate limit headers for a response.

func ParseRateLimits

func ParseRateLimits(resp *http.Response) RateLimitSnapshot

ParseRateLimits extracts rate limiting information from the response headers.

Jump to

Keyboard shortcuts

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