Noob: http script to google finance

Hello everybody, I’m learning Ruby, coming from Java and Python.

I thought a good first project would be to duplicate a script I’ve
previously done in Python, which takes a list of stock symbols and
does an http GET from google finance to pull the current stock price.

I started out by looking at the net.http library. However the
documentation isn’t super descriptive as far as usage:

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP/Get.html

This was a bit surprising to me coming from Python where the docs are
pretty good. Bascially, I am expecting to do a get and ruby returns a
string of the page html.

Is there another place documentation wise I should be looking? Or do I
just grab the interpreter and start experimenting? That’s fine also,
but if there is a better documentation source I thought I’d ask.

Thanks!

Hi,

You should generally look for the documentation of the top level classes
(in this case Net::HTTP or Net). That’s were you’ll find explanations,
usage examples etc.

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html

As a simple example:

require ‘net/http’

include the Net module so you don’t always have to prepend “Net”

include Net

response = HTTP.get ‘www.ruby-forum.com’, ‘/’
print response

I just created a new gem to provide a command line interface for
searches on rubygems.org.

gem install gemqs

gemqs term1 term2
…search results

repo: https://github.com/daveheitzman/gemqs

Hope it’s useful.

David H.
remo[email protected]

On Sat, Mar 17, 2012 at 7:02 PM, David H. [email protected]
wrote:

Hope it’s useful.
It seems to work like a charm. The one nitpick I have so far is that
my terminal is set to 160 columns but it truncates the output lines to
170 characters; so there are 7 characters plus ‘…’ sitting all alone
on a line sometimes.

For some reason I don’t see your announcement on ruby-forum.com

On Sun, Mar 18, 2012 at 12:55 PM, Ryan D. [email protected]
wrote:

Don’t thread hijack. It’s rude.

On Mar 17, 2012, at 17:02, David H. [email protected] wrote:

I just created a new gem to provide a command line interface for searches on
rubygems.org.

Ahh yes… that’s why I didn’t see it on the forum.

Sorry about that, my mistake.

Dave Heitzman

Don’t thread hijack. It’s rude.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs