Page 1 of 1

ManiaHome.NET, the ASP.NET ManiaHome Library (Version 1.1)

Posted: 21 Apr 2011, 07:37
by fastforza
Introducing ManiaHome.NET, the ASP.NET ManiaHome library.

As stated by me somewhere, I've released an ASP.NET version of the ManiaHome library. The library is free, open source, lightweight and extremely easy to use. 8-)

ManiaHome.NET operates in the exact same manner the PHP library operates. It allows you to post notifications to ManiaHome, the ingame social network provided by Nadeo. Additionally it operates only for the ASP.NET framework, making it possible for ASP.NET developers to take advantage of the API with this easy to use library.

Visit the ManiaHome.NET project page today! Project page contains further information, step by step documentation, code samples and the source code. Suggestions and contributions are welcome! :ugeek:

ManiaHome.NET Requirements
- ASP.NET Framework 4.0

ManiaHome.NET Instructions
- You must follow steps 2 and 3 in this thread!
- Other instructions can be found on the project page.

Looking for the PHP ManiaHome library? Click Here!

TMF Only! May not work with ManiaPlanet!

Re: ManiaHome.NET

Posted: 21 Apr 2011, 12:05
by gouxim
That's great, good job!

I was going to ask if you can change the user agent, but I just saw the TODO in the source code :) It doesn't change anything about the way it works, but it gives us information (in the apache logs, and then in our statistics) about what clients are interacting with the API.

edit: oh and I edited the topic title

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 21 Apr 2011, 12:18
by fastforza
Thanks. 8-)

In the next release (or whatever I'll do), I'll change the user agent string and I'll add style support.

@title: That's ok, looks better. :P

Any future API's, you should keep me informed, might be able to make ASP.NET versions. :mrgreen:

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 21 Apr 2011, 16:59
by gouxim
Actually, what you might want to do to save time is what we just did with ManiaLib.

On the one hand, we have our generic REST client.

http://code.google.com/p/manialib/sourc ... Client.php

You'll want to take a look at the execute() method. Basically you specify:

* The HTTP method: GET, POST, PUT or DELETE
* The ressource
* The parameters

The simpliest way would to treat the 3rd parameter as data to put in the request body (for POST and PUT).

But here, what we did is the ressource is treated as a string for sprintf(), parameters beeing taken from the array given as 3rd param of the execute method. Let's look at at a few example:

Code: Select all

$client->execute('GET', '/foobar/'); => GET /foobar/
$client->execute('GET', '/foobar/%s'/', array(1337)); => GET /foobar/1337/
$client->execute('POST', '/foobar/%s/', array(1337, some_object)); => POST /foobar/1337/ with "some_object" in the request body
On the other hand, we have the ManiaHome client for ManiaLib which is built on top of the Rest Client. As you can see the code is very simple:

http://code.google.com/p/manialib/sourc ... Client.php

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 21 Apr 2011, 17:05
by gouxim
It's also woth mentioning that the data type that you put in the request body doesn't really matter, as long as the key matches. In my library I created an array because it's very simple in PHP. But I could also have created an object.

For example posting:

Code: Select all

array( "key" => "value")
and:

Code: Select all

$object = new stdClass();
$object->key = "value";
are the same when you POST the request. The reason is that the json_encode function in PHP treats array with non-numeric keys as objects, so in the end the serialized string that is put in the body of the POST request is the same:

Code: Select all

{"key":"value"}
So the bottom line is: if it's simplier for you to create objects instead of arrays when you POST data on the API, go and do that :)

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 22 Apr 2011, 04:52
by fastforza
I'll get around to creating a standalone REST client for the API soon. Seems acceptable if you introduce more API's and I create more ASP.NET versions. Time saver too, guess I never thought about it. :P

In PHP, arrays are handled far differently from ASP.NET

Code: Select all

array( "key" => "value") 
PHP arrays can have keyvaluepairs, while ASP.NET cannot (indexes and values only), instead you have collections

Code: Select all

Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("key", "anyObjectHere");
That's why you see a collection Dictionary<TKey, TValue> being specified as the data parameter.

When serialized with the JavaScriptSerializer the output will of course, be the same. :P

Code: Select all

{"key":"anyObjecthere"}
It's not so much a matter of it being simpler or different, it's a matter of it being the only way to pass a collection of keys and values.

Update: I've started a new project and all the namespaces have changed. I'll Keep ManiaHome as is, perhaps an optional download in the future.

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 22 Apr 2011, 10:12
by gouxim
That's nice. Note that REST architecture is the one used on Facebook's and twitter's APIs (and many others), so you might find some useful ASP.net code in the SDKs of those services.

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 22 Apr 2011, 10:23
by fastforza
Hmm I might take look if I get a chance.

Re: ManiaHome.NET, the ASP.NET ManiaHome library

Posted: 29 Apr 2011, 11:13
by fastforza
I've released ManiaHome.NET 1.1. :D

Changes Include
- Ability to specify ManiaLink styles.
- The client now sends a new user agent string: ManiaHome ASP.NET Library

Enjoy. :mrgreen: