So I recently started to focus my effort to switch over from the legacy xml interface with oodle to their new REST-based web service for love2trade.com since it promises to be 20 times faster! I spent several hours trying to put this library together which should help others as well. Many thanks for Steve Baker from oodle in helping me get some issues sorted out.
We will make this library open source at some point in the near future. For now you are free to use the library & if you really want the code, shoot me an email!
Or get the OodleRestApi .NET 2.0 build from here
//Create the OodleRequest object that will be serialized to the server
OodleRequest oodleRequest = new OodleRequest("TEST");
oodleRequest.Filter.location.Region = Regions.RegionTypes._usa;
oodleRequest.Paging.Start = 1;
oodleRequest.Paging.Num = 50;
oodleRequest.Filter.refinements = Filter.refinementsTypes.none;
oodleRequest.Paging.Sort = Paging.SortKey.ctime;
oodleRequest.Filter.attributes.AddPriceRange(5000, 6000);
oodleRequest.category = "vehicle";
oodleRequest.q = "honda civic";
//Creating the webrequest object - Notice that the oodleRequest is simply a string representation of your query which you can print to the screen for troubleshooting
WebRequest webRequest = WebRequest.Create(oodleRequest.ToString());
using (WebResponse response = webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
//this will get the JSON result back from oodle
string output = reader.ReadToEnd();
//We do a minor alteration in the json string due to a problem oodle is facing with php's representation of objects as arrays
output = output.Replace("\"location\":[]", "\"location\":{}").Replace("\"user\":[]", "\"user\":{}");
OodleResult Result = JsonConvert.DeserializeObject<OodleResult>(output);
//Now you can whatever you want with the results, you can start by iterating through Result.Listings to view all the listings your query returned
}
}
You will notice that both the OodleRequest & OodleResponse objects represents a very similar structure to the structure defined by oodle in Oodle Api parameters
The Oodle Response is broken down to 5 main parts
- Current – This contains information about the query that is returned, (ex. Region, Category, Start item #, Num or items returned).
- Listings – This is a strong typed array of Listings. The maximum you will ever find is 50 items as defined by oodle
- Meta – Metadata details on the results available. How many total items available for your search query…etc. This is very important if you are implementing paging in your result set.
- Refinements – by default this is null unless you have requested refinements in your oodle request (ex. oodleRequest.Filter.refinements=none | simple | full)
- Stat – should always be “ok” if everything runs good.
Everything else is really self explanatory and you can depend on your IDE’s intellisense to guide you. Feel free to comment on this post if you have any Qs.
Let me know your feedback!! :)
Filed under: Technical | Tagged: classifieds, feed, free code, json, oodle, oodle api, parser, rest | 8 Comments »

