Custom API (Application Programming Interface)


 

Custom API

Name.ly and its satellites offer many standard bases for api calls. For example:

  • http://brief.ly/on-the-fly/
  • http://links2.me/links2tabs/
  • http://many.at/feed2tabs/

However, if you are frequent user of Name.ly/API, you might want to tune those pages with your custom settings (like own site avatar), or even to map it on your own (sub)domain name.

Below you will find detailed instructions on how one can create those custom bases.

1. Register any site on any Name.ly service

1.a. Go to http://brief.ly/?new or http://sincere.ly/?new or any other Name.ly/Site

1.b. Follow the standard procedure; provide your email, password, site name (let us say that for this example we will create site apitest.what-el.se).

1.c. If requested, confirm your account by email.

2. Set up the API page

2.a. Login to your site admin panel, e.g.: http://apitest.what-el.se/wp-admin/

2.b. Select Name.ly/Frames as the theme:

Appearance > Theme > Name.ly/Frames > Activate

2.c. In the theme options enable auxiliary tabs and customise the colours

Appearance > Theme Settings > Menu Layout

> Set Auxiliary Tabs to Public; you can hide the other tabs or make them private

> Set the code tabs’ source in “Tabs’ & Feed’s Sources” to Feed if you want to hook your API on RSS (make sure that the Core Tabs are set Public in such a case)

> You can also change the colours in the “Menu Colour Scheme” section

2.d. Upload site avatar

Appearance> Site Avatar

2.e. Delete default sites

My Sites > Edit

> Remove all default sites and press “Save changes” button

2.e Change site title and description

Site Settings > General

You are nearly done.

2.f. If you want, you can map the new API site on your own (sub)domain:

Tools> Domain Mapping

So that instead of apitest.what-el.se you will be calling say super.cheap.ly.  Find more instructions in the Domain Mapping section.

Now you have your own API base set up.

3. API Calls

Another advanced step is to generate links to your API base on the fly. The following php code creates such a link from the URLs stored in $entry_array:

$n = count ( $entry_array );

$p = '';
for ( $i=0; $i<$n; $i++ ) {
  if ( $s = trim ( $entry_array [$i] ) ) {
    $p .= '&url' . ($i+1) . '=' . urlencode ( $s  ) .
          '&caption' . ($i+1) . '=' . urlencode ( 'Item ' . ($i+1) );
  }
}

if ( $p ) {
  echo '<p>Link to open all URLs with one click:</p>' . "\n";
  $l = 'http://many.at/feed2tabs/?toc=' . urlencode ( 'ToC' ) . $p;
  echo '<a href="' . $l . '" target="_blank">' . $l . '</a>';
}

You can reuse this code to take your data source and to link to your API page.

Important: make sure you pass all parameters using urlencode. This is required for all special characters, including Chinese, Cyrillic, Thai letters etc.

Important: some browsers, namely, Internet Explorer (even 64 bit version 9) and Windows version of Safari cut the URLs longer than 2000 characters. To aviod the lose of any added parameters please check the URLs before sharing, and use on-the-fly URL shorteners (see another example here).

It is also possible to prevent embedding foreign links by white listing your own domain name. Just go to:

Appearance > Theme Settings > API Settings

and list those you want to enable. If the white list is not left blank, all other auxiliary links will be rejected.

4. Extra

If you enable the Analytics or provide your Google Analytics code, you will be able to monitor who is visiting your API calls too.

Additional notes

$entry_array

Open all references in tabs: [1 – 9]


Short link: [Facebook] [Twitter] [Email] Copy - http://name.ly/~v4GF$CO