Google API for .NET architecture (Part 1)

Part 2: Google API for .NET architecture (Part 2)

Today, I have just released a OSS with named is Gapi4net library at codeplex. This is a wrapper some of API's Google for search Web, Local, Video, Blog, News, Book, Image, Patent and language translation. In the past, I also saw some wrapper for Google API, specially are a google-api-for-dotnet, gapidotnet. But as I realized that they are hard to using and when you used them, you must remember many input parameters. For example, if you use the google-api-for-dotnet, you must input as:

GwebSearchClient client = new GwebSearchClient(/* Enter the URL of your site here */);
   
IList<IWebResult> results = client.Search("Google API for .NET", 32);  
   
foreach(IWebResult result in results)  
   
{  
       
Console.WriteLine("[{0}] {1} => {2}", result.Title, result.Content, result.Url);  
   
}

As you see, it does not support for you to easy in your work. So I decided to wrapping it according to my method. I will focus on purpose of user when using my library. And main feature is easy to use it. So why is my library easy to use than some of OSS before? I will show you this as below:

var result = Gapi4NetFactory<Web>
                .Init()
                .With(x => x.Version, "1.0")
                .With(x => x.Query, searchText)
                .With(x => x.Start, start)
                .Create();

I wrapped it and expose it with Fluent Interface and Lambda Expression. So input parameters is more meaningful than google-api-for-dotnet. And the input parameter is strong name now. You do not need to many comment on each parameter. And if you comment many line on each parameter, are you sure the end-user will see it? Trend now is avoiding the comments in code. Just simple that if you comment your code today, and next day you have the change request in your code, you maybe forget update your comment in this code. That make your comment is out of date. And why do you keep some of comments that not meaningful? So I usually make my code better possible and try to keep a little comment on my code, make my code self-talking with the end user about its function. In this sample above, I use Lambda Expression for make strong name and meaningful for input parameters. I am usually eager about this.

After talking many about my Gapi4net, I hope you will be enjoy about it in your practice. Now I will explain about architecture using in this library. The first thing is domain model, next I will explain some of technical, and finally is a example that write in ASP.NET MVC 3 Preview 1 for proving my solution.

Now, we shall jump into Gapi4net's domain model. You should see this link for APIs from Google. After see it, you will realize that many things in it. Don't worry about that. Just see for fun because I wrapped all of it in Gapi4net. And the main things I wrapped is Web, Local, Video, Blog, News, Book, Image, Patent and language translation. I worked on nine kind of APIs of Google in 2 weeks. Finally all things is going on well. And now I will show all my working in this post.

+ Domain Model's Web Search:

+ Domain Model's Local Search:

+ Domain Model's Video Search:

+ Domain Model's Blog Search:

+ Domain Model's News Search:

+ Domain Model's Book Search:

+ Domain Model's Image Search:

+ Domain Model's Patent Search:

+ Domain Model's Language Translation:

And I used the Json.net library for convert the Json data to my entities. Please see my previous post about converting technical in Json.net library. In this post I only show some line of code in Web Search for saving space in this post. All of them was put at here. And this is a code for web search:

    [JsonObject]
    public class WebSearchResult : ContractBase
    {
        [JsonProperty("responseData")]
        [JsonConverter(typeof(CustomObjectCreationConverter<IResponseDataResultResponseDataResult>))]
        public IResponseDataResult ResponseData { getset; }
    }

    [JsonObject]
    public class ResponseDataResult : IResponseDataResult
    {
        [JsonProperty("cursor")]
        [JsonConverter(typeof(CustomObjectCreationConverter<ICursorResultCursorResult>))]
        public ICursorResult Cursor { getset; }

        [JsonProperty("results")]
        [JsonConverter(typeof(CustomArrayCreationConverter<IMainResultMainResult>))]
        public IMainResult[] MainResult { getset; }
    }
    [JsonObject]
    public class MainResult : IMainResult
    {
        [JsonProperty("GsearchResultClass")]
        public string GsearchResultClass { getset; }

        [JsonProperty("cacheUrl")]
        public string CacheUrl { getset; }

        [JsonProperty("content")]
        public string Content { getset; }

        [JsonProperty("title")]
        public string Title { getset; }

        [JsonProperty("titleNoFormatting")]
        public string TitleNoFormatting { getset; }

        [JsonProperty("unescapedUrl")]
        public string UnescapedUrl { getset; }

        [JsonProperty("url")]
        public string Url { getset; }

        [JsonProperty("visibleUrl")]
        public string VisibleUrl { getset; }
    }
Next post I will continue to analyze some of technical that I used in Gapi4net and a example write in ASP.NET MVC 3 Preview 1. 
Good bye and see you next time!
Published Monday, September 13, 2010 1:47 AM by thangchung

Comments

# Google API for .NET architecture (Part 1) - Context is King

Sunday, September 12, 2010 2:20 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Google API for .NET architecture (Part 1)

Sunday, September 12, 2010 2:21 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: Google API for .NET architecture (Part 1)

Sunday, September 12, 2010 3:12 PM by Ian Pender

Hey cool! Tell me is it available / compilable into Silverlight and will you add support for Google Reader api ?

Cheers,

ian

# Twitter Trackbacks for Google API for .NET architecture (Part 1) - Context is King [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Google API for .NET architecture (Part 1) - Context is King         [asp.net]        on Topsy.com

# Google API for .NET architecture (Part 1) &#8211; Context is King | Build Talk

Pingback from  Google API for .NET architecture (Part 1) &#8211; Context is King | Build Talk

# Google API for .NET architecture (Part 1) &#8211; Context is King | AEC Media

Pingback from  Google API for .NET architecture (Part 1) &#8211; Context is King | AEC Media

# Google API for .NET architecture (Part 2)

Wednesday, September 15, 2010 1:02 PM by Context is King

Part 1: Google API for .NET architecture (Part 1) Today is Harvey Nash - 10 years in Viet Nam celebration

# re: Google API for .NET architecture (Part 1)

Tuesday, April 16, 2013 8:01 AM by Haggerty

Hi just wanted to give you a quick heads up and let you know a few of the images aren't loading properly. I'm not sure why but I think its a linking issue.

I've tried it in two different web browsers and both show the same outcome.

# re: Google API for .NET architecture (Part 1)

Tuesday, April 16, 2013 8:16 AM by Linville

Greetings from California! I'm bored at work so I decided to check out your site on my iphone during lunch break. I enjoy the knowledge you provide here and can't wait to take a look when I get

home. I'm shocked at how fast your blog loaded on my mobile .. I'm not even using WIFI, just 3G

.. Anyhow, superb blog!

# re: Google API for .NET architecture (Part 1)

Monday, April 22, 2013 5:50 AM by Culver

Nice weblog here! Additionally your website a lot up fast!

What host are you the use of? Can I am getting your affiliate link in your host?

I want my site loaded up as quickly as yours lol

# re: Google API for .NET architecture (Part 1)

Monday, April 22, 2013 12:50 PM by Pomeroy

Thanks to my father who stated to me about this blog, this web site is actually remarkable.

Leave a Comment

(required) 
(required) 
(optional)
(required)