/
GenericMediaDataBuilder.go
executable file
·90 lines (78 loc) · 2.29 KB
/
GenericMediaDataBuilder.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
package media
import (
"net/url"
"time"
"github.com/fatih/structs"
)
//Perhaps considering error returns if builder fails to add operation.
const genericMediaMetadataType int = 0
const MovieMetadataType int = 1
const TvShowMetadataType int = 2
const MusicTrackMetadataType int = 3
const PhotoMediaMetadataType int = 4
//genericMediaDataBuilder component for building up mediadatabuilders
type genericMediaDataBuilder struct {
standardMediaDataBuilder
imageURLs []string
subtitle *string
title *string
releaseDate *time.Time
}
//NewGenericMediaDataBuilder is a constructor for the media data builder class
func NewGenericMediaDataBuilder(contentID contentID, contentType contentType, sType streamType) (genericMediaDataBuilder, error) {
builder := genericMediaDataBuilder{}
builder.SetContentID(contentID)
builder.SetContentType(contentType)
builder.SetStreamType(sType)
return builder, nil
}
//SetImageURLs the display image slideshow urls for the media message
func (builder *genericMediaDataBuilder) SetImageURLs(imageURLs []string) {
for index := 0; index < len(imageURLs); index++ {
_, err := url.ParseRequestURI(imageURLs[index])
if err != nil {
return
}
}
builder.imageURLs = imageURLs
}
//SetTitle sets the builder's title
func (builder *genericMediaDataBuilder) SetTitle(title *string) {
builder.title = title
}
//SetSubtitleURL sets the builder's subtitle
func (builder *genericMediaDataBuilder) SetSubtitle(subtitle *string) {
builder.subtitle = subtitle
}
//SetReleaseDate sets release date for element.
func (builder *genericMediaDataBuilder) SetReleaseDate(releaseDate *time.Time) {
builder.releaseDate = releaseDate
}
func convertDateToISO8601(date *time.Time) *string {
if date == nil {
return nil
}
formatted := date.UTC().Format(time.RFC3339)
return &formatted
}
//Build returns a standard mediadata object from its current data.
func (builder *genericMediaDataBuilder) Build() (MediaData, error) {
date := convertDateToISO8601(builder.releaseDate)
metadata := genericMediaMetadata{
StandardMediaMetadata{
genericMediaMetadataType,
builder.title,
},
builder.imageURLs,
builder.subtitle,
date,
}
return MediaData{
builder.contentID,
builder.contentType,
builder.streamType,
builder.duration,
structs.Map(metadata),
builder.customData,
}, nil
}