forked from danilopolani/gocialite
/
foursquare.go
45 lines (35 loc) · 1.42 KB
/
foursquare.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
package drivers
import (
"net/http"
"github.com/danilopolani/gocialite/structs"
"golang.org/x/oauth2/foursquare"
)
const foursquareDriverName = "foursquare"
func init() {
registerDriver(foursquareDriverName, FoursquareDefaultScopes, FoursquareUserFn, foursquare.Endpoint, FoursquareAPIMap, FoursquareUserMap)
}
// FoursquareUserMap is the map to create the User struct
var FoursquareUserMap = map[string]string{}
// FoursquareAPIMap is the map for API endpoints
var FoursquareAPIMap = map[string]string{
"endpoint": "https://api.foursquare.com",
"userEndpoint": "/v2/users/self?oauth_token=%ACCESS_TOKEN&v=20171220",
}
// FoursquareUserFn is a callback to parse additional fields for User
var FoursquareUserFn = func(client *http.Client, u *structs.User) {
user := u.Raw["response"].(map[string]interface{})["user"].(map[string]interface{})
u.ID = user["id"].(string)
u.FirstName = user["firstName"].(string)
u.LastName = user["lastName"].(string)
u.FullName = u.FirstName + " " + u.LastName
if email, ok := user["contact"].(map[string]interface{})["email"]; ok {
u.Email = email.(string)
}
if avatarPrefix, ok := user["photo"].(map[string]interface{})["prefix"]; ok {
if avatarSuffix, ok2 := user["photo"].(map[string]interface{})["suffix"]; ok2 {
u.Avatar = avatarPrefix.(string) + "original" + avatarSuffix.(string)
}
}
}
// FoursquareDefaultScopes contains the default scopes
var FoursquareDefaultScopes = []string{}