forked from emiddleton/gads
-
Notifications
You must be signed in to change notification settings - Fork 1
/
media_test.go
79 lines (72 loc) · 1.56 KB
/
media_test.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
package gads
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func testMediaService(t *testing.T) (service *MediaService) {
return &MediaService{Auth: testAuthSetup(t)}
}
func TestMedia(t *testing.T) {
// load image into []byte
imageUrl := "https://orig00.deviantart.net/7088/f/2009/240/5/8/582121d950a606ed47bda5e181a770af.jpg"
resp, err := http.Get(imageUrl)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
ms := testMediaService(t)
images, err := ms.Upload(
[]Media{
NewImage("image3", "IMAGE", "IMAGE_JPEG", body),
NewImage("image4", "IMAGE", "IMAGE_JPEG", body),
},
)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%#v", images)
var pageSize int64 = 500
var offset int64 = 0
paging := Paging{
Offset: offset,
Limit: pageSize,
}
for {
medias, totalCount, err := ms.Get(
Selector{
Fields: []string{
"MediaId",
"Height",
"Width",
"MimeType",
"Urls",
},
Predicates: []Predicate{
{"Type", "IN", []string{"IMAGE", "VIDEO"}},
},
Paging: &paging,
},
)
if err != nil {
fmt.Printf("Error occured finding medias")
t.Fatal(err)
}
for _, m := range medias {
for _, d := range m.Dimensions {
if d.Name == "FULL" {
//fmt.Printf("Entry ID %d with dimensions %dx%d and MIME type is '%s'\n", m.Id, d.Height, d.Width, m.MimeType)
}
}
}
// Increment values to request the next page.
offset += pageSize
paging.Offset = offset
if totalCount < offset {
//fmt.Printf("\tFound %d entries.", totalCount)
break
}
}
}