Lance Wicks
Kiwi,
Judoka,
Geek,
Husband
Daddy!

JudoGeek Blog

How to add a new service to NoseRub... an eediot's Guide. ;-) 

How to add a new service to NoseRub... an eediot's Guide. ;-)



Below is a basic guide as to how to add a new service to NoseRub. By adding a new service to NoseRub you enable automatic discovery of RSS feeds and correct classification and handling of information from the new service.

This is an initial draft, so please give me your feedback. Some services will require more than this so your "mileage may vary" so to speak.

Enjoy...

To create a new service is a 4 step process.

STEP 1
Create a new file called myapp.php in /app/models/services.
You may decide to copy an existing similar service file to act as a template, for example if the service you are adding is a bookmarking service you might like to use the delicious.php file as a template for your service.
The contents of the delicious.php file are as follows:
<?php
class DeliciousService extends AbstractService {
public function detectService($url) {
return $this->extractUsername($url, array('#del.icio.us/(.+)#'));
}

public function getAccountUrl($username) {
return 'http://del.icio.us/'.$username;
}

public function getContacts($username) {
return ContactExtractor::getContactsFromSinglePage('http://del.icio.us/network/' . $username . '/', '/<a class="uname" href="\/(.*)">.*<\/a>/iU');
}

public function getContent($feeditem) {
return $feeditem->get_link();
}

public function getFeedUrl($username) {
return 'http://feeds.delicious.com/rss/'.$username;
}
}
?>

1a. You need to change the class name to MyappService
1b. Alter the detectService function so it refers to the url of your app, this is a REGEX. (This function is used to autodetect the username from an url)
1c. Alter the GetAccountUrl function so that it too knows where the username is. (This is used if you add the service and put your username, it creates an url)
1d. If the service has friends or contacts that you can connect to, alter getContacts to find contacts. If not you can remove this function.
1e. Alter getFeedUrl so that it has the correct path to the RSS feed for this new service.
Below is a example of how the myapp.php file might look:
<?php
class MyappService extends AbstractService {
public function detectService($url) {
return $this->extractUsername($url, array('#myapp.com/user/(.+)#'));
}

public function getAccountUrl($username) {
return 'http://myapp.com/user/'.$username;
}

public function getContacts($username) {
return ContactExtractor::getContactsFromSinglePage('http://myapp.com/users/' . $username . '/friends', '/<a class="Buddy" href="\/(.*)">.*<\/a>/iU');
}

public function getContent($feeditem) {
return $feeditem->get_link();
}

public function getFeedUrl($username) {
return 'http://rss.myapp.com/rss/'.$username;
}
}
?>


Step2.
Create a .GIF icon for this service and put it in the /app/webroot/images/icons/services directory. Please make it the right size etc.

Step 3.
Having created the php file you need to add an entry for this service in the NoseRub database. To ensure that everyone is able to benefit from your hard work database modifications are included in the SVN and are placed in individual files in /app/config/sql/migrations directory.
Create a SQL command similar to the one below (as a single line)
INSERT INTO `services` (`id` ,`internal_name` ,`name` ,`url` ,`service_type_id` ,`help` ,`icon` ,`has_feed` ,`is_contact` ,`minutes_between_updates` ,`created` ,`modified`)VALUES ('42' , 'Myapp', 'MyApp.com', 'http://www.myapp.com', '2', '', 'myapp.gif', '1', '0', '30', NOW( ) , NOW( ));
** The id field value (42 in this example). You need to select a unique ID, so check what services exist in the database already before choosing. You need to specify it so that the service ID will be consistent across installations.
** The internal_name field is case sensitive and is tied to the name of the class in step 1
** service_type_id. This is the type of service (bookmark, blog, picture, etc) the ID relates to the service_types table in the NoseRub database. In this example we have set the field to '2', which is a Bookmarking service.
** has_feed. Set to this is the service has a RSS feed. So in this case it does so it is set to '1'
** minutes_between_updates. This is the minimum time before noserub will check the RSS feed again. it will help prevent overloading of the service. In this example we have set it to thirty minutes.
You might want to cheat and add the record manually using something like phpmyadmin ( I know I do), you can then copy and paste the SQL command from the screen. If you do this however, be sure to edit the command so that it is one line and remove the name of your database. Also make sure you have added a ID field and it is not NULL.
Step 4.
Go to http://<server_name>/noserub/jobs ... tem/update to update the database with your new entry.

Hopefully everything is now working happily. So all there is left to do is send your changes to NoseRub.com (myapp.php and your migration SQL file).

Please also send an example username so that we can quickly test everything and get it into the code base.

*** Please note that you'll need to remove the service before you do an update from noserub.com as update will try and re add your new service and fail.




[ add comment ] ( 170 views ) permalink

<<First <Back | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Next> Last>>