# How to use ruby, csv and webservice? Need a direction

**URL:** <https://www.ruby-forum.com/t/how-to-use-ruby-csv-and-webservice-need-a-direction/150451>\
**Category:** Ruby\
**Created:** [October 8, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-use-ruby-csv-and-webservice-need-a-direction/150451 "2008-10-08T19:09:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [October 8, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-use-ruby-csv-and-webservice-need-a-direction/150451/1 "2008-10-08T19:09:44Z")

</div>

Hi, All.

I’m just a bit confused and need some direction here.

I have an app that does inventory and I also created a bunch of reports  
using great Ruport Library. All of my reports can produce: xls, csv, pdf  
& html.

What I’m trying to do is to have a scheduled ruby script on a separate  
scheduling machine that will pull one of the reports in CSV format and  
place it on HD for processing by our old DBF program.

There are two approaches:

1. I can have a copy of my app running on my scheduling computer that I  
will connect to the central DB do it’s processing and save the file  
locally where it’s needed. That’s how I’m doing right now.

(+ I don’t stress production server with reports)

1. My report urls are of this type:

[http://myapp/reports/csv\_export/2](http://myapp/reports/csv_export/2) - which spits out a csv file back at  
you for report #2

So I was thinking that I can just point a ruby script to that url, grab  
the file and place it on HD.

(+ This way I don’t need to 2 copies of my app. Better maintainability)

I want to go with the second approach - but here is where I’m stuck and  
need just a pointer. I’m sure it’s obvious but I just don’t know what to  
do.

How do I call that url from my ruby scrip and how do I process that csv  
file when I get it back? Everything I red talks about using xmlrpc or  
soap - but I don’t want to process that data again on a scheduling  
computer - when it’s already is being given to me in the proper format?  
How do I handle that?

If ruby has something like linux’s “wget” - that would be great - I  
think that would solve my problem.

( the reason I can’t use system wget is my scheduling pc - is a windows  
xp box - it has to be for old DBF stuff to work)

---

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [October 8, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/how-to-use-ruby-csv-and-webservice-need-a-direction/150451/2 "2008-10-08T19:25:52Z")

</div>

Hi!  
On Wed, Oct 8, 2008 at 12:07 PM, Nick da G [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> If ruby has something like linux’s “wget” - that would be great - I  
> think that would solve my problem.

Does open-uri help?

[http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html](http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html)

Something like this:

require ‘open-uri’  
open(“[http://myapp/reports/csv\_export/2](http://myapp/reports/csv_export/2)”) do |csv|  
#Write the csv report to file?  
end

HTH,  
Shajith

---

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [October 8, 2008, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-use-ruby-csv-and-webservice-need-a-direction/150451/3 "2008-10-08T21:07:20Z")

</div>

Thanks, Shajith.

That’s uber cool.

I couldn’t get your example working so I had to redo it slightly. But  
THANK YOU for the pointer - that was exactly what I needed.

For anyone else looking here is what I ended up doing

require ‘open-uri’  
url = ‘[http://localhost:3000/report\_details/csv\_export/2](http://localhost:3000/report_details/csv_export/2)’  
csv = open(url,  
:http\_basic\_authentication=\>[‘username’,‘password’]).read  
File.open(‘exports.csv’,‘w’) { |f| f.write(csv)}

On a side note I was wondering how would pipe output of of open(url)  
straight into a file? As I understand File.open(){} - takes each line of  
csv and writes it to file. Am I wrong?
