Driscoll Web Development Blog

Get information, tools, news, tips, and more from the expert web developers at Driscoll Web Development.


Thursday, January 29, 2009

Why Use the BitlyXAPI?

As you most likely saw in my last post, I've just released the BitlyXAPI .NET Library. I created this library for two reasons: first, it is my entry to the bit.ly API Contest; second, I wanted to have some fun with my .NET chops while at the same time doing something helpful for the web development community. The BitlyXAPI .NET Library is free under the terms of the GNU GPL, so clearly I'm not looking to make a profit off this nor am I attempting to prevent other developers from deriving their own libraries from it.

So, if you're a .NET developer and you're reading this, you're most likely wondering what the BitlyXAPI Library can do for you - which is not a topic that I've previously addressed in-depth. I wanted to spend some time highlighting what I believe to be the key advantages to using this library in a project that implements the bit.ly API.

The BitlyXAPI Library is Fast
Due in no small part to the fact that the bit.ly API itself is quite speedy, I've done my best to keep the BitlyXAPI Library's overhead low so that there is little (if any) perceptible difference between using the Library and calling the bit.ly API directly.

The BitlyXAPI Library is Open and Adaptable
I'm not a huge fan of most API wrappers because they often limit what you can do, so I purposefully set out to write a library that would allow developers to leverage the bit.ly API without necessarily being put into lock-step with the API's implementation. Rather, developers can use the BitlyXAPI Library as it fits into their applications rather than build applications that strictly adhere to the functionality of the library (which is, unfortunately, the case with most API wrappers). Granted, this level of adaptability does have its drawbacks; for instance, one might notice that none of the bit.ly API methods are defined in the BitlyXAPI Library - meaning that one would have to write one's own Shorten() method in their application should they choose to do so. However, I feel that the aforementioned example highlights why the BitlyXAPI Library is so great, because it potentially allows developers to easily write complex methods with the BitlyXAPI Library.

The BitlyXAPI Library is Event-based
I took an asynchronous, or event-based, model into account when I wrote the BitlyXAPI Library. It allowed me to write lean, granular, and easily maintained code in the Library itself. However, it also gives developers the advantage of writing lean, granular, and easily maintained code in their own applications. And, the event-based model gives developers the assurance that their application won't hang if a method call doesn't return a result.

The BitlyXAPI Library Handles Menial Tasks
For most, creating an application that imports data from an external resource is excruciating because so many lines of code must be dedicated to checking that the application has network access, then checking that the application can access the specified resource, then cleaning up when the resource is no longer needed, etc. Internally the BitlyXAPI checks with every call to the bit.ly API that the API is accessible to the application, and throws a BitlyException if the service is unavailable for any reason. The BitlyXAPI also performs its own garbage collection on the resources that it uses. Therefore, the developer can focus more on developing a solid application and spend less time writing code to perform menial tasks.

The BitlyXAPI Library is Well-documented
Another one of my pet peeves about many (but not all) API wrappers out there is their lack of documentation and/or working samples. Upon decompressing the BitlyXAPI Library archive a developer will notice the ReadMe.txt file along with a small sample class and console application. The ReadMe.txt file provides full documentation for the BitlyXAPI Library, while the sample class and console application allows the developer to see the BitlyXAPI Library at work - right out of the box.

The BitlyXAPI Library is Free
By "free" I don't mean "no-cost", although the BitlyXAPI Library is provided at no-cost as well. Rather, I mean that because the BitlyXAPI Library is licensed under the GNU GPL, developers are free to request and obtain the Library's source code so that they may alter it to better meet their needs, or to create an extended library from it. The only thing I request is that out of respect developers acknowledge Driscoll Web Development and/or Brian Driscoll (me) in their applications - and that they provide a link to the original BitlyXAPI Library somewhere in their application's documentation.

Now that you've read this (and assuming you're a .NET developer who's interested in the bit.ly API), I hope that you'll consider using the BitlyXAPI Library in your project. If you create an application with the BitlyXAPI Library I invite you to comment on this post with a link to your work.

The library is available for download here.

Labels: , , , , , ,

Tuesday, January 27, 2009

Now Available: The BitlyXAPI Library for .NET Development

Introducing: the BitlyXAPI library for .NET development!

This library allows .NET developers who wish to leverage the Bitly API in their applications a way of quickly implementing the Bitly API in their libraries/apps without having to worry about the plumbing, constructing calls, etc.

The zip file includes the BitlyXAPI DLL, a sample application (with source code), and documentation.

Download the BitlyXAPI package here:

Labels: , , , , , , ,

Friday, January 16, 2009

Creating a Read-Only Numeric Stepper Component in Flash/Actionscript 2.0

While working on a project recently I spent some time getting to know the Numeric Stepper component. Anyone who has worked with the component most likely knows about its most obvious shortcoming: the text field within the component is read/write! Of course, the actual value associated with the component only changes in response to events fired by the Mouse or Key (up/down arrow) objects, but nonetheless our client wasn't happy with the fact that a user could type in the text field.

So, I set about trying to make the text field read only. Based on my research I gathered quickly that this has been attempted before with varying results. One of the key issues that makes the proposition of "tweaking" a component difficult is the fact that a component class cannot be subclassed; otherwise, it would be fairly straightforward to create a new class that inherits from NumericStepper and simply add the necessary properties and methods to support read/write and read only modes for instances derived from the subclass.

With subclassing out of the question most of the developers' blogs I encountered suggested overriding methods of the mx.core.mx_internal namespace (from which the enabled property of the NumericStepper.inputField object is derived), however that's a bit cumbersome and a complex solution to what seems to be a relatively straight-forward problem.

Luckily for me, I've been playing around a bit with coding ActionScript Communication scripts, which are (more or less) ActionScript 1.0 scripts. In these scripts, the "easy" way to add properties and methods to a built-in class is to use the prototype object (i.e.: ClassName.prototype.someNewFunction = function(){...}). With that concept in mind I tried to see if I could use the prototype object to extend the capabilities of my NumericStepper component... and it worked! What follows is the code that allows you to do this for yourself:

1. Create a new Flash document.
2. Open the Components panel and drag two instances of the NumericStepper component onto the stage. Give the two steppers instance names of "myStepper1" and "myStepper2", respectively.
3. Add the following code to the Main Timeline of your document:

So, what does this code do, exactly? Well, the draw() method overrides the draw() method of the NumericStepper class. The only "new" functionality we've added is within the if-block; we test the instance's editable property, and if that property has a value of "false" then the component's text field is disabled. Otherwise, the text field is enabled (which is the default). All of the code that follows the if-block is the same as the NumericStepper's native draw() method.

The next two functions, setEditStatus and getEditStatus are simply getter/setter functions for the editable property.

Finally, I register the editable property with the component using the AS1-style addProperty method.

That's all there is to it! Now, to see this new property in action simply create a new layer on your main timeline and add the following code:

myStepper1.editable = true;
myStepper2.editable = false;

Go ahead and test out your movie. One instance (myStepper1) should have an editable text field, while the other (myStepper2) should not.

Happy coding!

(Download the source script for the extended NumericStepper here: http://blog.driscollwebdev.com/NumericStepperExtension.as)

Labels: , , ,