-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraph.go
65 lines (54 loc) · 1.65 KB
/
graph.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
package facebook
// Graph represents a default configuration
// for facebook graph api
type Graph struct {
Version string
URL string
}
// GraphInterface represents all methods for using
// Facebook Graph API
type GraphInterface interface {
SetVersion(version string) GraphInterface
GetVersion() string
GetGraphURL() string
GenerateURL(path string) string
GenerateURLWithFields(path string, fields string) string
GenerateRawURL(path string, querystring string) string
}
// SetVersion is use to set the Facebook Graph API version
// and also the default Graph API url
func (g *Graph) SetVersion(version string) GraphInterface {
graphURL := `https://graph.facebook.com`
defaultVersion := `v2.10`
if version == "" {
version = defaultVersion
}
return &Graph{
Version: version,
URL: graphURL,
}
}
// GetVersion is use to get current version
// used by graph functions
func (g *Graph) GetVersion() string {
return g.Version
}
// GetGraphURL is use to get current graph API URL
func (g *Graph) GetGraphURL() string {
return g.URL
}
// GenerateURL is use to generate a URL
// to be used when requesting to Facebook Graph API
func (g *Graph) GenerateURL(path string) string {
return g.URL + `/` + g.Version + path
}
// GenerateURLWithFields is use to generate a URL
// to be used when accessing Facebook Graph API with `fields` as query string
func (g *Graph) GenerateURLWithFields(path string, fields string) string {
return g.GenerateURL(path) + `?fields=` + fields
}
// GenerateRawURL is use to generate a URL
// with raw query string
func (g *Graph) GenerateRawURL(path string, querystring string) string {
return g.GenerateURL(path) + querystring
}