forked from justwatch/facebook-marketing-api-golang-sdk
/
types.go
124 lines (105 loc) · 2.96 KB
/
types.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package fb
import (
"encoding/json"
"fmt"
)
// ErrorContainer is a convenient type for embedding in other structs.
type ErrorContainer struct {
Error *Error `json:"error"`
}
// GetError returns an error if available.
func (ec *ErrorContainer) GetError() error {
if ec.Error != nil {
return ec.Error
}
return nil
}
type listResponse struct {
Paging
Data json.RawMessage `json:"data"`
}
type listElementsResponse struct {
Paging
Data []json.RawMessage `json:"data"`
}
// Error implements error.
type Error struct {
Message string `json:"message"`
Type string `json:"type"`
Code uint64 `json:"code"`
ErrorSubcode uint64 `json:"error_subcode"`
FbtraceID string `json:"fbtrace_id"`
IsTransient bool `json:"is_transient"`
ErrorUserTitle string `json:"error_user_title"`
ErrorUserMsg string `json:"error_user_msg"`
ErrorData json.RawMessage `json:"error_data"`
}
// IsNotFound returns whether the error is a fb error with specific code and subcode.
func IsNotFound(err error) bool {
e, ok := err.(*Error)
if !ok {
return false
}
if e == nil {
return false
}
return e.Code == 100 && e.ErrorSubcode == 33
}
// Error implements error.
func (e *Error) Error() string {
if e.ErrorUserMsg != "" {
return e.ErrorUserMsg
}
return fmt.Sprintf("facebook: type='%s' message='%s' error_user_title='%s'", e.Type, e.Message, e.ErrorUserTitle)
}
// TimeRange is the standard time range used by facebook.
type TimeRange struct {
Since string `json:"since"`
Until string `json:"until"`
}
// Paging is a convenient type for embedding in other structs.
type Paging struct {
Paging struct {
Cursors struct {
Before string `json:"before"`
After string `json:"after"`
} `json:"cursors"`
Next string `json:"next"`
} `json:"paging"`
}
// KeyValue represents a Facebook k/v entry in a API JSON response.
type KeyValue struct {
ActionType string `json:"action_type"`
Value json.Number `json:"value"`
}
// ID contains the ID field.
type ID struct {
ID string `json:"id"`
}
// MetadataContainer contains a graph APIs object metadata.
type MetadataContainer struct {
Metadata *Metadata `json:"metadata"`
}
// Metadata contains information about a graph API object.
type Metadata struct {
Type string `json:"type"`
Connections map[string]string `json:"connections"`
Fields []struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type,omitempty"`
} `json:"fields"`
}
// MinimalResponse contains some information about a object being updated.
type MinimalResponse struct {
ID string `json:"id"`
Success bool `json:"success"`
UpdatedTime Time `json:"updated_time"`
ErrorContainer
}
// SummaryContainer contains a summary with a total count of items.
type SummaryContainer struct {
Summary struct {
TotalCount uint64 `json:"total_count"`
} `json:"summary"`
}