-
Notifications
You must be signed in to change notification settings - Fork 56
/
media_test.go
78 lines (71 loc) · 1.52 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
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 := "http://www.google.com/intl/en/adwords/select/images/samples/inline.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("image1", "IMAGE", "IMAGE_JPEG", body),
NewImage("image2", "IMAGE", "IMAGE_JPEG", body),
},
)
if err != nil {
panic(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")
}
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
}
}
}