The HTTParty has just begun
67 comments Latest by vector conversion Tue, 31 Aug 2010 15:14:01 GMT
After releasing the new RubyURL API, I decided that it was time to look around at libraries to interact with it. I came across a new Ruby gem from John Nunemaker named, HTTParty, which aims to make it easy to talk to XML and JSON-based web services. Be sure to read John’s announcement of HTTParty.
So, I decided it might be fun to introduce more people to the gem by showing you all how to use it to talk to the new RubyURL API.
Install HTTParty
Before we get started, you’ll need to install the HTTParty gem with the following command:
~ : sudo gem install httparty
Password:
When you HTTParty, you must party hard!
Successfully installed httparty-0.1.6
1 gem installed
Installing ri documentation for httparty-0.1.6...
Installing RDoc documentation for httparty-0.1.6...
Great! Now that we’re ready to party hard, let’s build something.
Talking to the RubyURL API
The RubyURL API currently supports both XML and JSON, which are each supported by HTTParty. The great thing about HTTParty is that all you need to do is include it in a class and you’re able to quickly talk to remote services.
In this following example, we’re going to create a new class called Rubyurl.
class Rubyurl
endWhat we’ll want to do now is include the HTTParty library. (note: you’ll need to require both rubygems and httparty gems and I’ll skip those lines in following code samples)
class Rubyurl
include HTTParty
endThe HTTParty provides a few class methods, which we can use to configure our library. We’ll go ahead and specify the base_uri, which we’ll set to rubyurl.com.
class Rubyurl
include HTTParty
base_uri 'rubyurl.com'
endNow that our class is setup to talk to the Rubyurl.com site, we’ll want to add a new method which we can use to communicate with the RubyURL API. We’ll call this shorten as we’re using RubyURL to shorten long URLs… right?
class Rubyurl
include HTTParty
base_uri 'localhost:3000'
def self.shorten( website_url )
end
endOur new shorten method will expect us to provide it with a website url, which we’ll want RubyURL to return a shortened URL for. The PATH for the API that we’ll want to talk to is: /api/links, which we’re expected to pass XML or JSON to.
Here are two examples of using the RubyURL API with HTTParty.
RubyURL via JSON w/HTTParty
We’re going to use the post method that is provided with HTTParty to send a request to /api/links.json. As you can see, we’re providing the original website url to the web service.
class Rubyurl
include HTTParty
base_uri 'rubyurl.com'
def self.shorten( website_url )
post( '/api/links.json', :query => { :link => { :website_url => website_url } } )
end
endWhen ran, it’ll produce the following:
>> Rubyurl.shorten( 'http://github.com/jnunemaker/httparty/tree/master/lib/httparty.rb' ).inspect
=> {"link"=>{"permalink"=>"http://rubyurl.com/uJVu", "website_url"=>"http://github.com/jnunemaker/httparty/tree/master/lib/httparty.rb"}}Pretty simple, eh?
RubyURL via XML w/HTTParty
The great thing about HTTParty is that you can use XML without changing much.
class Rubyurl
include HTTParty
base_uri 'rubyurl.com'
def self.shorten( website_url )
post( '/api/links.xml', :query => { :link => { :website_url => website_url } } )
end
endProduces the following
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<link>
<website_url>http://github.com/jnunemaker/httparty/tree/master/lib/httparty.rb</website_url>
<permalink>http://rubyurl.com/uJVu</permalink>
</link>Closing thoughts
So… there you have it. HTTParty makes it extremely easy to interact with various web services that work over HTTP. I’d encourage you all to take a few minutes to experiment with it and see what crazy ideas that come to mind during the process. :-)
Enjoying the content? Be sure to subscribe to my RSS feed.






wow, that looks really simple. perhaps i’ll build my own twitter client so that i can play with it
@jason That’s what I’m doing. I’m building a twitter client that searches my girlfriend’s university library catalogue. You might find jnunemaker’s HappyMapper gem useful (it contains an example for mapping twitter responses straight to objects).
http://github.com/jnunemaker/happymapper/tree/master
The hardest part is parsing the search results. The template hasn’t been touched since about 1996.
For github-party (using JSON) I did something like:
Basically, it’s making an OpenStruct from the JSON hash, and then I’m pulling off the toplevel object. In you’re example, I figure you probably just want to pull off permalink.
Perhaps you will enjoy my pet project, h8ter, which uses HTTParty to spread hatred all over the world.
Great stuff. I’m going to have to read it again to make sure I got it all.
So, I decided it might be fun to introduce more people to the gem by showing you all how to use it to talk to the new RubyURL API.
Thanks man …............
supra tk society black white
rsgdrgdr
I absitively it ability be fun to acquaint added humans to the gem by assuming you all how to use it to allocution to the new RubyURL API.
The RubyURL API currently supports both XML and JSON, which are anniversary accurate by HTTParty. The abundant affair about HTTParty is that all you charge to do is cover it in a chic and you’re able to bound allocution to limited services.
What we’ll wish to do now is cover the HTTParty library. (note: you’ll charge to crave both rubygems and httparty gems and I’ll skip those curve in afterward cipher samples)
try
try
Great stuff. I’m going to have to read it again to make sure I got it all.
yuty
supra chad muska skytop purple camo
it’s the first time to be here.Very happy to come here.
Photographers got a attempt of a being allurement with one louis handbag , this looked rather antic as anybody knows these louis handbags are actual expensive. vuitton bag is your best choice.
There is a great deal of the delicate metalwork that is so indicative of the Tiffany designs. The Tiffany rings has a shade which is a gorgeous confection of stained glass that has been meticulously soldered together, and you will find that your silver rings can bring a great deal of life, you should consider what you can do with a Tiffany earrings
Go to a renowned retail store of Bentley GT and shop to away for your new Breitling Aeromarine . Breitling Windrider has always been known for its ultimate quality and standard in manufacturing superb designs of watches. Bentley 6.75 is a type of watch which has been designed to suit the requirements of pilots.
.
iron on transfer Jewish Directory Bar Mitzvah Wholesale menu keep jersey city shenzhen direct shenzhen discount shenzhen buy shenzhen city affiliate promos bars cash disco tumblr city star jar twink pinoy agency oak bar stool bar accessories Flair Bartending Posi Pourers
I would like to do some shopping, like http://www.holydress.com http://www.dc-micro-motor.com http://www.bridal01.com China wedding dress</a and so on!You can go with me!
Demonstrate a unique new conceptjordan shoesAwA10*
Christian Louboutin Shoes Sale
jordan shoes sale air jordan shoes sale
Manolo Blahnik Jimmy Choo
New Style Christian Louboutin Christian Louboutin Boots
Lacoste Polo Shirts Wholesale Polo Shirts
Seattle Seahawks jerseys store St Louis Rams jerseys
UGG Classic Cardy Boots UGG Classic Short Boots
chi hair straightener ugg boots
nice post, thank you for your sharing.
nice post,thank you for your sharing.
Great stuff. I’m going to have to read it again to make sure I got it all.
Just want to buy something like wedding dress or prom dress
it’s the first time to be here.Very happy to come here.
Louis Vuitton BOWLING MONTAIGNE PM M5932K Louis Vuitton BOWLING MONTAIGNE Louis Vuitton BOWLING MONTAIGNE GM M59312 Louis Vuitton BOWLING MONTAIGNE Louis Vuitton BOWLING MONTAIGNE GM M5931J Louis Vuitton BOWLING MONTAIGNE Louis Vuitton Epi Leather BOWLING MONTAIGNE GM M5931K Louis Vuitton Epi Leather BOWLING MONTAIGNE Louis Vuitton BOWLING MONTAIGNE GM M5931M Louis Vuitton BOWLING MONTAIGNE Louis Vuitton Epi Leather PASSY M5926M Louis Vuitton Epi Leather PASSY Louis Vuitton Epi Leather PASSY M59262 Louis Vuitton Epi Leather PASSY Louis Vuitton Epi Leather PASSY M5926K Louis Vuitton Epi Leather PASSY Louis Vuitton Epi Leather PASSY M5926J Louis Vuitton Epi Leather PASSY Louis Vuitton Epi Leather Lockit M4229K Louis Vuitton Epi Leather Lockit Louis Vuitton Epi Leather Lockit M4229J Louis Vuitton Epi Leather Lockit Louis Vuitton Epi Leather Lockit M42292 Louis Vuitton Epi Leather Lockit
wow its just begun so can i join too hehe
A wholesale Cell phones allows its user to make and receive telephone calls to and from the public telephone network which includes other mobiles and fixed line phones across the world. It does this by connecting to a wholesale Cell phones network owned by a mobile network operator. A key feature of the cellular network is that it enables seamless wholesale Cell phones even when the user is moving around wide areas via a process known as handoff or handover.
www.airjordanshoesdiscount.com > jordans www.vibram5fs.com/ > vibram www.fivefingersvibramdiscount.com/ > five fingers vibram
www.uggaustralianew.com/ > boots shoes
links of london earrings play a bigger national role, Cartier Tortue but he has kept a tiffany diamond rings low profile since leaving the replica rado Florida governor’s mansion in 2007. The tiffany engagement rings question that lingers on many panerai 8 days
so good
thank you
For me, I’m really interested in seeing what they’ve done to hopefully improve some of the short-comings of the user experience through their interaction design process. For example, tabs containing their own url/search fields sounds refreshing (I really dislike the hierarchy currently). Also, I’m really looking forward to their dashboard-like default pag
I don’t usually reply to posts but I will in this case.
I don’t usually reply to posts but I will in this case.
really good read. keep posting like this!
oduce more people to the gem by showing you all how to use it to talk to the new RubyUR
Thanks a lot for sharing. You have done a brilliant job. wait for more info. christian louboutin
The more reading, the better .
How to make use of the new Ruby URL ?
How to make use of the new Ruby URL ?
Thanks for your article. I think I have known how to do it. burberry wallet
wifi-via-mw8505-600mhz”>8” touch screen tft lcd google android 1.6 tablet pc
wifi-via-mw8505-600mhz”>8” touch screen tft lcd google android 1.6 tablet pc
ugg boot ugg boot sale ugg shoes ugg boot uk discount ugg boot ugg boot on sale ugg classic boot ugg
so good!!!
have a good time
wholesale nike shoesShop a great selection of authentic Nike shoes&Nike Air Max with reasonable price for the entire families at nike-shoes-max.com.nike shoes 100% quality guaranteed and smooth customer service.UGG Women’s Classic Cardy Boots 5819 are available with colorful knit uppers (composed of a wool blend) and a sheepskin sock liner for extra comfort.ugg boots It is detailed with three oversized wood buttons, allowing it to be styled buttoned up, australia uggslouched down, slightly unbuttoned, or completely cuffed down. They have a light and flexible EVA outsole along with a suede heel guard provides durable wear all season long. That is why it is one of several styles that have been all time favorites with women.
<a href=”http://www.christianlouboutintobuy.com/”>christian louboutin Shoes are currently becoming the top fashion accessory , which is made more obvious by the exotic shoe trends anticipated for every year.
“If you are cartier replica jewelry out shopping and you check discount Gucci shoes in somewhere and can immediately cartier wallets for men get a deal, that’s a burberry military belt win-win for you and the Mont Blanc Watch marketer,” Williamson added.
On Foursquare, for swiss replica watch instance, Starbucks has offered a gucci clothing for men $1 discounts to the “mayors” Gucci outlet of its local coffee shops cartier belt that is, people who Gucci 2009 check in the most often Breitling Watch as a reward.
m40372 Louis Vuitton Neo louis vuitton verona gm louis vuitton laptop sleeve louis vuitton speedy 35 lv speedy 35 verona mm lv verona mm louis vuitton beaubourg louis vuitton citadin lv purses louis vuitton speedy 30 damier ebene louis vuitton insolite wallet louis vuitton mini citadin lv josephine louis vuitton romance thames gm louis vuitton alma louis vuitton speedy louis vuitton speedy 25 louis vuitton papillon lv wallets louis vuitton epi lv speedy 30 lv epi leather louis vuitton sistina pm louis vuitton verona pm musette louis vuitton papillon lv louis vuitton zippy louis vuitton keepall louis vuitton laptop louis vuitton solar pm louis vuitton mahina leather
lv cosmic blossom cosmic blossom louis vuitton cosmic blossom lv store lv purses Soft Briefcase batignolles horizontal louis vuitton galliera lv louis vuitton damier azur handbag louis vuitton damier speedy 30 louis vuitton florin louis vuitton damier neverfull mm bulles louis vuitton vavin louis vuitton zippy wallet louis vuitton laptop laptop sleeve 13 louis vuitton boetie gm louis vuitton epi leather epi leather louis vuitton anton Sac Bosphore
christian louboutin Brad Wreidt of Bluetoad.com joins us and speaks about how tochristian louboutin shoes take your publication online, cost efficiently. christian louboutin saleTo make it even better
we can use to communicate with the RubyURL API. We’ll call this shorten as we’re using RubyURL to shorten long URLs… right?
Great job here. I really enjoyed what you had to say. Keep going because you definitely bring a new voice to this subject. Not many people would say what you’ve said and still make it interesting. Well, at least I’m interested.
custom packaging bags
Now, I feel good, I started take up real income. vector conversion have never thought that there weren’t any need in big initial investment.Keep working, great job, I love it! digitizing software Thanks.Great post. I have been searching for this exact info for a while now. I will bookmark it in the public bookmarking sites to get you more traffic. stock designs Now lets see if I can do something productive with it.Great job here. I really enjoyed what you had to say. Keep going because you definitely bring a new voice to this subject.