API

We have developed a simple but very useful API, which allows you to interact with ry.pe and perform some common tasks. This API is based on REST protocol (if you do not know what it is, you can find more info in Wikipedia)

All the API calls are like:

http://ry.pe/api/?method=method_name¶m_1=value

And the requests returns an XML like:

<?xml version="1.0" encoding="UTF-8"?>
<Model_API generator="zend" version="1.0">
	<method_name>
		<method_specific_data />
		<status>success</status>
	</method_name>
</Model_API>	

The status node value could be success or failed depending on the request result.


Currently we support these methods:

shorten

This creates a new ry.ped url with the provided long url. The new ry.ped url could be tweeted if the user has already linked ry.pe with his Twitter account.

This method is the only ione that requires some Basic http auth. A valid ry.pe username and password should be provided. The ry.ped url will be associated to this account.

Parameters:

longUrl
A string with the long url encoded.
comment
An optional string with the comment to be tweeted.
tweetIt
An optional boolean value that indicates if the new url should be tweeted. By default it is set to false

Returns: The new ry.ped URL, the title. If it was tweeted, the tweet message is also returned.

<Model_API generator="zend" version="1.0">
<shorten>
	<url>
		<short_url>http://ry.pe/testuser/bR</short_url>
		<title>Google</title>
		<tweeted>Testing the new ry.pe API :) http://ry.pe/testuser/bR</tweeted>
	</url>
	<status>success</status>
</shorten>
</Model_API>

Example:

<?php
$longurl = urlencode("http://www.google.com");
$cmnt = urlencode("Testing the new ry.pe API :)");
$url = "http://ry.pe/api/?method=shorten&longurl=$longurl&comment=$cmnt&tweetIt=true";
$rype_username = "testuser";
$rype_password = "testpwd";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$rype_username:$rype_password");

$return = curl_exec($ch);
print($return);
curl_close($ch);		

profile

With this method you can get the data and urls from a given user.

Parameters:

username
A string with the user.
limit
An optional integer with the limit of urls from the user specified. If this value is null, all the user's url will be returned.

Returns: The user data and his ry.ped URLs limited by the second parameter

<Model_API generator="zend" version="1.0">
<profile>
	<username>mstekl</username>
	<fullname>Mauricio Stekl</fullname>
	<location>fghfgh</location>
	<gender>male</gender>
	<age>77</age>
	<occupation>fghfghfgh</occupation>
	<avatar>http://ry.pe/images/avatars/2.jpg?1267485528</avatar>
	<urls>
		<url_1>
			<creation_date>2010-03-01 20:45:23</creation_date>
			<long_url>http://www.google.com</long_url>
			<title>Google</title>
			<likes>0</likes>
			<visits>0</visits>
			<short_url>http://ry.pe/mstekl/bR</short_url>
			<user>mstekl</user>
			<comment>Testing the new ry.pe API :) http://ry.pe/mstekl/bR</comment>
		</url_1>
		<url_2>
			<creation_date>2010-03-01 20:42:44</creation_date>
			<long_url>http://www.google.com</long_url>
			<title>Google</title>
			<likes>0</likes>
			<visits>0</visits>
			<short_url>http://ry.pe/mstekl/bQ</short_url>
			<user>mstekl</user>
			<comment>Testing the new ry.pe API :)</comment>
		</url_2>
		<url_3>
			<creation_date>2010-03-01 20:41:32</creation_date>
			<long_url>http://www.montevideo.com.uy</long_url>
			<title>Montevideo Portal - www.montevideo.com.uy - El mejor lugar para empezar en Internet!</title>
			<likes>0</likes>
			<visits>0</visits>
			<short_url>http://ry.pe/mstekl/bP</short_url>
			<user>mstekl</user>
			<comment>probando la futura API de ry.pe</comment>
		</url_3>
	</urls>
	<status>success</status>
</profile>
</Model_API>		

Example:

<?php
$url = "http://ry.pe/api/?method=profile&username=mstekl&limit=3";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$return = curl_exec($ch);
print($return);
curl_close($ch);

most_visited

With this method you can get the most visited ry.ped urls. By default it returns the 50 most visited urls, but this can be changed with the length parameter.

Parameters:

length
An optional integer that limits the number of results. The default value is 50

Returns:

An xml with the most visited urls. For each URL we provide: short url, title, comment, number of visits, likes and the creation date.

Example:

$url = "http://ry.pe/api/?method=most_visited&length=10";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$return = curl_exec($ch);
print($return);
curl_close($ch);

latest

With this method you can get latest urls added to ry.pe.

Parameters:

length
An optional integer that limits the number of results. The default value is 50.

Returns:

An xml with the latest urls. For each URL we provide: short url, title, comment, number of visits, likes and the creation date.

Example:

$url = "http://ry.pe/api/?method=latest&length=10";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$return = curl_exec($ch);
print($return);
curl_close($ch);

most_liked

With this method you can get the most liked urls.

Parameters:

length
An optional integer that limits the number of results. The default value is 50.

Returns:

An xml with the most liked urls. For each URL we provide: short url, title, comment, number of visits, likes and the creation date.

Example:

$url = "http://ry.pe/api/?method=most_liked&length=10";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$return = curl_exec($ch);
print($return);
curl_close($ch);

Note: All the provided examples are in PHP5 and needs the CURL extension enabled.

Copyright © 2009, ry.pe - All rights reserved.