Main Content
Ruby to access web services Archive - Originally posted on "The Horse's Mouth" - 2008-11-16 17:03:30 - Graham Ellis
If you want to use a Ruby program to access an RSS feed (or some other XML or HTML data), you can start with the standard Net::HTTP module ... full (working, tested) example here . That example "just" uses a Get method to get an RSS feed of the latest posts to the First Great Western Coffee Shop Forum - but you could easily tune it for other automated browsing.
If you take a look at the documentation for the class , you'll see it's straightforward to access data via the POST method too ... although it does require some background knowledge which we would love to teach you (if you don't know it ;-) ) on our Ruby Programming Course
I've been teaching Ruby over this weekend ... you may have guessed that, having seen the flurry of extra examples and tips posted, and I'm going to add in links to a final few examples here:
Ruby data formatting with the % operator / printf / sprintf
Ruby and $_ , the -n option, topicalisation, etc)
Yield in Ruby or how to have two pieces of code passing data back and forth like generators in Python
Some other articles
R114 - Ruby on the Web Reading and parsing a JSON object in Ruby Web and console - same principle, same code - Ruby example Ruby on the web - a simple example using CGI Some TestWise examples - helping use Ruby code to check your web site operation 3 digit HTTP status codes - what are they, which are most common, which should be a concern? Ruby at both extremes of your website Answers on Ruby on Rails Ruby on Rails - a sample application to teach you how This article R110 - Special Variables and Pseudo-Variables One line scripts - Awk, Perl and Ruby Reading and parsing a JSON object in Ruby Ruby - a teaching example showing many of the language features in short but useful program Object Oriented Ruby - new examples Constants in Ruby Variable scope - what is it, and how does it Ruby? This article Some Ruby programming examples from our course Variable types in Ruby Ruby - Totally Topical R109 - Strings and Regular Expressions Clarrissa-Marybelle - too long to really fit? Regular Expressions for the petrified - in Ruby Global Regular Expression matching in Ruby (using scan) Ruby - standard operators are overloaded. Perl - they are not Ruby - a teaching example showing many of the language features in short but useful program Matching regular expressions, and substitutions, in Ruby Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP Ruby - examples of regular expressions, inheritance and polymorphism Object Oriented Ruby - new examples Ruby collections and strings - some new examples Neatly formatting results into a table Search and replace in Ruby - Ruby Regular Expressions The dog is not in trouble Regular Expressions in Ruby This article Ruby Programming Course - Saturday and Sunday What are exceptions - Python based answer String interpretation in Ruby Regular expressions made easy - building from components Regular Express Primer Ruby v Perl - interpollating variables puts - opposite of chomp in Ruby String duplication - x in Perl, * in Python and Ruby R104 - Control Structures Alternating valuses / flip-flop / toggle - example in Ruby Where does Ruby load modules from, and how to load from current directory Separating your code for easier testing, understanding and re-use; example in Ruby Finding sum, minimum, maximum and average in Python (and Ruby) Conditionals, loops and methods in Ruby - a primer with simple examples Learning to program - Loop statements such as while Learning to Program - the conditional statement (if) Muttable v immutable and implications - Ruby Finding the total, average, minimum and maximum in a program Ruby v Perl - a comparison example Assigning values to variables within other statements - Ruby Does a for loop evaluate its end condition once, or on every iteration? Multiple inputs, multiple out, ruby functions Is this number between? Does this list include? - Ruby How a for loop works Java, Perl and other languages Returning multiple values from a function call in various languages - a comparison Ruby training - some fresh examples for string handling applications Splitting data reading code from data processing code - Ruby Why do I need brackets in Ruby ... or Perl, Python, C or Java Alternative loops and conditionals in Ruby and Perl For loop - checked once, or evety time? Ruby v Perl comparison and contrast Passing code to procedures and yield in Ruby A short form of if ... then ... else Learning to program in Ruby - examples of the programming basics Ruby, Perl, Linux, MySQL - some training notes This article Ruby Programming Course - Saturday and Sunday What to do with a huge crop of apples Clean code, jump free (Example in Lua) Saying NOT in Perl, PHP, Python, Lua ... Some Ruby programming examples from our course Ruby, C, Java and more - getting out of loops for loop - how it works (Perl, PHP, Java, C, etc) A better alternative to cutting and pasting code Ruby's case - no break Equality in Ruby - == eql? and equal? Breaking a loop - Ruby and other languages 1st, 2nd, 3rd revisited in Ruby