Oodle .NET API library – OodleRestApi

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!

OodleRestApi.NET is a free library that I have developed in my personal time. I would really appreciate your feedback and support for OodleRestApi and its future development.
Getting Started:
1. Download OodleRestApi dll from here (library is compiled in .NET 4.0)
Or get the OodleRestApi .NET 2.0 build from here
2.  In your project, add reference to the OodleRestApi library Love2Trade.OodleRestApi.dll
3. OodleRestApi uses  JSON.NET for deserializing oodle’s response. You will need to download the latests from http://json.codeplex.com/. After that you will need to add reference to Newtonsoft.Json.dll in your project
4. Now you are ready to roll!! The quickest way to learn is to show you a sample client.


//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!! :)

Support OodleRestApi
We appreciate your support for OodleRestApi
Advertisement

8 Responses

  1. Hello, do you have an asp.net 2.0 or 3.5 version of this DLL?

  2. Hi

    Great job works a treat. But how do i add my own Oodle API

  3. Hi ash

    Read the oodle site and see i just replace “Test” with my key, sorry for being a dope but the oodle dev site was down when i posted original question.

    Cheers

  4. No worries…looks like you figured it out!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.