libsurl Tutorial

Scott R. Lawrence

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".


Table of Contents
1. Introduction
1.1. About This Document
1.2. What is libsurl?
1.2.1. A simple example
2. Basic Use
3. Advanced Use
4. Extending libsurl

Chapter 1. Introduction

1.1. About This Document

This document is intended as a thorough introduction to all of libsurl's capabilities, but not as a complete reference. Therefore, although all functions and features are discussed, they may not be described completely and accurately.

This document was created with docbook and emacs. No non-free software went into the creation of this document. This document may be duplicated under the provisions of the GNU Free Documentation License version 1.3 or, at your option, any later version. The license is available online here.


1.2. What is libsurl?

Libsurl is a small library for interacting with various online url shortening services, such as tinyurl, bit.ly, and is.gd. The primary purpose of libsurl is to dynamically generate shortened urls, but it could also be used to access statistics or perform any other task supported by a large number of url-shorteneing services.


1.2.1. A simple example

The following example is a simple program to output the shortened version of a URL read from standard input.


#include <stdlib.h>
#include <stdio.h>
#include <libsurl-fe.h>

int main(int argc,char *argv[]) {
    SURL *surl=surl_init();
    if(surl==0) return 1;
	char *url=(char *)malloc(500);
	scanf("%s",url);
    surl_setopt(surl,SURLOPT_URL,url);
    surl_setopt(surl,SURLOPT_SERVICE,BIT_LY);
    surl_setopt(surl,SURLOPT_USERNAME,"libsurl");
    surl_setopt(surl,SURLOPT_API_KEY,"R_d23d5fe4eea3777446ec7fa17d67bf42");

    if(surl_shorten(surl) || surl->error)
    surl_wait(surl);
    puts(surl_getopt(surl,SURLOPT_SHORT_URL));

    surl_cleanup(surl);
    return 0;
}

Chapter 2. Basic Use

Coming soon: this section of the documentation is not available for this version of libsurl.


Chapter 3. Advanced Use

Coming soon: this section of the documentation is not available for this version of libsurl.


Chapter 4. Extending libsurl

Coming soon: this section of the documentation is not available for this version of libsurl.