Skip to content

Commit 7936fbc

Browse files
committed
simplify examples
1 parent aa44fa3 commit 7936fbc

1 file changed

Lines changed: 30 additions & 120 deletions

File tree

‎README.md‎

Lines changed: 30 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,12 @@ and then sent to the API for rendering.
8484
const Shotstack = require('shotstack-sdk');
8585

8686
const defaultClient = Shotstack.ApiClient.instance;
87-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
88-
const api = new Shotstack.EditApi();
89-
90-
let apiUrl = 'https://api.shotstack.io/stage';
87+
defaultClient.basePath = 'https://api.shotstack.io/stage';
9188

92-
if (!process.env.SHOTSTACK_KEY) {
93-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
94-
process.exit(1);
95-
}
96-
97-
if (process.env.SHOTSTACK_HOST) {
98-
apiUrl = process.env.SHOTSTACK_HOST;
99-
}
89+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
90+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
10091

101-
defaultClient.basePath = apiUrl;
102-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
92+
const api = new Shotstack.EditApi();
10393

10494
let videoAsset = new Shotstack.VideoAsset;
10595
videoAsset
@@ -133,12 +123,7 @@ api.postRender(edit).then((data) => {
133123
let id = data.response.id
134124

135125
console.log(message + '\n');
136-
console.log('>> Now check the progress of your render by running:');
137-
console.log('>> node examples/status.js ' + id);
138-
139-
}, (error) => {
140-
console.error('Request failed: ', error);
141-
process.exit(1);
126+
console.log('>> Render ID ' + id);
142127
});
143128
```
144129

@@ -151,28 +136,14 @@ the render, which can take several seconds to process.
151136
const Shotstack = require('shotstack-sdk');
152137

153138
const defaultClient = Shotstack.ApiClient.instance;
154-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
155-
const api = new Shotstack.EditApi();
156-
const id = process.argv[2];
139+
defaultClient.basePath = 'https://api.shotstack.io/stage';
157140

158-
if (!id) {
159-
console.log(">> Please provide the UUID of the render task (i.e. php examples/status.php 2abd5c11-0f3d-4c6d-ba20-235fc9b8e8b7)\n");
160-
process.exit(1);
161-
}
162-
163-
let apiUrl = 'https://api.shotstack.io/stage';
164-
165-
if (!process.env.SHOTSTACK_KEY) {
166-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
167-
process.exit(1);
168-
}
141+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
142+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
169143

170-
if (process.env.SHOTSTACK_HOST) {
171-
apiUrl = process.env.SHOTSTACK_HOST;
172-
}
144+
const api = new Shotstack.EditApi();
173145

174-
defaultClient.basePath = apiUrl;
175-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
146+
const id = "75143ec6-4b72-46f8-a67a-fd7284546935"; //use a valid render id
176147

177148
api.getRender(id, { data: false, merged: true }).then((data) => {
178149
let status = data.response.status;
@@ -187,9 +158,6 @@ api.getRender(id, { data: false, merged: true }).then((data) => {
187158
} else {
188159
console.log('>> Rendering in progress, please try again shortly.\n>> Note: Rendering may take up to 1 minute to complete.');
189160
}
190-
}, (error) => {
191-
console.error('Request failed or not found: ', error);
192-
process.exit(1);
193161
});
194162
```
195163

@@ -982,28 +950,14 @@ the render, which can take several seconds to process.
982950
const Shotstack = require('shotstack-sdk');
983951

984952
const defaultClient = Shotstack.ApiClient.instance;
985-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
986-
const api = new Shotstack.EditApi();
987-
const id = process.argv[2];
988-
989-
if (!id) {
990-
console.log(">> Please provide the UUID of the render task (i.e. php examples/status.php 2abd5c11-0f3d-4c6d-ba20-235fc9b8e8b7)\n");
991-
process.exit(1);
992-
}
993-
994-
let apiUrl = 'https://api.shotstack.io/stage';
953+
defaultClient.basePath = 'https://api.shotstack.io/stage';
995954

996-
if (!process.env.SHOTSTACK_KEY) {
997-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
998-
process.exit(1);
999-
}
955+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
956+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
1000957

1001-
if (process.env.SHOTSTACK_HOST) {
1002-
apiUrl = process.env.SHOTSTACK_HOST;
1003-
}
958+
const api = new Shotstack.EditApi();
1004959

1005-
defaultClient.basePath = apiUrl;
1006-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
960+
const id = "75143ec6-4b72-46f8-a67a-fd7284546935"; //use a valid render id
1007961

1008962
api.getRender(id, { data: false, merged: true }).then((data) => {
1009963
let status = data.response.status;
@@ -1018,9 +972,6 @@ api.getRender(id, { data: false, merged: true }).then((data) => {
1018972
} else {
1019973
console.log('>> Rendering in progress, please try again shortly.\n>> Note: Rendering may take up to 1 minute to complete.');
1020974
}
1021-
}, (error) => {
1022-
console.error('Request failed or not found: ', error);
1023-
process.exit(1);
1024975
});
1025976
```
1026977
## Inspecting Media
@@ -1034,28 +985,14 @@ The example below inspects (probes) a video hosted on GitHub and returns metadat
1034985
const Shotstack = require('shotstack-sdk');
1035986

1036987
const defaultClient = Shotstack.ApiClient.instance;
1037-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
1038-
const api = new Shotstack.EditApi();
1039-
const url = process.argv[2];
988+
defaultClient.basePath = 'https://api.shotstack.io/stage';
1040989

1041-
if (!url) {
1042-
console.log(">> Please provide the URL to a media file to inspect (i.e. php examples/probe.php https://github.com/shotstack/test-media/raw/main/captioning/scott-ko.mp4)\n");
1043-
process.exit(1);
1044-
}
1045-
1046-
let apiUrl = 'https://api.shotstack.io/stage';
1047-
1048-
if (!process.env.SHOTSTACK_KEY) {
1049-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
1050-
process.exit(1);
1051-
}
990+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
991+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
1052992

1053-
if (process.env.SHOTSTACK_HOST) {
1054-
apiUrl = process.env.SHOTSTACK_HOST;
1055-
}
993+
const api = new Shotstack.EditApi();
1056994

1057-
defaultClient.basePath = apiUrl;
1058-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
995+
const url = 'https://github.com/shotstack/test-media/raw/main/captioning/scott-ko.mp4';
1059996

1060997
api.probe(url).then((data) => {
1061998
data.response.metadata.streams.forEach(stream => {
@@ -1067,9 +1004,6 @@ api.probe(url).then((data) => {
10671004
console.log('Duration: ' + stream.duration + ' secs');
10681005
}
10691006
});
1070-
}, (error) => {
1071-
console.error('Request failed or not found: ', error);
1072-
process.exit(1);
10731007
});
10741008
```
10751009
## Probe Schemas
@@ -1103,23 +1037,14 @@ created for a render, i.e. video, thumb and poster. Each asset has a unique asse
11031037
const Shotstack = require('shotstack-sdk');
11041038

11051039
const defaultClient = Shotstack.ApiClient.instance;
1106-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
1107-
const api = new Shotstack.ServeApi();
1108-
const id = process.argv[2];
1109-
1110-
let apiUrl = 'https://api.shotstack.io/serve/stage';
1040+
defaultClient.basePath = 'https://api.shotstack.io/stage';
11111041

1112-
if (!process.env.SHOTSTACK_KEY) {
1113-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
1114-
process.exit(1);
1115-
}
1042+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
1043+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
11161044

1117-
if (process.env.SHOTSTACK_SERVE_HOST) {
1118-
apiUrl = process.env.SHOTSTACK_SERVE_HOST;
1119-
}
1045+
const api = new Shotstack.EditApi();
11201046

1121-
defaultClient.basePath = apiUrl;
1122-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
1047+
const id = '140924c6-077d-4334-a89f-94befcfc0155'; // Use a valid render ID
11231048

11241049
api.getAssetByRenderId(id).then((assets) => {
11251050
assets.data.forEach((asset) => {
@@ -1134,9 +1059,6 @@ api.getAssetByRenderId(id).then((assets) => {
11341059
console.log('>> Render ID: ' + asset.attributes.renderId);
11351060
}
11361061
});
1137-
}, (error) => {
1138-
console.error('Request failed or not found: ', error);
1139-
process.exit(1);
11401062
});
11411063
```
11421064
@@ -1148,23 +1070,14 @@ Every asset has a unique asset ID, the example below looks up an asset by its as
11481070
const Shotstack = require('shotstack-sdk');
11491071

11501072
const defaultClient = Shotstack.ApiClient.instance;
1151-
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
1152-
const api = new Shotstack.ServeApi();
1153-
const id = process.argv[2];
1154-
1155-
let apiUrl = 'https://api.shotstack.io/serve/stage';
1073+
defaultClient.basePath = 'https://api.shotstack.io/stage';
11561074

1157-
if (!process.env.SHOTSTACK_KEY) {
1158-
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
1159-
process.exit(1);
1160-
}
1075+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
1076+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
11611077

1162-
if (process.env.SHOTSTACK_SERVE_HOST) {
1163-
apiUrl = process.env.SHOTSTACK_SERVE_HOST;
1164-
}
1078+
const api = new Shotstack.EditApi();
11651079

1166-
defaultClient.basePath = apiUrl;
1167-
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
1080+
const id = 'ed43eae3-4825-4c03-979d-f7dc47b9997c'; // use a valid asset ID
11681081

11691082
api.getAsset(id).then((asset) => {
11701083
const status = asset.data.attributes.status;
@@ -1177,9 +1090,6 @@ api.getAsset(id).then((asset) => {
11771090
console.log('>> Asset ID: ' + asset.data.attributes.id);
11781091
console.log('>> Render ID: ' + asset.data.attributes.renderId);
11791092
}
1180-
}, (error) => {
1181-
console.error('Request failed or not found: ', error);
1182-
process.exit(1);
11831093
});
11841094
```
11851095

0 commit comments

Comments
 (0)