Example #1
0
/**
 * flickcurl_photos_geo_removeLocation:
 * @fc: flickcurl context
 * @photo_id: The id of the photo you want to remove location data from.
 * 
 * Removes the geo data associated with a photo.
 *
 * Implements flickr.photos.geo.removeLocation (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_geo_removeLocation(flickcurl* fc, const char* photo_id)
{
  xmlDocPtr doc = NULL;
  
  flickcurl_init_params(fc, 1);

  if(!photo_id)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.removeLocation"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  tidy:

  return fc->failed;
}
/**
 * flickcurl_photosets_comments_editComment:
 * @fc: flickcurl context
 * @comment_id: The id of the comment to edit.
 * @comment_text: Update the comment to this text.
 * 
 * Edit the text of a comment as the currently authenticated user.
 *
 * Implements flickr.photosets.comments.editComment (0.10)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_comments_editComment(flickcurl* fc,
                                         const char* comment_id,
                                         const char* comment_text)
{
  xmlDocPtr doc = NULL;
  int result = 1;
  
  flickcurl_init_params(fc, 1);

  if(!comment_id || !comment_text)
    return 1;

  flickcurl_add_param(fc, "comment_id", comment_id);
  flickcurl_add_param(fc, "comment_text", comment_text);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photosets.comments.editComment"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
/**
 * flickcurl_photosets_orderSets:
 * @fc: flickcurl context
 * @photoset_ids_array: Array of photoset IDs, ordered with the set to show first, first in the list. Any set IDs not given in the list will be set to appear at the end of the list, ordered by their IDs.
 *
 * Set the order of photosets for the calling user.
 *
 * Implements flickr.photosets.orderSets (0.13)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_orderSets(flickcurl* fc, const char** photoset_ids_array)
{
    const char* parameters[8][2];
    int count = 0;
    xmlDocPtr doc = NULL;
    int result = 1;
    char* photoset_ids;

    if(!photoset_ids_array)
        return 1;

    photoset_ids = flickcurl_array_join(photoset_ids_array, ',');
    parameters[count][0]  = "photoset_ids";
    parameters[count++][1]= photoset_ids;

    parameters[count][0]  = NULL;

    if(flickcurl_prepare(fc, "flickr.photosets.orderSets", parameters, count))
        goto tidy;

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

    result = 0;

tidy:
    if(fc->failed)
        result = 1;
    if(photoset_ids)
        free(photoset_ids);

    return result;
}
Example #4
0
/**
 * flickcurl_photosets_orderSets:
 * @fc: flickcurl context
 * @photoset_ids_array: Array of photoset IDs, ordered with the set to show first, first in the list. Any set IDs not given in the list will be set to appear at the end of the list, ordered by their IDs.
 *
 * Set the order of photosets for the calling user.
 *
 * Implements flickr.photosets.orderSets (0.13)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_orderSets(flickcurl* fc, const char** photoset_ids_array)
{
    xmlDocPtr doc = NULL;
    int result = 1;
    char* photoset_ids;

    flickcurl_init_params(fc);

    if(!photoset_ids_array)
        return 1;

    photoset_ids = flickcurl_array_join(photoset_ids_array, ',');
    flickcurl_add_param(fc, "photoset_ids", photoset_ids);

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.photosets.orderSets"))
        goto tidy;

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

    result = 0;

tidy:
    if(fc->failed)
        result = 1;
    if(photoset_ids)
        free(photoset_ids);

    return result;
}
Example #5
0
/**
 * flickcurl_photosets_delete:
 * @fc: flickcurl context
 * @photoset_id: The id of the photoset to delete. Must be owned by the calling user.
 *
 * Delete a photoset.
 *
 * Implements flickr.photosets.delete (0.13)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_delete(flickcurl* fc, const char* photoset_id)
{
    xmlDocPtr doc = NULL;

    flickcurl_init_params(fc);

    if(!photoset_id)
        return 1;

    flickcurl_add_param(fc, "photoset_id", photoset_id);

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.photosets.delete"))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

tidy:

    return fc->failed;
}
Example #6
0
/**
 * flickcurl_photosets_setPrimaryPhoto:
 * @fc: flickcurl context
 * @photoset_id: The id of the photoset to set primary photo to.
 * @photo_id: The id of the photo to set as primary.
 *
 * Set photoset primary photo
 *
 * Implements flickr.photosets.setPrimaryPhoto (1.19)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_setPrimaryPhoto(flickcurl* fc, const char* photoset_id,
                                    const char* photo_id)
{
    xmlDocPtr doc = NULL;
    int result = 1;

    flickcurl_init_params(fc);

    if(!photoset_id || !photo_id)
        return 1;

    flickcurl_add_param(fc, "photoset_id", photoset_id);
    flickcurl_add_param(fc, "photo_id", photo_id);

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.photosets.setPrimaryPhoto"))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

    result = 0;

tidy:
    if(fc->failed)
        result = 1;

    return result;
}
Example #7
0
/**
 * flickcurl_groups_pools_add:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to add to the group pool.
 * @group_id: The NSID of the group who's pool the photo is to be added to.
 * 
 * Add a photo to a group's pool.
 *
 * Implements flickr.groups.pools.add (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_groups_pools_add(flickcurl* fc, const char* photo_id,
                           const char* group_id)
{
  xmlDocPtr doc = NULL;
  int result = 1;
  
  flickcurl_init_params(fc);

  if(!photo_id || !group_id)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  flickcurl_add_param(fc, "group_id", group_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.groups.pools.add"))
    goto tidy;

  flickcurl_set_write(fc, 1);
  flickcurl_set_data(fc, (void*)"", 0);

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #8
0
/**
 * flickcurl_test_null:
 * @fc: flickcurl context
 * 
 * Null test
 *
 * Implements flickr.test.null (1.0)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_test_null(flickcurl* fc)
{
  const char* parameters[7][2];
  int count = 0;
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  
  parameters[count][0]  = NULL;

  if(flickcurl_prepare(fc, "flickr.test.null", parameters, count))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  return fc->failed;
}
Example #9
0
/**
 * flickcurl_interestingness_getList_params:
 * @fc: flickcurl context
 * @date: A specific date, formatted as YYYY-MM-DD, to return interesting photos for. (or NULL)
 * @list_params: #flickcurl_photos_list_params result parameters (or NULL)
 * 
 * Returns the list of interesting photos for the most recent day or a user-specified date.
 *
 * Optional extra type 'media' that will return an extra media = VALUE
 * for VALUE "photo" or "video".  API addition 2008-04-07.
 *
 * Return value: non-0 on failure
 **/
flickcurl_photos_list*
flickcurl_interestingness_getList_params(flickcurl* fc, const char* date,
                                         flickcurl_photos_list_params* list_params)
{
  flickcurl_photos_list* photos_list = NULL;
  const char* format = NULL;

  flickcurl_init_params(fc);

  /* API parameters */
  if(date) {
    flickcurl_add_param(fc, "date", date);
  }

  /* Photos List parameters */
  flickcurl_append_photos_list_params(fc, list_params, &format);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.interestingness.getList"))
    goto tidy;

  photos_list = flickcurl_invoke_photos_list(fc,
                                             (const xmlChar*)"/rsp/photos",
                                             format);

  tidy:
  if(fc->failed) {
    if(photos_list)
      flickcurl_free_photos_list(photos_list);
    photos_list = NULL;
  }

  return photos_list;
}
Example #10
0
/**
 * flickcurl_photos_notes_add:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to add a note to
 * @note_x: The left coordinate of the note
 * @note_y: The top coordinate of the note
 * @note_w: The width of the note
 * @note_h: The height of the note
 * @note_text: The description of the note
 * 
 * Add a note to a photo.
 *
 * Coordinates and sizes are in pixels, based on the 500px image size
 * shown on individual photo pages.
 *
 * Implements flickr.photos.notes.add (0.12)
 * 
 * Return value: note ID or NULL on failure
 **/
char*
flickcurl_photos_notes_add(flickcurl* fc, const char* photo_id,
                           int note_x, int note_y, int note_w, int note_h,
                           const char* note_text)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  char *id = NULL;
  char note_x_s[10];
  char note_y_s[10];
  char note_w_s[10];
  char note_h_s[10];
  
  flickcurl_init_params(fc);

  if(!photo_id || !note_text)
    return NULL;

  flickcurl_add_param(fc, "photo_id", photo_id);
  sprintf(note_x_s, "%d", note_x);
  flickcurl_add_param(fc, "note_x", note_x_s);
  sprintf(note_y_s, "%d", note_y);
  flickcurl_add_param(fc, "note_y", note_y_s);
  sprintf(note_w_s, "%d", note_w);
  flickcurl_add_param(fc, "note_w", note_w_s);
  sprintf(note_h_s, "%d", note_h);
  flickcurl_add_param(fc, "note_h", note_h_s);
  flickcurl_add_param(fc, "note_text", note_text);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.notes.add"))
    goto tidy;

  flickcurl_set_write(fc, 1);
  flickcurl_set_data(fc, (void*)"", 0);

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  id = flickcurl_xpath_eval(fc, xpathCtx, (const xmlChar*)"/rsp/note/@id");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    id = NULL;

  return id;
}
Example #11
0
/**
 * flickcurl_photos_transform_rotate:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to rotate.
 * @degrees: The amount of degrees by which to rotate the photo (clockwise) from it's current orientation. Valid values are 90, 180 and 270.
 * 
 * Rotate a photo.
 *
 * Implements flickr.photos.transform.rotate (0.13)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_transform_rotate(flickcurl* fc, const char* photo_id,
                                  int degrees)
{
  xmlDocPtr doc = NULL;
  char degrees_str[4];
  int result = 0;
  
  flickcurl_init_params(fc);

  if(!photo_id || !(degrees == 90 || degrees == 180 || degrees == 270))
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  sprintf(degrees_str, "%d", degrees);
  flickcurl_add_param(fc, "degrees", degrees_str);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.transform.rotate"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #12
0
/**
 * flickcurl_photos_notes_delete:
 * @fc: flickcurl context
 * @note_id: The id of the note to delete
 * 
 * Delete a note from a photo.
 *
 * Implements flickr.photos.notes.delete (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_notes_delete(flickcurl* fc, const char* note_id)
{
  xmlDocPtr doc = NULL;
  int result = 1;
  
  flickcurl_init_params(fc);

  if(!note_id)
    return 1;

  flickcurl_add_param(fc, "note_id", note_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.notes.delete"))
    goto tidy;

  flickcurl_set_write(fc, 1);
  flickcurl_set_data(fc, (void*)"", 0);

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #13
0
/**
 * flickcurl_photosets_delete:
 * @fc: flickcurl context
 * @photoset_id: The id of the photoset to delete. Must be owned by the calling user.
 *
 * Delete a photoset.
 *
 * Implements flickr.photosets.delete (0.13)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photosets_delete(flickcurl* fc, const char* photoset_id)
{
    const char* parameters[8][2];
    int count = 0;
    xmlDocPtr doc = NULL;

    if(!photoset_id)
        return 1;

    parameters[count][0]  = "photoset_id";
    parameters[count++][1]= photoset_id;

    parameters[count][0]  = NULL;

    if(flickcurl_prepare(fc, "flickr.photosets.delete", parameters, count))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

tidy:

    return fc->failed;
}
Example #14
0
/**
 * flickcurl_auth_getToken:
 * @fc: flickcurl context
 * @frob: frob string
 * 
 * Get the auth token for the given frob, if one has been attached.
 *
 * Implements flickr.auth.getToken (0.9)
 * Must be signed.
 * 
 * Return value: token string or NULL on failure
 **/
char*
flickcurl_auth_getToken(flickcurl* fc, const char* frob)
{
  const char * parameters[6][2];
  int count = 0;
  char *auth_token = NULL;
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  
  parameters[count][0]   = "frob";
  parameters[count++][1] = (char*)frob;

  parameters[count][0]   = NULL;

  flickcurl_set_sign(fc);

  if(flickcurl_prepare(fc, "flickr.auth.getToken", parameters, count))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;
  
  xpathCtx = xmlXPathNewContext(doc);
  if(xpathCtx) {
    auth_token = flickcurl_xpath_eval(fc, xpathCtx,
                                    (const xmlChar*)"/rsp/auth/token");
    xmlXPathFreeContext(xpathCtx);
  }

  tidy:

  return auth_token;
}
Example #15
0
/**
 * flickcurl_photos_licenses_setLicense:
 * @fc: flickcurl context
 * @photo_id: The photo to update the license for.
 * @license_id: The license to apply, or 0 (zero) to remove the current license.
 * 
 * Sets the license for a photo.
 *
 * Implements flickr.photos.licenses.setLicense (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_licenses_setLicense(flickcurl* fc, const char* photo_id,
                                     int license_id)
{
  xmlDocPtr doc = NULL;
  int result = 1;
  char license_id_s[5];
  
  flickcurl_init_params(fc, 1);

  if(!photo_id)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  sprintf(license_id_s, "%d", license_id);
  flickcurl_add_param(fc, "license_id", license_id_s);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.licenses.setLicense"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #16
0
/**
 * flickcurl_test_echo:
 * @fc: flickcurl context
 * @key: test key
 * @value: test value
 * 
 * A testing method which echo's all parameters back in the response.
 *
 * Actually prints the returned byte count to stderr.
 *
 * Implements flickr.test.echo (0.5)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_test_echo(flickcurl* fc, const char* key, const char* value)
{
  const char * parameters[6][2];
  int count = 0;
  xmlDocPtr doc = NULL;
  int rc = 0;
  
  parameters[count][0]  = key;
  parameters[count++][1]= value;

  parameters[count][0]  = NULL;

  if(flickcurl_prepare(fc, "flickr.test.echo", parameters, count)) {
    rc = 1;
    goto tidy;
  }

  doc = flickcurl_invoke(fc);
  if(!doc) {
    rc = 1;
    goto tidy;
  }

  fprintf(stderr, "Flickr echo returned %d bytes\n", fc->total_bytes);
  
  tidy:
  
  return rc;
}
Example #17
0
/**
 * flickcurl_auth_getFrob:
 * @fc: flickcurl context
 * 
 * Get a frob to be used during authentication
 *
 * Implements flickr.auth.getFrob (0.9)
 * Must be signed.  Does not require authentication.
 * 
 * Return value: frob string or NULL on failure
 **/
char*
flickcurl_auth_getFrob(flickcurl* fc)
{
  const char * parameters[5][2];
  int count = 0;
  char *frob = NULL;
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  
  parameters[count][0]   = NULL;

  flickcurl_set_sign(fc);
  
  if(flickcurl_prepare(fc, "flickr.auth.getFrob", parameters, count))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;
  
  xpathCtx = xmlXPathNewContext(doc);
  if(xpathCtx) {
    frob = flickcurl_xpath_eval(fc, xpathCtx, (const xmlChar*)"/rsp/frob");
    xmlXPathFreeContext(xpathCtx);
  }

  tidy:

  return frob;
}
Example #18
0
/**
 * flickcurl_people_getPhotosOf_params:
 * @fc: flickcurl context
 * @user_id: The NSID of the user who's photo to search. A value of "me" will search against the calling user's photos for authenticated calls.
 * @list_params: #flickcurl_photos_list_params result parameters (or NULL)
 * 
 * Returns a list of photos containing a particular Flickr member.
 *
 * Announced 2010-01-21
 * http://code.flickr.com/blog/2010/01/21/people-in-photos-the-api-methods/
 * 
 * Return value: photos list or NULL on failure
 **/
flickcurl_photos_list*
flickcurl_people_getPhotosOf_params(flickcurl* fc, const char* user_id,
                                    flickcurl_photos_list_params* list_params)
{
  flickcurl_photos_list* photos_list = NULL;
  const char* format = NULL;
  
  flickcurl_init_params(fc, 0);

  if(!user_id)
    return photos_list;

  flickcurl_add_param(fc, "user_id", user_id);

  /* Photos List parameters */
  flickcurl_append_photos_list_params(fc, list_params, &format);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.people.getPhotosOf"))
    goto tidy;

  photos_list = flickcurl_invoke_photos_list(fc,
                                             (const xmlChar*)"/rsp/photos",
                                             format);

  tidy:
  if(fc->failed) {
    if(photos_list)
      flickcurl_free_photos_list(photos_list);
    photos_list = NULL;
  }

  return photos_list;
}
Example #19
0
/**
 * flickcurl_tags_getClusterPhotos:
 * @fc: flickcurl context
 * @tag: The tag that this cluster belongs to.
 * @cluster_id: The top three tags for the cluster, separated by dashes (just like the url).
 * @list_params: #flickcurl_photos_list_params result parameters (or NULL)
 * 
 * Returns the first 24 photos for a given tag cluster
 *
 * Implements flickr.tags.getClusterPhotos (1.7)
 *
 * Added to API (not announced) some time between 2008-09-04 and 2008-09-19
 * 
 * Return value: non-0 on failure
 **/
flickcurl_photos_list*
flickcurl_tags_getClusterPhotos(flickcurl* fc, const char* tag,
                                const char* cluster_id,
                                flickcurl_photos_list_params* list_params)
{
  const char* parameters[10][2];
  int count = 0;
  flickcurl_photos_list* photos_list = NULL;
  const char* format = NULL;
  
  if(!tag || !cluster_id)
    return NULL;

  parameters[count][0]  = "tag";
  parameters[count++][1]= tag;
  parameters[count][0]  = "cluster_id";
  parameters[count++][1]= cluster_id;

  parameters[count][0]  = NULL;

  if(flickcurl_prepare(fc, "flickr.tags.getClusterPhotos", parameters, count))
    goto tidy;

  photos_list = flickcurl_invoke_photos_list(fc,
                                             (const xmlChar*)"/rsp/photos",
                                             format);
  tidy:
  if(fc->failed) {
    if(photos_list)
      flickcurl_free_photos_list(photos_list);
    photos_list = NULL;
  }

  return photos_list;
}
Example #20
0
/**
 * flickcurl_tags_getClusterPhotos:
 * @fc: flickcurl context
 * @tag: The tag that this cluster belongs to.
 * @cluster_id: The top three tags for the cluster, separated by dashes (just like the url).
 * @list_params: #flickcurl_photos_list_params result parameters (or NULL)
 * 
 * Returns the first 24 photos for a given tag cluster
 *
 * Implements flickr.tags.getClusterPhotos (1.7)
 *
 * Added to API (not announced) some time between 2008-09-04 and 2008-09-19
 * 
 * Return value: non-0 on failure
 **/
flickcurl_photos_list*
flickcurl_tags_getClusterPhotos(flickcurl* fc, const char* tag,
                                const char* cluster_id,
                                flickcurl_photos_list_params* list_params)
{
  flickcurl_photos_list* photos_list = NULL;
  const char* format = NULL;
  
  flickcurl_init_params(fc);

  if(!tag || !cluster_id)
    return NULL;

  flickcurl_add_param(fc, "tag", tag);
  flickcurl_add_param(fc, "cluster_id", cluster_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.tags.getClusterPhotos"))
    goto tidy;

  photos_list = flickcurl_invoke_photos_list(fc,
                                             (const xmlChar*)"/rsp/photos",
                                             format);
  tidy:
  if(fc->failed) {
    if(photos_list)
      flickcurl_free_photos_list(photos_list);
    photos_list = NULL;
  }

  return photos_list;
}
Example #21
0
/**
 * flickcurl_photos_geo_batchCorrectLocation:
 * @fc: flickcurl context
 * @location: The location (lat, long, accuracy) of the photos to update.
 * @place_id: A Flickr Places ID (or NULL)
 * @woe_id: A Where On Earth (WOE) ID (or 0)
 *
 * Correct the places hierarchy for all the photos for a user at a
 * given location (latitude, longitude and accuracy).
 *
 * You must pass either a valid Places ID in @place_id or a WOE ID in
 * @woe_id.
 * 
 * Batch corrections are processed in a delayed queue so it may take
 * a few minutes before the changes are reflected in a user's photos.
 *
 * Implements flickr.photos.geo.batchCorrectLocation (1.8)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_geo_batchCorrectLocation(flickcurl* fc,
                                          flickcurl_location* location,
                                          const char* place_id, int woe_id)
{
  xmlDocPtr doc = NULL;
  char latitude_s[50];
  char longitude_s[50];
  char accuracy_s[50];
  char woe_id_str[10];
  int result = 0;

  flickcurl_init_params(fc, 1);

  if(!place_id || !woe_id)
    return 1;

  if(location->latitude < -90.0)
    location->latitude= -90.0;
  if(location->latitude > 90.0)
    location->latitude= 90.0;
  if(location->longitude < -180.0)
    location->longitude= -180.0;
  if(location->longitude > 180.0)
    location->longitude= 180.0;
  if(location->accuracy < 1 || location->accuracy > 16)
    location->accuracy = 0;
  

  sprintf(latitude_s, "%f", location->latitude);
  flickcurl_add_param(fc, "lat", latitude_s);
  sprintf(longitude_s, "%f", location->longitude);
  flickcurl_add_param(fc, "lon", longitude_s);
  sprintf(accuracy_s, "%d", location->accuracy);
  flickcurl_add_param(fc, "accuracy", accuracy_s);
  if(place_id) {
    flickcurl_add_param(fc, "place_id", place_id);
  }
  if(woe_id > 0) {
    sprintf(woe_id_str, "%d", woe_id);
    flickcurl_add_param(fc, "woe_id", woe_id_str);
  }
  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.batchCorrectLocation"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #22
0
/**
 * flickcurl_photos_people_editCoords:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to edit a person in.
 * @user_id: The NSID of the person to edit in a photo.
 * @person_x: The left-most pixel co-ordinate of the box around the person.
 * @person_y: The top-most pixel co-ordinate of the box around the person.
 * @person_w: The width (in pixels) of the box around the person.
 * @person_h: The height (in pixels) of the box around the person.
 * 
 * Edit the bounding box of an existing person on a photo.
 *
 * Implements flickr.photos.people.editCoords (1.17)
 * 
 * Announced 2010-01-21
 * http://code.flickr.com/blog/2010/01/21/people-in-photos-the-api-methods/
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_people_editCoords(flickcurl* fc, const char* photo_id,
                                   const char* user_id,
                                   int person_x, int person_y,
                                   int person_w, int person_h)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  int rc = 0;
  char person_x_str[10];
  char person_y_str[10];
  char person_w_str[10];
  char person_h_str[10];
  
  flickcurl_init_params(fc, 1);

  if(!photo_id || !user_id || 
     person_x < 0  || person_y < 0 || person_w <0 || person_h < 0)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  flickcurl_add_param(fc, "user_id", user_id);

  sprintf(person_x_str, "%d", person_x);
  flickcurl_add_param(fc, "person_x", person_x_str);
  sprintf(person_y_str, "%d", person_y);
  flickcurl_add_param(fc, "person_y", person_y_str);
  sprintf(person_w_str, "%d", person_w);
  flickcurl_add_param(fc, "person_w", person_w_str);
  sprintf(person_h_str, "%d", person_h);
  flickcurl_add_param(fc, "person_h", person_h_str);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.people.editCoords"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    rc = 1;

  return rc;
}
Example #23
0
/**
 * flickcurl_galleries_create:
 * @fc: flickcurl context
 * @title: The name of the gallery
 * @description: A short description for the gallery
 * @primary_photo_id: The first photo to add to your gallery (or NULL)
 * @gallery_url_p: pointer to variable to store new gallery URL (or NULL)
 *
 * Create a new gallery for the calling user.
 *
 * Implements flickr.galleries.create (1.18)
 *
 * Announced 2010-04-08
 * http://code.flickr.com/blog/2010/04/08/galleries-apis/
 *
 * Return value: gallery ID or NULL on failure
 **/
char*
flickcurl_galleries_create(flickcurl* fc,
                           const char* title,
                           const char* description,
                           const char* primary_photo_id,
                           char** gallery_url_p)
{
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xpathCtx = NULL;
    char* gallery_id = NULL;

    flickcurl_init_params(fc);

    if(!title || !description)
        return NULL;

    flickcurl_add_param(fc, "title", title);
    flickcurl_add_param(fc, "description", description);
    if(primary_photo_id) {
        flickcurl_add_param(fc, "primary_photo_id", primary_photo_id);
    }

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.galleries.create"))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

    xpathCtx = xmlXPathNewContext(doc);
    if(!xpathCtx) {
        flickcurl_error(fc, "Failed to create XPath context for document");
        fc->failed = 1;
        goto tidy;
    }

    gallery_id = flickcurl_xpath_eval(fc, xpathCtx,
                                      (const xmlChar*)"/rsp/gallery/@id");
    if(gallery_url_p) {
        *gallery_url_p = flickcurl_xpath_eval(fc, xpathCtx,
                                              (const xmlChar*)"/rsp/gallery/@url");
    }

tidy:
    if(xpathCtx)
        xmlXPathFreeContext(xpathCtx);

    if(fc->failed)
        gallery_id = NULL;

    return gallery_id;
}
Example #24
0
/**
 * flickcurl_photosets_create:
 * @fc: flickcurl context
 * @title: A title for the photoset.
 * @description: A description of the photoset which may contain limited html (or NULL)
 * @primary_photo_id: The id of the photo to represent this set. The photo must belong to the calling user.
 * @photoset_url_p: pointer to variable to store new photoset URL (or NULL)
 *
 * Create a new photoset for the calling user.
 *
 * Implements flickr.photosets.create (0.13)
 *
 * Return value: photoset ID or NULL on failure
 **/
char*
flickcurl_photosets_create(flickcurl* fc, const char* title,
                           const char* description,
                           const char* primary_photo_id,
                           char** photoset_url_p)
{
    const char* parameters[10][2];
    int count = 0;
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xpathCtx = NULL;
    char* photoset_id = NULL;

    if(!title || !primary_photo_id)
        return NULL;

    parameters[count][0]  = "title";
    parameters[count++][1]= title;
    if(description) {
        parameters[count][0]  = "description";
        parameters[count++][1]= description;
    }
    parameters[count][0]  = "primary_photo_id";
    parameters[count++][1]= primary_photo_id;

    parameters[count][0]  = NULL;

    if(flickcurl_prepare(fc, "flickr.photosets.create", parameters, count))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;

    xpathCtx = xmlXPathNewContext(doc);
    if(!xpathCtx) {
        flickcurl_error(fc, "Failed to create XPath context for document");
        fc->failed = 1;
        goto tidy;
    }

    photoset_id = flickcurl_xpath_eval(fc, xpathCtx, (const xmlChar*)"/rsp/photoset/@id");
    if(photoset_url_p) {
        *photoset_url_p = flickcurl_xpath_eval(fc, xpathCtx, (const xmlChar*)"/rsp/photoset/@url");
    }

tidy:
    if(xpathCtx)
        xmlXPathFreeContext(xpathCtx);

    if(fc->failed)
        photoset_id = NULL;

    return photoset_id;
}
Example #25
0
/**
 * flickcurl_photos_geo_photosForLocation_params:
 * @fc: flickcurl context
 * @location: The location (lat, long, accuracy) of the photos
 * @list_params: #flickcurl_photos_list_params result parameters (or NULL)
 * 
 * Get a list of photos for a user at a specific location (latitude, longitude
 * and accuracy)
 *
 * Return value: list of photos or NULL on failure
 **/
flickcurl_photos_list*
flickcurl_photos_geo_photosForLocation_params(flickcurl* fc,
                                              flickcurl_location* location,
                                              flickcurl_photos_list_params* list_params)
{
  flickcurl_photos_list* photos_list = NULL;
  char latitude_s[50];
  char longitude_s[50];
  char accuracy_s[50];
  const char* format = NULL;

  flickcurl_init_params(fc, 0);

  if(!location)
    return NULL;
  
  if(location->latitude < -90.0)
    location->latitude= -90.0;
  if(location->latitude > 90.0)
    location->latitude= 90.0;
  if(location->longitude < -180.0)
    location->longitude= -180.0;
  if(location->longitude > 180.0)
    location->longitude= 180.0;
  if(location->accuracy < 1 || location->accuracy > 16)
    location->accuracy = 0;
  

  sprintf(latitude_s, "%f", location->latitude);
  flickcurl_add_param(fc, "lat", latitude_s);
  sprintf(longitude_s, "%f", location->longitude);
  flickcurl_add_param(fc, "lon", longitude_s);
  sprintf(accuracy_s, "%d", location->accuracy);
  flickcurl_add_param(fc, "accuracy", accuracy_s);

  /* Photos List parameters */
  flickcurl_append_photos_list_params(fc, list_params, &format);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.photosForLocation"))
    goto tidy;

  photos_list = flickcurl_invoke_photos_list(fc,
                                             (const xmlChar*)"/rsp/photos",
                                             format);

  tidy:
  if(fc->failed) {
    if(photos_list)
      flickcurl_free_photos_list(photos_list);
    photos_list = NULL;
  }

  return photos_list;
}
Example #26
0
/**
 * flickcurl_photos_geo_setLocation:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to set location data for.
 * @location: The location
 * 
 * Sets the geo data (latitude and longitude and, optionally, the
 * accuracy level) for a photo.
 *
 * Implements flickr.photos.geo.setLocation (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_geo_setLocation(flickcurl* fc, const char* photo_id,
                                 flickcurl_location* location)
{
  xmlDocPtr doc = NULL;
  char latitude_s[50];
  char longitude_s[50];
  char accuracy_s[50];
  int result = 1;
  
  flickcurl_init_params(fc, 1);

  if(!photo_id)
    return 1;

  if(location->latitude < -90.0)
    location->latitude= -90.0;
  if(location->latitude > 90.0)
    location->latitude= 90.0;
  if(location->longitude < -180.0)
    location->longitude= -180.0;
  if(location->longitude > 180.0)
    location->longitude= 180.0;
  if(location->accuracy < 1 || location->accuracy > 16)
    location->accuracy = 0;
  

  flickcurl_add_param(fc, "photo_id", photo_id);
  sprintf(latitude_s, "%f", location->latitude);
  flickcurl_add_param(fc, "lat", latitude_s);
  sprintf(longitude_s, "%f", location->longitude);
  flickcurl_add_param(fc, "lon", longitude_s);
  if(location->accuracy >= 1) {
    sprintf(accuracy_s, "%d", location->accuracy);
    flickcurl_add_param(fc, "accuracy", accuracy_s);
  }

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.setLocation"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}
Example #27
0
/**
 * flickcurl_collections_getTree:
 * @fc: flickcurl context
 * @collection_id: The ID of the collection to fetch a tree for, or zero to fetch the root collection. Defaults to zero. (or NULL)
 * @user_id: The ID of the account to fetch the collection tree for. Deafults to the calling user. (or NULL)
 * 
 * Returns a tree (or sub tree) of collections belonging to a given user.
 *
 * Implements flickr.collections.getTree (1.12)
 * 
 * Return value: a collection or NULL on failure
 **/
flickcurl_collection*
flickcurl_collections_getTree(flickcurl* fc, const char* collection_id,
                              const char* user_id)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  flickcurl_collection* collection  =  NULL;
  
  flickcurl_init_params(fc, 0);

  if(collection_id) {
    flickcurl_add_param(fc, "collection_id", collection_id);
  }
  if(user_id) {
    flickcurl_add_param(fc, "user_id", user_id);
  }

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.collections.getTree"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  collection = flickcurl_build_collection(fc, xpathCtx,
                                          (const xmlChar*)"/rsp/collections/collection");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed) {
    if(collection)
      flickcurl_free_collection(collection);

    collection = NULL;
  }

  return collection;
}
Example #28
0
/**
 * flickcurl_galleries_getInfo:
 * @fc: flickcurl context
 * @gallery_id: The gallery ID you are requesting information for.
 *
 * Get information for a gallery.
 *
 * Implements flickr.galleries.getInfo (1.18)
 *
 * Announced 2010-04-08
 * http://code.flickr.com/blog/2010/04/08/galleries-apis/
 *
 * Return value: gallery or NULL on failure
 **/
flickcurl_gallery*
flickcurl_galleries_getInfo(flickcurl* fc, const char* gallery_id)
{
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xpathCtx = NULL;
    flickcurl_gallery* gallery = NULL;
    flickcurl_gallery** galleries = NULL;

    flickcurl_init_params(fc);

    if(!gallery_id)
        return NULL;

    flickcurl_add_param(fc, "gallery_id", gallery_id);

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.galleries.getInfo"))
        goto tidy;

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;


    xpathCtx = xmlXPathNewContext(doc);
    if(!xpathCtx) {
        flickcurl_error(fc, "Failed to create XPath context for document");
        fc->failed = 1;
        goto tidy;
    }

    galleries = flickcurl_build_galleries(fc, xpathCtx,
                                          (const xmlChar*)"/rsp/galleries/gallery",
                                          NULL);
    if(galleries) {
        gallery = galleries[0];
        galleries[0] = NULL;
        flickcurl_free_galleries(galleries);
    }

tidy:
    if(xpathCtx)
        xmlXPathFreeContext(xpathCtx);

    if(fc->failed)
        gallery = NULL;

    return gallery;
}
Example #29
0
/**
 * flickcurl_galleries_addPhoto:
 * @fc: flickcurl context
 * @gallery_id: The ID of the gallery to add a photo to as returned by flickcurl_galleries_getList() and flickcurl_galleries_getListForPhoto().
 * @photo_id: The photo ID to add to the gallery.
 * @comment_text: A short comment or story to accompany the photo (or NULL).
 *
 * Add a photo to a gallery.
 *
 * Implements flickr.galleries.addPhoto (1.17)
 *
 * Return value: non-0 on failure
 **/
int
flickcurl_galleries_addPhoto(flickcurl* fc, const char* gallery_id,
                             const char* photo_id, const char* comment_text)
{
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xpathCtx = NULL;
    void* result = NULL;

    flickcurl_init_params(fc);

    if(!gallery_id || !photo_id)
        return 1;

    flickcurl_add_param(fc, "gallery_id", gallery_id);
    flickcurl_add_param(fc, "photo_id", photo_id);
    if(comment_text) {
        flickcurl_add_param(fc, "comment", comment_text);
    }

    flickcurl_end_params(fc);

    if(flickcurl_prepare(fc, "flickr.galleries.addPhoto"))
        goto tidy;

    flickcurl_set_write(fc, 1);
    flickcurl_set_data(fc, (void*)"", 0);

    doc = flickcurl_invoke(fc);
    if(!doc)
        goto tidy;


    xpathCtx = xmlXPathNewContext(doc);
    if(!xpathCtx) {
        flickcurl_error(fc, "Failed to create XPath context for document");
        fc->failed = 1;
        goto tidy;
    }

    result = NULL; /* your code here */

tidy:
    if(xpathCtx)
        xmlXPathFreeContext(xpathCtx);

    if(fc->failed)
        result = NULL;

    return (result == NULL);
}
Example #30
0
/**
 * flickcurl_photos_notes_edit:
 * @fc: flickcurl context
 * @note_id: The id of the note to edit
 * @note_x: The left coordinate of the note
 * @note_y: The top coordinate of the note
 * @note_w: The width of the note
 * @note_h: The height of the note
 * @note_text: The description of the note
 * 
 * Edit a note on a photo. Coordinates and sizes are in pixels, based on the 500px image size shown on individual photo pages.

 *
 * Implements flickr.photos.notes.edit (0.12)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_notes_edit(flickcurl* fc,
                            const char* note_id,
                            int note_x, int note_y, int note_w, int note_h,
                            const char* note_text)
{
  xmlDocPtr doc = NULL;
  int result = 1;
  char note_x_s[10];
  char note_y_s[10];
  char note_w_s[10];
  char note_h_s[10];
  
  flickcurl_init_params(fc);

  if(!note_id || !note_text)
    return 1;

  flickcurl_add_param(fc, "note_id", note_id);
  sprintf(note_x_s, "%d", note_x);
  flickcurl_add_param(fc, "note_x", note_x_s);
  sprintf(note_y_s, "%d", note_y);
  flickcurl_add_param(fc, "note_y", note_y_s);
  sprintf(note_w_s, "%d", note_w);
  flickcurl_add_param(fc, "note_w", note_w_s);
  sprintf(note_h_s, "%d", note_h);
  flickcurl_add_param(fc, "note_h", note_h_s);
  flickcurl_add_param(fc, "note_text", note_text);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.notes.edit"))
    goto tidy;

  flickcurl_set_write(fc, 1);
  flickcurl_set_data(fc, (void*)"", 0);

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;

  result = 0;

  tidy:
  if(fc->failed)
    result = 1;

  return result;
}