Skip to content

Commit 4f07c07

Browse files
committed
Update README.md
1 parent bb63b0c commit 4f07c07

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To run it, just use `make run`.
114114
Code Samples
115115
------------
116116

117-
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 DS3.
117+
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 DS3:
118118

119119
```c
120120

@@ -177,7 +177,7 @@ int main (int args, char * argv[]) {
177177
printf("No buckets returned\n");
178178
ds3_free_creds(creds);
179179
ds3_free_client(client);
180-
return 1;
180+
return 0;
181181
}
182182

183183
for (i = 0; i < response->num_buckets; i++) {
@@ -239,3 +239,75 @@ int main (int args, char * argv[]) {
239239
return 0;
240240
}
241241
```
242+
243+
The following is an example of performing a get bucket:
244+
245+
```c
246+
247+
ds3_get_bucket_response *response;
248+
uint64_t i;
249+
250+
// Setup client credentials and then the actual client itself.
251+
ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
252+
ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
253+
254+
// You can optionally set a proxy server that a request should be sent through
255+
//ds3_client_proxy(client, "192.168.56.1:8888");
256+
257+
char * bucket = "books";
258+
259+
// Create the get bucket request.
260+
ds3_request* request = ds3_init_get_bucket(bucket);
261+
262+
// This performs the request to a DS3 appliance.
263+
// If there is an error 'error' will not be NULL
264+
// If the request completed successfully then 'error' will be NULL
265+
ds3_error* error = ds3_get_bucket(client, request, &response);
266+
ds3_free_request(request);
267+
268+
// Check that the request completed successfully
269+
if(error != NULL) {
270+
if(error->error != NULL) {
271+
printf("Got an error (%lu): %s\n", error->error->status_code, error->message);
272+
printf("Message Body: %s\n", error->error->error_body);
273+
}
274+
else {
275+
printf("Got a runtime error: %s\n", error->message);
276+
}
277+
ds3_free_error(error);
278+
ds3_free_creds(creds);
279+
ds3_free_client(client);
280+
return 1;
281+
}
282+
283+
if (response == NULL) {
284+
printf("Response was null\n");
285+
ds3_free_creds(creds);
286+
ds3_free_client(client);
287+
return 1;
288+
}
289+
290+
if(response->num_objects == 0) {
291+
printf("No objects returned\n");
292+
ds3_free_bucket_response(response);
293+
ds3_free_creds(creds);
294+
ds3_free_client(client);
295+
return 0;
296+
}
297+
298+
for (i = 0; i < response->num_objects; i++) {
299+
ds3_object object = response->objects[i];
300+
printf("Object: (%s) created on %s\n", object.name, object.last_modified);
301+
}
302+
303+
ds3_free_bucket_response(response);
304+
305+
ds3_free_creds(creds);
306+
ds3_free_client(client);
307+
ds3_cleanup();
308+
return 0;
309+
}
310+
```
311+
312+
The structure of the code is very similar to the previous examples. Setup the client, setup the call, perform the call. Every request follows this same pattern. Things get a little more complicated with the bulk get/put cases. The following bulk put will demonstrate some of those complexities
313+

0 commit comments

Comments
 (0)