Skip to content

Commit 367d6c5

Browse files
committed
Throwing all of this on a branch so I can see it go through CI
1 parent d907f30 commit 367d6c5

File tree

13 files changed

+562
-20
lines changed

13 files changed

+562
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ on:
44
push:
55
branches:
66
- master
7-
pull_request:
8-
9-
# I appreciate this isn't the cleanest workflow, but it's the neatest I can get it while we're
10-
# still using dep to manage dependencies. If we move to go modules this can be cleaned up a lot.
11-
# I'd love to use a nicer checkout path, but GitHub actions won't let you use anything above
12-
# /home/runner/work/mux-go/mux-go/, so /home/runner/work/mux-go/mux-go/go it is!
7+
pull_request:
138

149
jobs:
1510
build:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Not familiar with Mux? Check out https://mux.com/ for more information.
1616
## Installation
1717

1818
```
19-
go get github.com/muxinc/mux-go/v6
19+
go get github.com/muxinc/mux-go/v5
2020
```
2121

2222
## Getting Started
@@ -48,7 +48,7 @@ import (
4848
"fmt"
4949
"os"
5050

51-
"github.com/muxinc/mux-go/v6"
51+
"github.com/muxinc/mux-go/v5"
5252
)
5353

5454
func main() {

configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ConfigurationOption func(*Configuration)
2222
func NewConfiguration(opts ...ConfigurationOption) *Configuration {
2323
cfg := &Configuration{
2424
basePath: "https://api.mux.com",
25-
userAgent: "Mux Go | 6.0.0",
25+
userAgent: "Mux Go | 6.0.1",
2626
}
2727
for _, opt := range opts {
2828
opt(cfg)

docs/Upload.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Name | Type | Description | Notes
66
**Id** | **string** | Unique identifier for the Direct Upload. | [optional]
77
**Timeout** | **int32** | Max time in seconds for the signed upload URL to be valid. If a successful upload has not occurred before the timeout limit, the direct upload is marked `timed_out` | [optional] [default to 3600]
88
**Status** | **string** | | [optional]
9-
**NewAssetSettings** | [**Asset**](Asset.md) | | [optional]
9+
**NewAssetSettings** | [**CreateAssetRequest**](CreateAssetRequest.md) | | [optional]
1010
**AssetId** | **string** | Only set once the upload is in the `asset_created` state. | [optional]
1111
**Error** | [**UploadError**](Upload_error.md) | | [optional]
1212
**CorsOrigin** | **string** | If the upload URL will be used in a browser, you must specify the origin in order for the signed URL to have the correct CORS headers. | [optional]
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
muxgo "github.com/muxinc/mux-go/v6"
9+
"github.com/muxinc/mux-go/v6/examples/common"
10+
)
11+
12+
func main() {
13+
14+
// API Client Initialization
15+
client := muxgo.NewAPIClient(
16+
muxgo.NewConfiguration(
17+
muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")),
18+
))
19+
20+
// ========== create-asset ==========
21+
asset, err := client.AssetsApi.CreateAsset(muxgo.CreateAssetRequest{
22+
Input: []muxgo.InputSettings{
23+
muxgo.InputSettings{
24+
Url: "https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4",
25+
},
26+
muxgo.InputSettings{
27+
Url: "https://tears-of-steel-subtitles.s3.amazonaws.com/tears-fr.vtt",
28+
TextType: "subtitles",
29+
Type: "text",
30+
LanguageCode: "fr",
31+
ClosedCaptions: false,
32+
Name: "French",
33+
},
34+
},
35+
NormalizeAudio: true,
36+
})
37+
common.AssertNoError(err)
38+
common.AssertNotNil(asset.Data)
39+
fmt.Println("create-asset OK ✅")
40+
41+
// ========== list-assets ==========
42+
lr, err := client.AssetsApi.ListAssets()
43+
common.AssertNoError(err)
44+
common.AssertNotNil(lr.Data)
45+
common.AssertStringEqualsValue(asset.Data.Id, lr.Data[0].Id)
46+
fmt.Println("list-assets OK ✅")
47+
48+
// Wait for the asset to become ready
49+
if asset.Data.Status != "ready" {
50+
fmt.Println(" Waiting for asset to become ready...")
51+
for {
52+
// ========== get-asset ==========
53+
gr, err := client.AssetsApi.GetAsset(asset.Data.Id)
54+
common.AssertNoError(err)
55+
common.AssertNotNil(gr)
56+
common.AssertStringEqualsValue(asset.Data.Id, gr.Data.Id)
57+
if gr.Data.Status != "ready" {
58+
fmt.Println(" Asset still not ready.")
59+
time.Sleep(1 * time.Second)
60+
} else {
61+
// ========== get-asset-input-info ==========
62+
ir, err := client.AssetsApi.GetAssetInputInfo(asset.Data.Id)
63+
common.AssertNoError(err)
64+
common.AssertNotNil(ir.Data)
65+
break
66+
}
67+
}
68+
}
69+
fmt.Println("get-asset OK ✅")
70+
fmt.Println("get-asset-input-info OK ✅")
71+
72+
// ========== clipping ==========
73+
clipAsset, err := client.AssetsApi.CreateAsset(muxgo.CreateAssetRequest{
74+
Input: []muxgo.InputSettings{
75+
muxgo.InputSettings{
76+
Url: "mux://assets/" + asset.Data.Id,
77+
StartTime: 0,
78+
EndTime: 5,
79+
},
80+
},
81+
})
82+
common.AssertNoError(err)
83+
common.AssertNotNil(clipAsset.Data.Id)
84+
fmt.Println("clipping OK ✅")
85+
86+
// ========== create-asset-playback-id ==========
87+
capr := muxgo.CreatePlaybackIdRequest{Policy: muxgo.PUBLIC}
88+
capre, err := client.AssetsApi.CreateAssetPlaybackId(asset.Data.Id, capr)
89+
common.AssertNoError(err)
90+
common.AssertNotNil(capre.Data)
91+
common.AssertStringEqualsValue(string(capre.Data.Policy), "public")
92+
fmt.Println("create-asset-playback-id OK ✅")
93+
94+
// ========== get-asset-playback-id ==========
95+
pbre, err := client.AssetsApi.GetAssetPlaybackId(asset.Data.Id, capre.Data.Id)
96+
common.AssertNoError(err)
97+
common.AssertNotNil(pbre.Data)
98+
common.AssertStringEqualsValue(capre.Data.Id, pbre.Data.Id)
99+
fmt.Println("get-asset-playback-id OK ✅")
100+
101+
// ========== get-asset-or-livestream-id =========
102+
playbackId := pbre.Data.Id
103+
pbResp, err := client.PlaybackIDApi.GetAssetOrLivestreamId(playbackId)
104+
common.AssertNoError(err)
105+
common.AssertNotNil(pbResp.Data)
106+
common.AssertStringEqualsValue(pbResp.Data.Object.Id, asset.Data.Id)
107+
common.AssertStringEqualsValue(pbResp.Data.Object.Type, "asset")
108+
fmt.Println("get-asset-or-livestream-id OK ✅")
109+
110+
// ========== update-asset-mp4-support ==========
111+
mp4r := muxgo.UpdateAssetMp4SupportRequest{Mp4Support: "standard"}
112+
mp4, err := client.AssetsApi.UpdateAssetMp4Support(asset.Data.Id, mp4r)
113+
common.AssertNoError(err)
114+
common.AssertNotNil(mp4.Data)
115+
common.AssertStringEqualsValue(asset.Data.Id, mp4.Data.Id)
116+
common.AssertStringEqualsValue(mp4.Data.Mp4Support, "standard")
117+
fmt.Println("update-asset-mp4-support OK ✅")
118+
119+
// ========== update-asset-master-access ==========
120+
mr := muxgo.UpdateAssetMasterAccessRequest{MasterAccess: "temporary"}
121+
mas, err := client.AssetsApi.UpdateAssetMasterAccess(asset.Data.Id, mr)
122+
common.AssertNoError(err)
123+
common.AssertNotNil(mas.Data)
124+
common.AssertStringEqualsValue(asset.Data.Id, mas.Data.Id)
125+
common.AssertStringEqualsValue(mas.Data.MasterAccess, "temporary")
126+
fmt.Println("update-asset-master-access OK ✅")
127+
128+
// ========== create-asset-track ==========
129+
cat := muxgo.CreateTrackRequest{
130+
Url: "https://tears-of-steel-subtitles.s3.amazonaws.com/tears-en.vtt",
131+
TextType: "subtitles",
132+
Type: "text",
133+
LanguageCode: "en",
134+
ClosedCaptions: false,
135+
Name: "English",
136+
}
137+
s, err := client.AssetsApi.CreateAssetTrack(asset.Data.Id, cat)
138+
common.AssertNoError(err)
139+
common.AssertNotNil(s.Data)
140+
common.AssertNotNil(s.Data.Id)
141+
common.AssertStringEqualsValue(s.Data.Name, "English")
142+
a2s, err := client.AssetsApi.GetAsset(asset.Data.Id)
143+
common.AssertIntEqualsValue(len(a2s.Data.Tracks), 4) // Audio, Video, French that we ingested with the asset, and the English we added here!
144+
fmt.Println("create-asset-track OK ✅")
145+
146+
// ========== delete-asset-track ==========
147+
time.Sleep(5 * time.Second)
148+
err = client.AssetsApi.DeleteAssetTrack(asset.Data.Id, s.Data.Id)
149+
common.AssertNoError(err)
150+
a1s, err := client.AssetsApi.GetAsset(asset.Data.Id)
151+
common.AssertIntEqualsValue(len(a1s.Data.Tracks), 3) // Audio, Video, French that we ingested with the asset
152+
fmt.Println("delete-asset-track OK ✅")
153+
154+
// ========== delete-asset-playback-id ==========
155+
err = client.AssetsApi.DeleteAssetPlaybackId(asset.Data.Id, capre.Data.Id)
156+
common.AssertNoError(err)
157+
dpba, err := client.AssetsApi.GetAsset(asset.Data.Id)
158+
common.AssertNoError(err)
159+
if len(dpba.Data.PlaybackIds) > 0 {
160+
fmt.Println("List of playback IDs wasn't empty")
161+
os.Exit(255)
162+
}
163+
fmt.Println("delete-asset-playback-id OK ✅")
164+
165+
// ========== delete-asset ==========
166+
err = client.AssetsApi.DeleteAsset(asset.Data.Id)
167+
common.AssertNoError(err)
168+
_, err = client.AssetsApi.GetAsset(asset.Data.Id)
169+
common.AssertNotNil(err)
170+
fmt.Println("delete-asset OK ✅")
171+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
muxgo "github.com/muxinc/mux-go/v6"
9+
"github.com/muxinc/mux-go/v6/examples/common"
10+
)
11+
12+
func main() {
13+
14+
t := int32(time.Now().Unix())
15+
fmt.Println(t)
16+
17+
// API Client Initialization
18+
client := muxgo.NewAPIClient(
19+
muxgo.NewConfiguration(
20+
muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")),
21+
))
22+
23+
// ========== list-delivery-usage ==========
24+
// OK, so here's the deal. Until we have actual meaningful data flowing into an account this is
25+
// really hard to to test, so instead I just create a timeframe that's valid and call the API.
26+
// We've manually verified this works during development.
27+
// To use specific times:
28+
// p := muxgo.ListDeliveryUsageParams{Timeframe: []string{"1574175600", "1574305200"}}
29+
// du, err := client.DeliveryUsageApi.ListDeliveryUsage(muxgo.WithParams(&p))
30+
// Default time window is 1 hour representing usage from 13th to 12th hour from when the request is made.
31+
du, err := client.DeliveryUsageApi.ListDeliveryUsage()
32+
common.AssertNoError(err)
33+
common.AssertNotNil(du.Data)
34+
fmt.Println("list-delivery-usage OK ✅")
35+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
muxgo "github.com/muxinc/mux-go/v6"
8+
"github.com/muxinc/mux-go/v6/examples/common"
9+
)
10+
11+
// Exercises all direct upload operations:
12+
// create-direct-upload
13+
// list-direct-uploads
14+
// get-direct-upload
15+
// cancel-direct-upload
16+
17+
func main() {
18+
19+
// API Client Initialization
20+
client := muxgo.NewAPIClient(
21+
muxgo.NewConfiguration(
22+
muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")),
23+
))
24+
25+
// ========== create-direct-upload ==========
26+
car := muxgo.CreateAssetRequest{PlaybackPolicy: []muxgo.PlaybackPolicy{muxgo.PUBLIC}}
27+
cur := muxgo.CreateUploadRequest{NewAssetSettings: car, Timeout: 3600, CorsOrigin: "philcluff.co.uk"}
28+
u, err := client.DirectUploadsApi.CreateDirectUpload(cur)
29+
common.AssertNoError(err)
30+
common.AssertNotNil(u.Data)
31+
fmt.Println("create-direct-upload OK ✅")
32+
33+
// ========== create-direct-upload ==========
34+
us, err := client.DirectUploadsApi.ListDirectUploads()
35+
common.AssertNoError(err)
36+
common.AssertNotNil(u.Data)
37+
common.AssertStringEqualsValue(u.Data.Id, us.Data[0].Id)
38+
fmt.Println("list-direct-uploads ✅")
39+
40+
// ========== get-direct-upload ==========
41+
ug, err := client.DirectUploadsApi.GetDirectUpload(u.Data.Id)
42+
common.AssertNoError(err)
43+
common.AssertNotNil(ug.Data)
44+
common.AssertStringEqualsValue(u.Data.Id, ug.Data.Id)
45+
fmt.Println("get-direct-upload ✅")
46+
47+
// ========== cancel-direct-upload ==========
48+
uc, err := client.DirectUploadsApi.CancelDirectUpload(u.Data.Id)
49+
common.AssertNoError(err)
50+
common.AssertNotNil(uc.Data)
51+
common.AssertStringEqualsValue(u.Data.Id, uc.Data.Id)
52+
common.AssertStringEqualsValue(uc.Data.Status, "cancelled")
53+
fmt.Println("cancel-direct-upload ✅")
54+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
muxgo "github.com/muxinc/mux-go/v6"
8+
)
9+
10+
func checkError(err error) {
11+
if err != nil {
12+
fmt.Printf("err: %s \n\n", err)
13+
os.Exit(255)
14+
}
15+
}
16+
17+
func main() {
18+
// API Client Init
19+
client := muxgo.NewAPIClient(
20+
muxgo.NewConfiguration(
21+
muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")),
22+
))
23+
24+
// List Assets
25+
fmt.Println("Listing Assets: \n")
26+
assets, err := client.AssetsApi.ListAssets()
27+
checkError(err)
28+
for _, asset := range assets.Data {
29+
fmt.Printf("Asset ID: %s\n", asset.Id)
30+
fmt.Printf("Status: %s\n", asset.Status)
31+
fmt.Printf("Duration: %f\n\n", asset.Duration)
32+
}
33+
34+
// List Live Streams
35+
fmt.Println("Listing Live Streams: \n")
36+
streams, err := client.LiveStreamsApi.ListLiveStreams()
37+
checkError(err)
38+
for _, stream := range streams.Data {
39+
fmt.Printf("Live Stream ID: %s\n", stream.Id)
40+
fmt.Printf("Status: %s\n", stream.Status)
41+
fmt.Printf("Stream Key: %s\n\n", stream.StreamKey)
42+
}
43+
44+
// List Direct Uploads
45+
fmt.Println("Listing Direct Uploads: \n")
46+
uploads, err := client.DirectUploadsApi.ListDirectUploads()
47+
checkError(err)
48+
for _, upload := range uploads.Data {
49+
fmt.Printf("Status: %s\n", upload.Status)
50+
fmt.Printf("New Asset ID: %s\n\n", upload.AssetId)
51+
}
52+
53+
// List URL Signing Keys
54+
fmt.Println("Listing URL Signing Keys: \n")
55+
keys, err := client.URLSigningKeysApi.ListUrlSigningKeys()
56+
for _, key := range keys.Data {
57+
fmt.Printf("Signing Key ID: %s\n\n", key.Id)
58+
}
59+
}

0 commit comments

Comments
 (0)