If you are interested in microfinance, then it is very likely that you’d know about Kiva. And if you know about Kiva, then it is possible that you might know that they have provided public access to their data via web-services. And once they did it, there were toolkits available in most of the languages.
One of the implementation that caught my interest was the Kiva .NET. I never worked on C# earlier, so I thought this might be a good project to start with. The reasons
- It’s a toolkit – so it is compact
- There is already an implementation for XML that was done by the original author
- I wanted to write some code using LINQ, even if it was not working off DB data sets
So, given the above, I added support for JSON data in the Kiva.NET library (can’t locate the link where the Kiva folks mentioned that they would release the JSON format first and then the XML for the API). Nevertheless, the JSON format support has been added.
Most importantly – this code is seriously beta. The reasons are
- The code is not backward compatible with the existing Kiva.NET implementation. Almost all the objects have changed with
- Attribute names (members of the class) have changed to make it possible to deserialize the JSON data (more on this further)
- For some objects, as the data returned by Kiva has changed, the object layout also had to change
- Exception handling is not done
- I did not check all the APIs to see if the XML implementation is full-featured as the JSON one
- Productizing the API is not done i.e.
- Versioning of the library
- Proper comments and documentation
- Test suite for the toolkit
But the code does work :). In the zip file attached, the KivaTest project has a very simple main() to test each of the APIs. Also, this requires atleast JSON.NET 3.5R5 as it has support for non-public default constructors. Thanks to James for adding this (you can follow the discussion here).
Coming to the point about the attribute names being changed. The reason this was needed because I was deserializing the JSON object using JSON.net and the library tries to match the attribute names with the JSON data. As mentioned in the Kiva API specifications, the variable names are separated with an underscore. The initial implementation of the Kiva .NET library didn’t use underscores for the attribute names. That is why my changes are not backward compatible. I did check the resolver interface in Kiva.net, but that is used to piddle with the attribute names of the objects but not with the JSON data. What I am looking for is to modify the JSON attributes so that I can remove the underscores for the attribute names before deseralizing them into Kiva objects. I am certain it must be possible, just that I am a n00b when it comes to C#, so will dig more and find out.
Will have more updates in the coming days based on how the owner of the library reviews my changes ! The patch file and the zip file for the changes are here