Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to use ruby, csv and webservice? Need a direction.

Reply
Thread Tools

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

 
 
Nick da G
Guest
Posts: n/a
 
      10-08-2008
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)


2) My report urls are of this type:

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)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Shajith
Guest
Posts: n/a
 
      10-08-2008
[Note: parts of this message were removed to make it a legal post.]

Hi!
On Wed, Oct 8, 2008 at 12:07 PM, Nick da G <> 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/libdo...s/OpenURI.html

Something like this:

require 'open-uri'
open("http://myapp/reports/csv_export/2") do |csv|
#Write the csv report to file?
end

HTH,
Shajith

 
Reply With Quote
 
 
 
 
Nick da G
Guest
Posts: n/a
 
      10-08-2008
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'
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?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
csv read clean up and write out to csv Sacha Rook Python 2 11-02-2012 07:51 PM
read and write csv file using csv module jliu66 Python 0 10-19-2007 03:12 PM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
csv writerow creates double spaced excel csv files Michal Mikolajczyk Python 0 02-13-2004 08:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57