func (f *Flickr) Search(q string) (*Image, error) { if q == "" { return nil, errors.New("Trying to make a query without parameters") } f.Client.Init() f.Client.Args.Set("api_key", f.ApiKey) f.Client.Args.Set("method", "flickr.photos.search") f.Client.Args.Set("text", strings.Trim(q, " ")) f.Client.Args.Set("format", "rest") response := &flickr.BasicResponse{} fmt.Println(f.Client.GetUrl()) err := flickr.DoGet(f.Client, response) if err != nil { return nil, err } var p Photos xml.Unmarshal([]byte(response.Extra), &p) if len(p.Photos) <= 0 { return nil, errors.New("No results") } idx := rand.Intn(len(p.Photos)) photo := p.Photos[idx] img, _ := NewImage(photo.buildUrl(), photo.Title) return img, nil }
// A testing method which echo's all parameters back in the response. // This method does not require authentication. func Echo(client *flickr.FlickrClient) (*EchoResponse, error) { client.EndpointUrl = flickr.API_ENDPOINT client.Args.Set("method", "flickr.test.echo") client.Args.Set("oauth_consumer_key", client.ApiKey) response := &EchoResponse{} err := flickr.DoGet(client, response) return response, err }
// Noop method // This method requires authentication with 'read' permission. func Null(client *flickr.FlickrClient) (*flickr.BasicResponse, error) { client.Init() client.SetOAuthDefaults() client.Args.Set("method", "flickr.test.null") client.OAuthSign() response := &flickr.BasicResponse{} err := flickr.DoGet(client, response) return response, err }
// A testing method which checks if the caller is logged in then returns their username. // This method requires authentication with 'read' permission. func Login(client *flickr.FlickrClient) (*LoginResponse, error) { client.Init() client.SetOAuthDefaults() client.Args.Set("method", "flickr.test.login") client.OAuthSign() loginResponse := &LoginResponse{} err := flickr.DoGet(client, loginResponse) return loginResponse, err }
// Returns the credentials attached to an OAuth authentication token. // This method does not require user authentication, but the request must be api-signed. func CheckToken(client *flickr.FlickrClient, oauthToken string) (*CheckTokenResponse, error) { client.EndpointUrl = flickr.API_ENDPOINT client.ClearArgs() client.Args.Set("method", "flickr.auth.oauth.checkToken") client.Args.Set("oauth_token", oauthToken) client.ApiSign() response := &CheckTokenResponse{} err := flickr.DoGet(client, response) return response, err }
// Gets information about a photoset. // This method does not require authentication unless you want to access a private set func GetInfo(client *flickr.FlickrClient, authenticate bool, photosetId, ownerID string) (*PhotosetResponse, error) { client.Init() client.Args.Set("method", "flickr.photosets.getInfo") client.Args.Set("photoset_id", photosetId) // this argument is optional but increases query performances if ownerID != "" { client.Args.Set("user_id", ownerID) } // sign the client for authentication and authorization if authenticate { client.OAuthSign() } else { client.ApiSign() } response := &PhotosetResponse{} err := flickr.DoGet(client, response) return response, err }
// Return the public sets belonging to the user with userId. // If userId is not provided it defaults to the caller user but call needs to be authenticated. // This method requires authentication to retrieve private sets. func GetList(client *flickr.FlickrClient, authenticate bool, userId string, page int) (*PhotosetsListResponse, error) { client.Init() client.Args.Set("method", "flickr.photosets.getList") if userId != "" { client.Args.Set("user_id", userId) } // if not provided, flickr defaults this argument to 1 if page > 1 { client.Args.Set("page", strconv.Itoa(page)) } // perform authentication if requested if authenticate { client.OAuthSign() } else { client.ApiSign() } response := &PhotosetsListResponse{} err := flickr.DoGet(client, response) return response, err }
// Get the photos in a set // This method requires authentication to retrieve photos from private sets func GetPhotos(client *flickr.FlickrClient, authenticate bool, photosetId, ownerID string, page int) (*PhotosListResponse, error) { client.Init() client.Args.Set("method", "flickr.photosets.getPhotos") client.Args.Set("photoset_id", photosetId) // this argument is optional but increases query performances if ownerID != "" { client.Args.Set("user_id", ownerID) } // if not provided, flickr defaults this argument to 1 if page > 1 { client.Args.Set("page", strconv.Itoa(page)) } // sign the client for authentication and authorization if authenticate { client.OAuthSign() } else { client.ApiSign() } response := &PhotosListResponse{} err := flickr.DoGet(client, response) return response, err }