@@ -99,7 +99,7 @@ compiler tags using the following commands:
9999Sample
100100------
101101
102- The ` /sample ` directory has an example of using the sdk. It provides a Makefile
102+ The ` /sample ` directory has an example project that uses the sdk. It provides a Makefile
103103to build the SDK and itself.
104104
105105To build the sample, use the following commands:
@@ -111,3 +111,75 @@ To build the sample, use the following commands:
111111
112112To run it, just use ` make run ` .
113113
114+ Code Samples
115+ ------------
116+
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.
118+
119+ ``` c
120+
121+ #include < stdlib.h>
122+ #include < string.h>
123+ #include < stdint.h>
124+ #include < stdio.h>
125+ #include < sys/types.h>
126+ #include < sys/stat.h>
127+ #include " ds3.h"
128+
129+ int main (int args, char * argv[ ] ) {
130+ ds3_get_service_response * response;
131+ uint64_t i;
132+
133+ ds3_creds * creds = ds3_create_creds("cnlhbg==","ZIjGDQAs");
134+ ds3_client * client = ds3_create_client("http://192.168.56.101:8080", creds);
135+
136+ //ds3_client_proxy(client, "192.168.56.1:8888");
137+
138+ ds3_request* request = ds3_init_get_service();
139+ ds3_error* error = ds3_get_service(client, request, &response);
140+ ds3_free_request(request);
141+
142+ if(error != NULL) {
143+ if(error->error != NULL) {
144+ printf("Got an error (%lu): %s\n", error->error->status_code, error->message);
145+ printf("Message Body: %s\n", error->error->error_body);
146+ }
147+ else {
148+ printf("Got a runtime error: %s\n", error->message);
149+ }
150+ ds3_free_error(error);
151+ ds3_free_creds(creds);
152+ ds3_free_client(client);
153+ return 1;
154+ }
155+
156+ if (response == NULL) {
157+ printf("Response was null\n");
158+ ds3_free_creds(creds);
159+ ds3_free_client(client);
160+ return 1;
161+ }
162+
163+ if(response->num_buckets == 0) {
164+ printf("No buckets returned\n");
165+ ds3_free_creds(creds);
166+ ds3_free_client(client);
167+ return 1;
168+ }
169+
170+ for (i = 0; i < response->num_buckets; i++) {
171+ ds3_bucket bucket = response->buckets[i];
172+ printf("Bucket: (%s) created on %s\n", bucket.name, bucket.creation_date);
173+ }
174+
175+ ds3_free_service_response(response);
176+
177+ ds3_free_creds(creds);
178+ ds3_free_client(client);
179+ ds3_cleanup();
180+
181+ return 0;
182+ }
183+
184+ ```
185+
0 commit comments