-
Notifications
You must be signed in to change notification settings - Fork 44
/
media.go
85 lines (82 loc) · 3.35 KB
/
media.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
package wordpress
import (
"fmt"
"net/http"
)
type MediaDetailsSizesItem struct {
File string `json:"file,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
MimeType string `json:"mime_type,omitempty"`
SourceURL string `json:"source_url,omitempty"`
}
type MediaDetailsSizes struct {
Thumbnail MediaDetailsSizesItem `json:"thumbnail,omitempty"`
Medium MediaDetailsSizesItem `json:"medium,omitempty"`
Large MediaDetailsSizesItem `json:"large,omitempty"`
SiteLogo MediaDetailsSizesItem `json:"site-logo,omitempty"`
}
type MediaDetails struct {
Raw string `json:"raw,omitempty"`
Rendered string `json:"rendered,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
File string `json:"file,omitempty"`
Sizes MediaDetailsSizes `json:"sizes,omitempty"`
ImageMeta map[string]interface{} `json:"image_meta,omitempty"`
}
type MediaUploadOptions struct {
Filename string
ContentType string
Data []byte
}
type Media struct {
ID int `json:"id,omitempty"`
Date string `json:"date,omitempty"`
DateGMT string `json:"date_gmt,omitempty"`
GUID GUID `json:"guid,omitempty"`
Link string `json:"link,omitempty"`
Modified string `json:"modified,omitempty"`
ModifiedGMT string `json:"modifiedGMT,omitempty"`
Password string `json:"password,omitempty"`
Slug string `json:"slug,omitempty"`
Status string `json:"status,omitempty"`
Type string `json:"type,omitempty"`
Title Title `json:"title,omitempty"`
Author int `json:"author,omitempty"`
MediaStatus string `json:"comment_status,omitempty"`
PingStatus string `json:"ping_status,omitempty"`
AltText string `json:"alt_text,omitempty"`
Caption string `json:"caption,omitempty"`
Description string `json:"description,omitempty"`
MediaType string `json:"media_type,omitempty"`
MediaDetails MediaDetails `json:"media_details,omitempty"`
Post int `json:"post,omitempty"`
SourceURL string `json:"source_url,omitempty"`
}
type MediaCollection struct {
client *Client
url string
}
func (col *MediaCollection) List(params interface{}) ([]Media, *http.Response, []byte, error) {
var media []Media
resp, body, err := col.client.List(col.url, params, &media)
return media, resp, body, err
}
func (col *MediaCollection) Create(options *MediaUploadOptions) (*Media, *http.Response, []byte, error) {
var created Media
resp, body, err := col.client.PostData(col.url, options.Data, options.ContentType, options.Filename, &created)
return &created, resp, body, err
}
func (col *MediaCollection) Get(id int, params interface{}) (*Media, *http.Response, []byte, error) {
var entity Media
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Get(entityURL, params, &entity)
return &entity, resp, body, err
}
func (col *MediaCollection) Delete(id int, params interface{}) (*Media, *http.Response, []byte, error) {
var deleted Media
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Delete(entityURL, params, &deleted)
return &deleted, resp, body, err
}