RedGifsWrapper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 7 Imported by: 0

README

RedGifsWrapper

==============

RedGifsWrapper is a Go package for interacting with the RedGifs API. It provides methods for requesting access tokens and looking up stream URLs for GIFs hosted on RedGifs.

Installation


To use RedGifsWrapper, you can install it using go get:

go get github.com/StellarReddit/RedGifsWrapper

Usage


Creating a client

To use RedGifsWrapper, you first need to create a client object using the NewClient function. The NewClient function requires a Config object, which contains your RedGifs API credentials and other optional configuration options.

Here's an example of how to create a client object:

import (
    "github.com/your-username/RedGifsWrapper"
)

config := RedGifsWrapper.Config{
    ClientID: "your-client-id",
    ClientSecret: "your-client-secret",
    UserAgent: "your-user-agent",
}

client := RedGifsWrapper.NewClient(config)
Requesting a new access token

To request a new access token, use the RequestNewAccessToken method of your client object. The method returns a string containing the access token, or an error if the request fails.

Here's an example of how to request a new access token:

accessToken, err := client.RequestNewAccessToken()
if err != nil {
    // handle error
}
Looking up a stream URL

To look up a stream URL for a GIF hosted on RedGifs, use the LookupStreamURL method of your client object. The method requires the IP address and user agent string of the user requesting the GIF, the ID of the RedGifs GIF, and the access token. The method returns a string containing the stream URL, or an error if the request fails.

Here's an example of how to look up a stream URL:

ipAddress := "127.0.0.1"
userAgent := "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
redGifsID := "your-gif-id"
streamURL, err := client.LookupStreamURL(ipAddress, userAgent, redGifsID, accessToken)
if err != nil {
    // handle error
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAuthorized = errors.New("401 when testing RedGifs access token")
	ErrNotFound      = errors.New("404/410 gif not found")
)

Functions

This section is empty.

Types

type Client added in v1.0.0

type Client interface {
	RequestNewAccessToken() (string, error)
	LookupStreamURL(ipAddress, userAgent, redGifsID, accessToken string) (string, error)
}

Client defines the methods for interacting with the RedGifs API.

func NewClient added in v1.0.0

func NewClient(config Config) Client

NewClient returns a new RedGifs API client.

type Config added in v1.0.0

type Config struct {
	ClientID     string
	ClientSecret string
	UserAgent    string
	HTTPClient   http.Client
}

Config defines the configuration for the RedGifs API client.

type RedGifsGif

type RedGifsGif struct {
	Urls RedGifsUrls `json:"urls"`
}

type RedGifsLookupResponse

type RedGifsLookupResponse struct {
	Gif RedGifsGif `json:"gif"`
}

type RedGifsTokenResponse

type RedGifsTokenResponse struct {
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
	AccessToken string `json:"access_token"`
}

type RedGifsUrls

type RedGifsUrls struct {
	Hd string `json:"hd"`
}

Jump to

Keyboard shortcuts

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