-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
41 lines (30 loc) · 780 Bytes
/
client.go
File metadata and controls
41 lines (30 loc) · 780 Bytes
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
package flickr
import (
"fmt"
"net/http"
"io/ioutil"
)
type Params map[string]string
type Client struct {
Key string
Token string
Sig string
}
func (client *Client) Request (method string, params Params) ([]byte, error) {
url := fmt.Sprintf("https://api.flickr.com/services/rest/?method=flickr.%s&api_key=%s&format=json&nojsoncallback=1", method, client.Key)
if len(client.Token) > 0 {
url = fmt.Sprintf("%s&auth_token=%s", url, client.Token)
}
if len(client.Sig) > 0 {
url = fmt.Sprintf("%s&auth_sig=%s", url, client.Sig)
}
for key, value := range params {
url = fmt.Sprintf("%s&%s=%s", url, key, value)
}
response, err := http.Get(url)
if err != nil {
return nil, err
}
defer response.Body.Close()
return ioutil.ReadAll(response.Body)
}