Repository: cloudflare/cloudflare-go
Pull request #1457 (2023-12-04 19:11:18)

Add support for scheduledDeletion
<!-- 
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points. 
-->

## Description
Added `scheduledDeletion` field to following structures according to: 

[Upload videos from a URL](https://developers.cloudflare.com/api/operations/stream-videos-upload-videos-from-a-url)
[Upload videos via direct upload URLs](https://developers.cloudflare.com/api/operations/stream-videos-upload-videos-via-direct-upload-ur-ls)


1. `StreamVideo`
2. `StreamUploadFromURLParameters`
3. `StreamCreateVideoParameters`
4. `StreamVideoCreate`

<!--
Describe your changes in detail through motivation and context. Why is
this change required? What problem does it solve? If it fixes an open
issue, link to the issue using GitHub's closing issues keywords[1].
-->
## Has your change been tested?
Added the related field to test files

<!--
Explain how the change has been tested and what you ran to confirm your
change affects other parts of the code. Automated tests are generally
expected and changes without tests should explain why they aren't
required.
-->

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1457.txt b/.changelog/1457.txt
new file mode 100644
index 000000000..86f0914cb
--- /dev/null
+++ b/.changelog/1457.txt
@@ -0,0 +1,15 @@
+```release-note:enhancement
+stream: Add ScheduledDeletion to StreamVideo
+```
+
+```release-note:enhancement
+stream: Add ScheduledDeletion to StreamUploadFromURLParameters
+```
+
+```release-note:enhancement
+stream: Add ScheduledDeletion to StreamCreateVideoParameters
+```
+
+```release-note:enhancement
+stream: Add ScheduledDeletion to StreamVideoCreate
+```
\ No newline at end of file
diff --git a/stream.go b/stream.go
index a2cae8dd9..ebb175cb8 100644
--- a/stream.go
+++ b/stream.go
@@ -66,6 +66,7 @@ type StreamVideo struct {
 	Creator               string                   `json:"creator,omitempty"`
 	LiveInput             string                   `json:"liveInput,omitempty"`
 	Uploaded              *time.Time               `json:"uploaded,omitempty"`
+	ScheduledDeletion     *time.Time               `json:"scheduledDeletion,omitempty"`
 	Watermark             StreamVideoWatermark     `json:"watermark,omitempty"`
 	NFT                   StreamVideoNFTParameters `json:"nft,omitempty"`
 }
@@ -124,6 +125,7 @@ type StreamUploadFromURLParameters struct {
 	RequireSignedURLs     bool                    `json:"requireSignedURLs,omitempty"`
 	Watermark             UploadVideoURLWatermark `json:"watermark,omitempty"`
 	Meta                  map[string]interface{}  `json:"meta,omitempty"`
+	ScheduledDeletion     *time.Time              `json:"scheduledDeletion,omitempty"`
 }
 
 // StreamCreateVideoParameters are parameters used when creating a video.
@@ -137,6 +139,7 @@ type StreamCreateVideoParameters struct {
 	RequireSignedURLs     bool                    `json:"requireSignedURLs,omitempty"`
 	Watermark             UploadVideoURLWatermark `json:"watermark,omitempty"`
 	Meta                  map[string]interface{}  `json:"meta,omitempty"`
+	ScheduledDeletion     *time.Time              `json:"scheduledDeletion,omitempty"`
 }
 
 // UploadVideoURLWatermark represents UID of an existing watermark.
@@ -146,9 +149,10 @@ type UploadVideoURLWatermark struct {
 
 // StreamVideoCreate represents parameters returned after creating a video.
 type StreamVideoCreate struct {
-	UploadURL string               `json:"uploadURL,omitempty"`
-	UID       string               `json:"uid,omitempty"`
-	Watermark StreamVideoWatermark `json:"watermark,omitempty"`
+	UploadURL         string               `json:"uploadURL,omitempty"`
+	UID               string               `json:"uid,omitempty"`
+	Watermark         StreamVideoWatermark `json:"watermark,omitempty"`
+	ScheduledDeletion *time.Time           `json:"scheduledDeletion,omitempty"`
 }
 
 // StreamParameters are the basic parameters needed.
@@ -159,9 +163,10 @@ type StreamParameters struct {
 
 // StreamUploadFileParameters are parameters needed for file upload of a video.
 type StreamUploadFileParameters struct {
-	AccountID string
-	VideoID   string
-	FilePath  string
+	AccountID         string
+	VideoID           string
+	FilePath          string
+	ScheduledDeletion *time.Time
 }
 
 // StreamListParameters represents parameters used when listing stream videos.


Test patch:
diff --git a/stream_test.go b/stream_test.go
index d42b941a4..fec0d4cc0 100644
--- a/stream_test.go
+++ b/stream_test.go
@@ -69,7 +69,8 @@ const (
     "nft": {
       "contract": "0x57f1887a8bf19b14fc0d912b9b2acc9af147ea85",
       "token": 5
-    }
+    },
+	"scheduledDeletion": "2014-01-02T02:20:00Z"
   }
 }
 `
@@ -85,6 +86,8 @@ func createTestVideo() StreamVideo {
 	modified, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
 	uploadexpiry, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
 	uploaded, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+	scheduledDuration, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+
 	return StreamVideo{
 		AllowedOrigins:     []string{"example.com"},
 		Created:            &created,
@@ -130,6 +133,7 @@ func createTestVideo() StreamVideo {
 			Token:    5,
 			Contract: "0x57f1887a8bf19b14fc0d912b9b2acc9af147ea85",
 		},
+		ScheduledDeletion: &scheduledDuration,
 	}
 }
 
@@ -155,6 +159,8 @@ func TestStream_StreamUploadFromURL(t *testing.T) {
 		assert.Equal(t, ErrMissingUploadURL, err)
 	}
 
+	scheduledDuration, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+
 	want := TestVideoStruct
 	input := StreamUploadFromURLParameters{
 		AccountID: testAccountID,
@@ -162,6 +168,7 @@ func TestStream_StreamUploadFromURL(t *testing.T) {
 		Meta: map[string]interface{}{
 			"name": "My First Stream Video",
 		},
+		ScheduledDeletion: &scheduledDuration,
 	}
 
 	out, err := client.StreamUploadFromURL(context.Background(), input)
@@ -192,7 +199,15 @@ func TestStream_UploadVideoFile(t *testing.T) {
 		assert.Equal(t, ErrMissingFilePath, err)
 	}
 
-	input := StreamUploadFileParameters{AccountID: testAccountID, VideoID: testVideoID, FilePath: "stream_test.go"}
+	scheduledDuration, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+
+	input := StreamUploadFileParameters{
+		AccountID:         testAccountID,
+		VideoID:           testVideoID,
+		FilePath:          "stream_test.go",
+		ScheduledDeletion: &scheduledDuration,
+	}
+
 	out, err := client.StreamUploadVideoFile(context.Background(), input)
 
 	want := TestVideoStruct
@@ -228,7 +243,8 @@ func TestStream_CreateVideoDirectURL(t *testing.T) {
       "padding": 0.1,
       "scale": 0.1,
       "position": "center"
-    }
+    },
+	"scheduledDeletion": "2014-01-02T02:20:00Z"
   }
 }
 `)
@@ -248,12 +264,21 @@ func TestStream_CreateVideoDirectURL(t *testing.T) {
 		assert.Equal(t, ErrMissingMaxDuration, err)
 	}
 
-	input := StreamCreateVideoParameters{AccountID: testAccountID, MaxDurationSeconds: 300, Meta: map[string]interface{}{
-		"name": "My First Stream Video",
-	}}
+	scheduledDuration, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+
+	input := StreamCreateVideoParameters{
+		AccountID:          testAccountID,
+		MaxDurationSeconds: 300,
+		Meta: map[string]interface{}{
+			"name": "My First Stream Video",
+		},
+		ScheduledDeletion: &scheduledDuration,
+	}
+
 	out, err := client.StreamCreateVideoDirectURL(context.Background(), input)
 
 	created, _ := time.Parse(time.RFC3339, "2014-01-02T02:20:00Z")
+
 	want := StreamVideoCreate{
 		UploadURL: "www.example.com/samplepath",
 		UID:       "ea95132c15732412d22c1476fa83f27a",
@@ -270,6 +295,7 @@ func TestStream_CreateVideoDirectURL(t *testing.T) {
 			Scale:          0.1,
 			Position:       "center",
 		},
+		ScheduledDeletion: &scheduledDuration,
 	}
 
 	if assert.NoError(t, err) {
@@ -341,7 +367,8 @@ func TestStream_ListVideos(t *testing.T) {
     "nft": {
       "contract": "0x57f1887a8bf19b14fc0d912b9b2acc9af147ea85",
       "token": 5
-    }
+    },
+ 	"scheduledDeletion": "2014-01-02T02:20:00Z"
   }]
 }
 `)