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
- func CheckTicketWithClient(ctx context.Context, cl Client, ticket *response.UploadTicket) (int64, error)
- func ExecuteMethodPaginatedWithClient(ctx context.Context, cl Client, args *url.Values, ...) error
- func RegisterClient(ctx context.Context, scheme string, f ClientInitializeFunc) error
- func ReplaceAsyncWithClient(ctx context.Context, cl Client, fh io.Reader, args *url.Values) (int64, error)
- func Schemes() []string
- func UploadAsyncWithClient(ctx context.Context, cl Client, fh io.Reader, args *url.Values) (int64, error)
- type Client
- type ClientInitializeFunc
- type ExecuteMethodPaginatedCallback
- type OAuth1Client
- func (cl *OAuth1Client) ExecuteMethod(ctx context.Context, args *url.Values) (io.ReadSeekCloser, error)
- func (cl *OAuth1Client) GetAccessToken(ctx context.Context, req_token auth.RequestToken, ...) (auth.AccessToken, error)
- func (cl *OAuth1Client) GetAuthorizationURL(ctx context.Context, req auth.RequestToken, perms string) (string, error)
- func (cl *OAuth1Client) GetRequestToken(ctx context.Context, cb_url string) (auth.RequestToken, error)
- func (cl *OAuth1Client) Replace(ctx context.Context, fh io.Reader, args *url.Values) (io.ReadSeekCloser, error)
- func (cl *OAuth1Client) Upload(ctx context.Context, fh io.Reader, args *url.Values) (io.ReadSeekCloser, error)
- func (cl *OAuth1Client) WithAccessToken(ctx context.Context, access_token auth.AccessToken) (Client, error)
Constants ¶
const API_ENDPOINT string = "https://api.flickr.com/services/rest"
The default Flickr API endpoint.
const OAUTH1_ACCESS_TOKEN_ENDPOINT string = "https://www.flickr.com/services/oauth/access_token"
The default Flickr endpoint for OAuth1 access token requests.
const OAUTH1_AUTHORIZE_ENDPOINT string = "https://www.flickr.com/services/oauth/authorize"
The default Flickr endpoint for OAuth1 authorization requests.
const OAUTH1_REQUEST_TOKEN_ENDPOINT string = "https://www.flickr.com/services/oauth/request_token"
The default Flickr endpoint for OAuth1 request token requests.
const REPLACE_ENDPOINT string = "https://up.flickr.com/services/replace/"
The default Flickr API endpoint for replacing images.
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 ¶
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 ¶
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 ¶
The initialization function signature for implementation of the Client interface.
type ExecuteMethodPaginatedCallback ¶
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.