@@ -114,7 +114,7 @@ To run it, just use `make run`.
114114Code 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 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
@@ -124,21 +124,34 @@ The following section contains several examples of using the DS3 C SDK. The fir
124124#include < stdio.h>
125125#include < sys/types.h>
126126#include < sys/stat.h>
127+ // "ds3.h" is the only header that needs to be included to use the DS3 API.
127128#include " ds3.h"
128129
129130int main (int args, char * argv[ ] ) {
131+ // Allocate space for the response pointer.
132+ // The DS3 client library will end up consuming this.
130133 ds3_get_service_response * response;
131134 uint64_t i;
132135
136+ // Setup client credentials and then the actual client itself.
133137 ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
134138 ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
135139
140+ // You can optionally set a proxy server that a request should be sent through
136141 //ds3_client_proxy(client, "192.168.56.1:8888");
137142
143+ // Create the get service request. All requests to a DS3 appliance start this way.
144+ // All ds3_init_* functions return a ds3_request struct
145+
138146 ds3_request* request = ds3_init_get_service();
147+
148+ // This performs the request to a DS3 appliance.
149+ // If there is an error 'error' will not be NULL
150+ // If the request completed successfully then 'error' will be NULL
139151 ds3_error* error = ds3_get_service(client, request, &response);
140152 ds3_free_request(request);
141153
154+ // Check that the request completed successfully
142155 if(error != NULL) {
143156 if(error->error != NULL) {
144157 printf("Got an error (%lu): %s\n", error->error->status_code, error->message);
@@ -183,3 +196,46 @@ int main (int args, char * argv[]) {
183196
184197```
185198
199+ The next demonstrates how to create a new bucket:
200+
201+ ```c
202+
203+ #include <stdlib.h>
204+ #include <string.h>
205+ #include <stdint.h>
206+ #include <stdio.h>
207+ #include <sys/types.h>
208+ #include <sys/stat.h>
209+ #include "ds3.h"
210+
211+ int main (int args, char * argv[]) {
212+ ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
213+ ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
214+
215+ char * bucket = "books";
216+ ds3_request * create_bucket_request = ds3_init_put_bucket(bucket);
217+ ds3_error* error = ds3_put_bucket(client, create_bucket_request);
218+ ds3_free_request(create_bucket_request);
219+
220+ if(error != NULL) {
221+ if(error->error != NULL) {
222+ printf("Failed to create bucket with error (%lu): %s\n", error->error->status_code, error->message);
223+ printf("Message Body: %s\n", error->error->error_body);
224+ }
225+ else {
226+ printf("Got a runtime error: %s\n", error->message);
227+ }
228+ ds3_free_error(error);
229+ ds3_free_creds(creds);
230+ ds3_free_client(client);
231+ return 1;
232+ }
233+
234+ printf("Successfully created bucket: %s\n", bucket);
235+ ds3_free_creds(creds);
236+ ds3_free_client(client);
237+ ds3_cleanup();
238+
239+ return 0;
240+ }
241+ ```
0 commit comments