forked from masci/flickr
/
test.go
66 lines (57 loc) · 1.8 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Package implementing methods: flickr.test.*
package test
import (
"github.com/denmark/flickr"
)
// Response type used by Login function
type LoginResponse struct {
flickr.BasicResponse
// the user who provided authentication infos
User struct {
// Flickr ID
ID string `xml:"id,attr"`
// Flickr Username
Username string `xml:"username"`
} `xml:"user"`
}
// Response type used by Echo function
type EchoResponse struct {
flickr.BasicResponse
// API method name, dotted notation
Method string `xml:"method"`
// API Key provided
ApiKey string `xml:"api_key"`
// API data exchange format (ex. rest)
Format string `xml:"format"`
}
// 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.Args.Set("method", "flickr.test.login")
client.OAuthSign()
loginResponse := &LoginResponse{}
err := flickr.DoGet(client, loginResponse)
return loginResponse, 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 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
}