Tuesday, August 16. 2016
Integrating runalyze into runnerup (Part II)
This is the second part of the series about the integration of runalyze into the android application runnerup. As you know runnerup is an opensource application to track your running activities in any android phone. The runalyze project is the other side of the coin, it is an opensource (license is not already specified but the project claims it will be AGPL) server to store and analyze your exercises. So, for me, as an amateur runner, the integration between the two projects is a must.
There is an open issue in runnerup to perform the integration that sadly I missed for a very long time. There people from runalyze explains that they are working in a next version 3.0 and then the idea is starting a restful web services API for integrating external applications. The issue recommends to wait for that API and then perform the integration between the two projects. On the other hand, I started another project that was my little runalyze called runnerupweb. I did that just because I had not find any software of that type (as I said I did not know anything about runalyze). As I stated before I think that the integration between both applications is very important and, therefore, I started to study how it could be (see the previous entry in the series). Finally I decided to not wait for the API and implement something that just let you upload your activities in an easy way.
And it is almost done! The past weekend I finally had the time to implement the proposed integration presented in the previous entry. It works, there are some tricky parts (how the IDs are converted from one application to the other, calculating the calories of the activity, and so on) but the synchronizer is able to upload your tracks from the phone to the server. Please take in mind that my main target is using my own runalyze server, so the solution MUST deal with that feature. (As it was commented when I was implementing my runnerupweb application, the phone application just manages standard cloud services and therefore the different accounts just request username and password. In order to have your own backend it is absolutely necessary to also request an URL. In this case I have just done exactly the same idea I did in the case of runnerupweb, a new authentication method was created that requests url, username and password. The only difference in the new integration is that now the URL is filled by default with the public URL of the runalyze services. You have to be kind with people that work for the community.)
Finally I commented in the github issue that a working solution is in place. The user mipapo (a runalyze developer) told that the solution would only work with current version 2.x, and not for the upcoming version 3.x. It seems that the new version changes some internal framework or something and much of the URIs are different from one version to the other (you know, the URL for login or the URL for uploading the activity). So, I had to spend two hours more to change the synchronizer to detect the version, perform the login and upload the activity to the proper end-point. Now the implementation works with both versions, and you can smoothly upgrade runalyze from 2.x to 3.x without worrying about runnerup, the synchronization will work without changing anything.
Just one more comment, the runnerup application uses a smart technique to perform the login and later calls. It stores the cookies after a login and resend them in the next operations (just like a browser does). I had faced a problem in the implementation. The runalyze version 2.x returns two PHPSESSID cookies (the cookie that handles the session and in turn maintains the login) if you access the login.php directly to submit the username and password. I think this is a bug that should be fixed by runalyze but for the moment I overrided the getCookies method in the synchronizer to get the last cookie (that way it works).
This is a little video uploading some activities with the development environment into a local 2.6 runalyze server.
And that is all. Now I am waiting what is the reaction in the runnerup project. If you are interested please try to read the issue and test the application I uploaded to my github (remember that this is at your own risk and do not forget to do an export before anything else). I will try to handle any inconvenience with the synchronizer (but be merciful, I have little experience in android and even less time).
That's the way I wanna open source!
Comments