Skip to content

Commit dc0c0fb

Browse files
authored
Merge pull request #118 from SpectraLogic/DenverM80-patch-1
Update README.md
2 parents 8c46848 + 4b13e08 commit dc0c0fb

File tree

1 file changed

+55
-86
lines changed

1 file changed

+55
-86
lines changed

README.md

Lines changed: 55 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -163,110 +163,81 @@ Code Samples
163163
The following section contains several examples of using the DS3 C SDK. The first example shows how to get a list of all the buckets back from Spectra S3:
164164

165165
```c
166-
167166
#include <stdlib.h>
168-
#include <string.h>
169-
#include <stdint.h>
170167
#include <stdio.h>
171-
#include <sys/types.h>
172-
#include <sys/stat.h>
173168
// "ds3.h" is the only header that needs to be included to use the DS3 API.
174169
#include "ds3.h"
175170

176-
int main (int args, char * argv[]) {
177-
// Allocate space for the response pointer.
178-
// The DS3 client library will end up consuming this.
179-
ds3_get_service_response *response;
180-
uint64_t i;
171+
int main (void) {
172+
// Get Service
173+
ds3_client* client;
174+
ds3_request* request;
175+
ds3_error* error;
176+
ds3_list_all_my_buckets_result_response *response;
177+
uint64_t bucket_index;
178+
179+
// Create a client from environment variables
180+
error = ds3_create_client_from_env(&client);
181+
handle_error(error);
181182

182-
// Setup client credentials and then the actual client itself.
183-
ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
184-
ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
185-
186-
// You can optionally set a proxy server that a request should be sent through
187-
//ds3_client_proxy(client, "192.168.56.1:8888");
188-
189183
// Create the get service request. All requests to a DS3 appliance start this way.
190184
// All ds3_init_* functions return a ds3_request struct
191-
192-
ds3_request* request = ds3_init_get_service();
193-
185+
request = ds3_init_get_service_request();
186+
194187
// This performs the request to a DS3 appliance.
195188
// If there is an error 'error' will not be NULL
196189
// If the request completed successfully then 'error' will be NULL
197-
ds3_error* error = ds3_get_service(client, request, &response);
198-
ds3_free_request(request);
199-
200-
// Check that the request completed successfully
201-
if(error != NULL) {
202-
if(error->error != NULL) {
203-
printf("Got an error (%lu): %s\n", error->error->status_code, error->message->value);
204-
printf("Message Body: %s\n", error->error->error_body->value);
205-
}
206-
else {
207-
printf("Got a runtime error: %s\n", error->message->value);
208-
}
209-
ds3_free_error(error);
210-
ds3_free_creds(creds);
211-
ds3_free_client(client);
212-
return 1;
213-
}
214-
215-
if (response == NULL) {
216-
printf("Response was null\n");
217-
ds3_free_creds(creds);
218-
ds3_free_client(client);
219-
return 1;
220-
}
190+
error = ds3_get_service_request(client, request, &response);
191+
ds3_request_free(request);
192+
handle_error(error);
221193

222194
if(response->num_buckets == 0) {
223195
printf("No buckets returned\n");
224-
ds3_free_creds(creds);
225-
ds3_free_client(client);
196+
ds3_list_all_my_buckets_result_response_free(response);
197+
ds3_creds_free(client->creds);
198+
ds3_client_free(client);
226199
return 0;
227200
}
228201

229-
for (i = 0; i < response->num_buckets; i++) {
230-
ds3_bucket bucket = response->buckets[i];
231-
printf("Bucket: (%s) created on %s\n", bucket.name->value, bucket.creation_date->value);
202+
for (bucket_index = 0; bucket_index < response->num_buckets; bucket_index++) {
203+
ds3_bucket_details_response* bucket = response->buckets[bucket_index];
204+
printf("Bucket: (%s) created on %s\n", bucket->name->value, bucket->creation_date->value);
232205
}
233-
234-
ds3_free_service_response(response);
235206

236-
ds3_free_creds(creds);
237-
ds3_free_client(client);
207+
ds3_list_all_my_buckets_result_response_free(response);
208+
ds3_creds_free(client->creds);
209+
ds3_client_free(client);
238210
ds3_cleanup();
239-
211+
240212
return 0;
241213
}
242214

215+
243216
```
244217
245218
The next demonstrates how to create a new bucket:
246219
247220
```c
248221
249222
#include <stdlib.h>
250-
#include <string.h>
251-
#include <stdint.h>
252223
#include <stdio.h>
253-
#include <sys/types.h>
254-
#include <sys/stat.h>
224+
// "ds3.h" is the only header that needs to be included to use the DS3 API.
255225
#include "ds3.h"
256226
257227
int main (int args, char * argv[]) {
258228
ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
259229
ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
260230
261231
char * bucket = "books";
262-
ds3_request * create_bucket_request = ds3_init_put_bucket(bucket);
263-
ds3_error* error = ds3_put_bucket(client, create_bucket_request);
264-
ds3_free_request(create_bucket_request);
232+
ds3_request * create_bucket_request = ds3_init_put_bucket_request(bucket_name);
233+
ds3_error* error = ds3_put_bucket_request(client, create_bucket_request);
234+
ds3_request_free(create_bucket_request);
265235
266236
if(error != NULL) {
267237
if(error->error != NULL) {
268-
printf("Failed to create bucket with error (%lu): %s\n", error->error->status_code, error->message->value);
269-
printf("Message Body: %s\n", error->error->error_body->value);
238+
printf("Failed to create bucket with error (%lu): %s\n", error->error->http_error_code, error->message->value);
239+
printf("Message Body: %s\n", error->error->message->value);
240+
printf("Resource: %s\n", error->error->resource->value);
270241
}
271242
else {
272243
printf("Got a runtime error: %s\n", error->message->value);
@@ -291,16 +262,12 @@ The following is an example of performing a get bucket:
291262
```c
292263

293264
#include <stdlib.h>
294-
#include <string.h>
295-
#include <stdint.h>
296265
#include <stdio.h>
297-
#include <sys/types.h>
298-
#include <sys/stat.h>
299266
// "ds3.h" is the only header that needs to be included to use the DS3 API.
300267
#include "ds3.h"
301268

302269
int main (int args, char * argv[]) {
303-
ds3_get_bucket_response *response;
270+
ds3_list_bucket_result_response* response;
304271
uint64_t i;
305272

306273
// Setup client credentials and then the actual client itself.
@@ -318,48 +285,50 @@ int main (int args, char * argv[]) {
318285
// This performs the request to a DS3 appliance.
319286
// If there is an error 'error' will not be NULL
320287
// If the request completed successfully then 'error' will be NULL
321-
ds3_error* error = ds3_get_bucket(client, request, &response);
322-
ds3_free_request(request);
288+
ds3_error* error = ds3_get_bucket_request(client, request, &response);
289+
ds3_request_free(request);
323290

324291
// Check that the request completed successfully
325292
if(error != NULL) {
326293
if(error->error != NULL) {
327-
printf("Got an error (%lu): %s\n", error->error->status_code, error->message->value);
328-
printf("Message Body: %s\n", error->error->error_body->value);
294+
printf("Failed to create bucket with error (%lu): %s\n", error->error->http_error_code, error->message->value);
295+
printf("Message Body: %s\n", error->error->message->value);
296+
printf("Resource: %s\n", error->error->resource->value);
329297
}
330298
else {
331299
printf("Got a runtime error: %s\n", error->message->value);
332300
}
333-
ds3_free_error(error);
334-
ds3_free_creds(creds);
335-
ds3_free_client(client);
301+
ds3_list_bucket_result_response_free(response);
302+
ds3_error_free(error);
303+
ds3_creds_free(creds);
304+
ds3_client_free(client);
336305
return 1;
337-
}
306+
}
338307

339308
if (response == NULL) {
340309
printf("Response was null\n");
341-
ds3_free_creds(creds);
342-
ds3_free_client(client);
310+
ds3_creds_free(creds);
311+
ds3_client_free(client);
343312
return 1;
344313
}
345314

346315
if(response->num_objects == 0) {
347316
printf("No objects returned\n");
348-
ds3_free_bucket_response(response);
349-
ds3_free_creds(creds);
350-
ds3_free_client(client);
317+
ds3_list_bucket_result_response_free(response);
318+
ds3_creds_free(creds);
319+
ds3_client_free(client);
351320
return 0;
352321
}
353322

354323
for (i = 0; i < response->num_objects; i++) {
355-
ds3_object object = response->objects[i];
356-
printf("Object: (%s) created on %s\n", object.name->value, object.last_modified->value);
324+
ds3_contents_response* object = response->objects[i];
325+
printf("Object: (%s) created on %s\n", object->name->value, object->last_modified->value);
357326
}
358327

359-
ds3_free_bucket_response(response);
328+
ds3_list_bucket_result_response_free(response);
360329

361-
ds3_free_creds(creds);
362-
ds3_free_client(client);
330+
ds3_creds_free(creds);
331+
ds3_client_free(client);
363332
ds3_cleanup();
364333
return 0;
365334
}

0 commit comments

Comments
 (0)