This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreative.go
77 lines (63 loc) · 1.65 KB
/
creative.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
package fbintegration
import (
"fmt"
"strings"
facebookLib "github.com/huandu/facebook"
)
const videoType = "VIDEO"
type (
// Creative comment pending
Creative struct {
ID string `facebook:"id"`
ObjectStorySpec CreativeObjectStorySpec `facebook:"object_story_spec"`
ObjectType string `facebook:"object_type"`
PostID string `facebook:"effective_object_story_id"`
}
// CreativeObjectStorySpec comment pending
CreativeObjectStorySpec struct {
VideoData CreativeObjectVideoData `facebook:"video_data"`
}
// CreativeObjectVideoData comment pending
CreativeObjectVideoData struct {
VideoID string `facebook:"video_id"`
Description string `facebook:"description"`
}
)
// NewCreativeFromResult comment pending
func NewCreativeFromResult(result facebookLib.Result) Creative {
var creative Creative
result.DecodeField("", &creative)
return creative
}
// GenerateParams comments pending
func (c *Creative) GenerateParams() BatchParams {
fields := []string{
"object_id",
"object_type",
"effective_object_story_id",
"object_story_spec",
}
uri := fmt.Sprintf("%s?fields=%s", c.ID, strings.Join(fields, ","))
return NewBatchParams(uri)
}
// IsVideo comment pending
func (c *Creative) IsVideo() bool {
if c.ObjectType == videoType {
return true
}
return false
}
// HasObjectID comment pending
func (c Creative) HasObjectID() bool {
if c.ObjectStorySpec.VideoData.VideoID != "" {
return true
}
return false
}
// ObjectID comment pending
func (c Creative) ObjectID() string {
if c.HasObjectID() {
return c.ObjectStorySpec.VideoData.VideoID
}
return ""
}