client

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: BSD-3-Clause Imports: 17 Imported by: 2

Documentation

Overview

package client provides interfaces for common methods for accessing the Flickr API. Currently there is only a single client interface that calls the Flickr API using the OAuth1 authentication and authorization scheme but it is assumed that eventually there will be at least one other when OAuth1 is superseded.

Index

Constants

View Source
const API_ENDPOINT string = "https://api.flickr.com/services/rest"

The default Flickr API endpoint.

View Source
const OAUTH1_ACCESS_TOKEN_ENDPOINT string = "https://www.flickr.com/services/oauth/access_token"

The default Flickr endpoint for OAuth1 access token requests.

View Source
const OAUTH1_AUTHORIZE_ENDPOINT string = "https://www.flickr.com/services/oauth/authorize"

The default Flickr endpoint for OAuth1 authorization requests.

View Source
const OAUTH1_REQUEST_TOKEN_ENDPOINT string = "https://www.flickr.com/services/oauth/request_token"

The default Flickr endpoint for OAuth1 request token requests.

View Source
const REPLACE_ENDPOINT string = "https://up.flickr.com/services/replace/"

The default Flickr API endpoint for replacing images.

View Source
const UPLOAD_ENDPOINT string = "https://up.flickr.com/services/upload/"

The default Flickr API endpoint for uploading images.

Variables

This section is empty.

Functions

func CheckTicketWithClient

func CheckTicketWithClient(ctx context.Context, cl Client, ticket *response.UploadTicket) (int64, error)

CheckTicketWithClient calls with Flickr API with Client and reponse.UploadTicket at regular intervals (every 2 seconds) to check the status of an upload ticket. If successful it will return the photo ID assigned to the upload.

func ExecuteMethodPaginatedWithClient

func ExecuteMethodPaginatedWithClient(ctx context.Context, cl Client, args *url.Values, cb ExecuteMethodPaginatedCallback) error

ExecuteMethodPaginatedWithClient invokes the Flickr API using a Client instance and then continues to invoke that method as many times as necessary to paginate through all of the results. Each result is passed to the ExecuteMethodPaginatedCallback for processing.

func RegisterClient

func RegisterClient(ctx context.Context, scheme string, f ClientInitializeFunc) error

Register a new URI scheme and ClientInitializeFunc function for a implementation of the Client interface.

func ReplaceAsyncWithClient

func ReplaceAsyncWithClient(ctx context.Context, cl Client, fh io.Reader, args *url.Values) (int64, error)

ReplaceAsyncWithClient invokes the Flickr API using a Client instance to replace an image asynchronously and then waits, invoking the CheckTicketWithClient method at regular intervals, until the replacement is complete.

func Schemes

func Schemes() []string

Return a list of URI schemes for registered implementations of the Client interface.

func UploadAsyncWithClient

func UploadAsyncWithClient(ctx context.Context, cl Client, fh io.Reader, args *url.Values) (int64, error)

UploadAsyncWithClient invokes the Flickr API using a Client instance to upload an image asynchronously and then waits, invoking the CheckTicketWithClient method at regular intervals, until the upload is complete.

Types

type Client

type Client interface {
	// Return a new Client instance that uses the credentials included in the auth.AccessToken instance.
	WithAccessToken(context.Context, auth.AccessToken) (Client, error)
	// Call the Flickr API and create a new request token as part of the token authorization flow.
	GetRequestToken(context.Context, string) (auth.RequestToken, error)
	// Generate the URL using a request token and permissions string used to redirect a user to in order to authorize a token request.
	GetAuthorizationURL(context.Context, auth.RequestToken, string) (string, error)
	// Call the Flickr API to exchange a request and authorization token for a permanent access token.
	GetAccessToken(context.Context, auth.RequestToken, auth.AuthorizationToken) (auth.AccessToken, error)
	// Execute a Flickr API method.
	ExecuteMethod(context.Context, *url.Values) (io.ReadSeekCloser, error)
	// Upload an image using the Flickr API.
	Upload(context.Context, io.Reader, *url.Values) (io.ReadSeekCloser, error)
	// Replace an image using the Flickr API.
	Replace(context.Context, io.Reader, *url.Values) (io.ReadSeekCloser, error)
}

Client is the interface that defines common methods for all Flickr API Client implementations. Currently there is only a single implementation that calls the Flickr API using the OAuth1 authentication and authorization scheme but it is assumed that eventually there will be at least one other when OAuth1 is superseded.

func NewClient

func NewClient(ctx context.Context, uri string) (Client, error)

Create a new instance of the Client interface. Client instances are created by passing in a context.Context instance and a URI string. The form and substance of URI strings are specific to their implementations. For example to create a OAuth1Client you would write: cl, err := client.NewClient(ctx, "oauth1://?consumer_key={KEY}&consumer_secret={SECRET}")

func NewOAuth1Client

func NewOAuth1Client(ctx context.Context, uri string) (Client, error)

Create a new OAuth1Client instance conforming to the Client interface. OAuth1Client instances are create by passing in a context.Context instance and a URI string in the form of: oauth1://?consumer_key={KEY}&consumer_secret={SECRET} or: oauth1://?consumer_key={KEY}&consumer_secret={SECRET}&oauth1_token={TOKEN}&oauth1_token_secret={SECRET}

type ClientInitializeFunc

type ClientInitializeFunc func(context.Context, string) (Client, error)

The initialization function signature for implementation of the Client interface.

type ExecuteMethodPaginatedCallback

type ExecuteMethodPaginatedCallback func(context.Context, io.ReadSeekCloser, error) error

ExecuteMethodPaginatedCallback is the interface for callback functions passed to the ExecuteMethodPaginatedWithClient method.

type OAuth1Client

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

OAuth1Client implements the Client interface for invoking the Flickr API using the OAuth1 authentication and authorization mechanism.

func (*OAuth1Client) ExecuteMethod

func (cl *OAuth1Client) ExecuteMethod(ctx context.Context, args *url.Values) (io.ReadSeekCloser, error)

Execute a Flickr API method. If not "format" parameter in include in the url.Values instance passed to the method API responses will be returned as JSON (by automatically assign the 'nojsoncallback=1' and 'format=json' parameters).

func (*OAuth1Client) GetAccessToken

func (cl *OAuth1Client) GetAccessToken(ctx context.Context, req_token auth.RequestToken, auth_token auth.AuthorizationToken) (auth.AccessToken, error)

Call the Flickr API to exchange a request and authorization token for a permanent access token.

func (*OAuth1Client) GetAuthorizationURL

func (cl *OAuth1Client) GetAuthorizationURL(ctx context.Context, req auth.RequestToken, perms string) (string, error)

Generate the URL using a request token and permissions string used to redirect a user to in order to authorize a token request.

func (*OAuth1Client) GetRequestToken

func (cl *OAuth1Client) GetRequestToken(ctx context.Context, cb_url string) (auth.RequestToken, error)

Call the Flickr API and create a new request token as part of the token authorization flow.

func (*OAuth1Client) Replace

func (cl *OAuth1Client) Replace(ctx context.Context, fh io.Reader, args *url.Values) (io.ReadSeekCloser, error)

Replace an image using the Flickr API.

func (*OAuth1Client) Upload

func (cl *OAuth1Client) Upload(ctx context.Context, fh io.Reader, args *url.Values) (io.ReadSeekCloser, error)

Upload an image using the Flickr API.

func (*OAuth1Client) WithAccessToken

func (cl *OAuth1Client) WithAccessToken(ctx context.Context, access_token auth.AccessToken) (Client, error)

Return a new Client instance that uses the credentials included in the auth.AccessToken instance.

Jump to

Keyboard shortcuts

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