Tuesday, 9 March 2010

Apache Shindig: Java vs. PHP (part 2)

In my previous post I decided to make the Friends Gadget work on PHP Shindig. I managed to do so, thus I will stay with PHP version of Apache Shindig.

I will use the gadget that lists friends of the user. Notice that http://shindig/ is where you have your shindig installation (http://localhost:8080, for example). Here is the gadget code:


Now we want Apache Shindig to get a list of friends for a user with id=2 from my database 'graaasp_development'.

Here is a url that does it.

The most important parameter here is a "st" parameter, that stands for security token.


Owner_id means id of the owner of the gadget. Viewer_id means id the current user watching the gadget.
Application_id means the id of the gadget instance in the database.
In other words, in 'graaasp_development' database we have a gadget with id=12. Owner of this gadget is user with id=2 and the same user watches the gadget at the moment.

Now we have to add some code to shindig to let it know that 'graaasp_development' database should be used as a backend for gadgets requests.
First of all in the folder "shindig/php/config/" we should create a file 'local.php' with the following content.



This will force Shindig to use the code specific to the 'graaasp_development' database, which is located in '/Library/WebServer/Documents/graaasp'.

Now we have to rewrite the classes that will respond to opensocial code with data from 'graaasp_development' database.
1) in the file config.php we should change the database settings as follows:


2) In file PartuzaDbFetcher.php we have the code that gets friends from 'graaasp_development' database.


The output of the widget will be similar to the following:
Friends of User1:
* Guest
* User2
* User3

Monday, 1 March 2010

Reminder: svn ignore

A reminder on how to work with svn ignore.

In every folder svn keeps a list of all files/folders to ignore. By using the command "svn propset svn:ignore" you change this list. From my experience the best way is to have a text file "ignore.txt" (where you keep the list of all ignore rules) for every folder. The command "svn propdel svn:ignore ." will remove all rules for this folder and "svn propset svn:ignore -F ignore.txt ." will apply all the rules from the file "ignore.txt" for this folder.

The scenario: you are in a folder "MyFolder" and you want to ignore in this folder all svg files, the whole folder "log" and the whole folder "tmp". Then, you want to remove all ignore rules for this folder.

To add svn:ignore property for folder "MyFolder"
1) Make sure a file/folder to be ignored is not committed to svn repository.
If it is there, remove it from svn repository
2) Create a file "ignore.txt" in the "MyFolder" with the following content:

3) Go to the folder "MyFolder"
4) Run the following command to apply the rules

5) Commit the changes

To remove svn:ignore property for the folder "MyFolder".
1) Go to "MyFolder"
2) Run the following command to remove all the ignore rules.

2) Commit the changes

To do it recursively for all subfolders add "-R" to the command.

Monday, 15 February 2010

Apache Shindig: Java vs. PHP

I've spent a lot of time trying to understand what Shindig does and how it works. Well, I am close to it now, I believe. Another point that I was concerned about is Java or PHP? Shindig is known to be available as both java and php code. I need to use shindig to redirect the OpenSocial API calls inside gadget to my database. For this I need to write some interface methods. So which Shindig to choose: php or java?

Since I am more confident with php rather than java, I've chosen to look into php version. Partuza project that provides an example of social application based on PHP version of Shindig turned out to be very helpful.

At first I ran into some problems with php shindig, but it seems as I found the answers and those are not really problems.

Problem 1:
First of all the common todo gadget in php version of Shindig has a layout completely different from that of java version, which seems to be strange. Well it's not. Why it is different is explained here by Chris Chabot.

Problem 2:
Gadget default user preferences are not shown in shindig (php version),
but shown in java version.
It seems as it is the container implementations issue.
If those values are passed over url parameters it works:
http://shindig/gadgets/ifr?url=http://your_hosting/gadget.xml&up_myname=Evgeny

Gadget example is taked from Google:
http://code.google.com/apis/gadgets/docs/basic.html

Problem 3:
Gadget Friends gadget doesn't work in SimpleContainer.
It seems that those examples are not supported in PHP Shindig (found it on shindig emails list)
This gadget seems to work ok with partuza!!

Problem 3 was the biggest issue for me.
It seems it works properly in Partuza. Thus I will try to
implement interface methods to allow this gadget to request people from my database. If it works for Friends widget I will most probably stay with PHP if not, I guess I'll have to switch to Java version.