Permalink
Browse files

Supporting anonymous gist when the environment variable is not defined

  • Loading branch information...
1 parent e4bbcc5 commit c348534cc378df8dc981ea8b476c6923ba5921f6 @jrbasso committed Jul 8, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/gistit.c
View
@@ -10,6 +10,7 @@
#define ENV_ACCESS_TOKEN_KEY "GISTIT_TOKEN"
#define GITHUB_GIST_URL "https://api.github.com/gists?access_token=%s"
+#define GITHUB_GIST_URL_ANONYMOUS "https://api.github.com/gists"
struct github_response {
char *response_text;
@@ -116,20 +117,20 @@ struct github_response *github_submit(json_t *content)
curl = curl_easy_init();
if (curl) {
- token = getenv(ENV_ACCESS_TOKEN_KEY);
- if (token == NULL) {
- printf("Gist It! Token is not defined. Please define the %s environement\n", ENV_ACCESS_TOKEN_KEY);
- return NULL;
- }
-
response = (struct github_response *)malloc(1 * sizeof(struct github_response));
response->response_text = (char *)malloc(1 * sizeof(char));
response->response_text[0] = '\0';
response->length = 0;
headers = curl_slist_append(headers, "Content-Type: application/json");
- sprintf(url, GITHUB_GIST_URL, token);
+ token = getenv(ENV_ACCESS_TOKEN_KEY);
+ if (token != NULL) {
+ sprintf(url, GITHUB_GIST_URL, token);
+ } else {
+ sprintf(url, GITHUB_GIST_URL_ANONYMOUS);
+ }
+
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

0 comments on commit c348534

Please sign in to comment.