Using streams to access web sites

26 views
Skip to first unread message

Andy Burnett

unread,
Mar 25, 2012, 9:19:42 PM3/25/12
to amber...@googlegroups.com
I would like to grab a csv file ( from a google spreadsheet ), and
then parse it. I was thinking of implementing Avi's csv code in Amber.
Is it possible to create a stream on the contents of a URL? Is it
something that one would do via jQuery?

Cheers
Andy

R. Tyler Croy

unread,
Mar 25, 2012, 9:29:08 PM3/25/12
to amber...@googlegroups.com

What kind of a stream? If you just want a stream like API, you could use
jQuery's JSONP support and then just wrap the results with a stream-like API.

If you mean literal stream, like Web Sockets or Coment, then there's some
plugins you could wrap for that: <https://code.google.com/p/jquery-websocket/>


- R. Tyler Croy
--------------------------------------
Code: http://github.com/rtyler
Chatter: http://twitter.com/agentdero
rty...@jabber.org

Andy Burnett

unread,
Mar 25, 2012, 9:49:07 PM3/25/12
to amber...@googlegroups.com
>
> On Sun, 25 Mar 2012, Andy Burnett wrote:
>
>> I would like to grab a csv file ( from a google spreadsheet ), and
>> then parse it. I was thinking of implementing Avi's csv code in Amber.
>> Is it possible to create a stream on the contents of a URL? Is it
>> something that one would do via jQuery?
>
> What kind of a stream? If you just want a stream like API, you could use
> jQuery's JSONP support and then just wrap the results with a stream-like API.
>
> If you mean literal stream, like Web Sockets or Coment, then there's some
> plugins you could wrap for that: <https://code.google.com/p/jquery-websocket/

Hmm, good question. What I was hoping was that I could do something like:

doc := Stream on: 'http://foo.com/somecontents'.

And then be able to parse it, in the same way I would if I had grabbed
a handle on a standardfilestream.

Would the jQuery approach give me an object that I could convert to an
Amber Stream? And then work with that?

Cheers
Andy

Tom

unread,
Mar 27, 2012, 9:45:38 AM3/27/12
to amber-lang
Hi!

...
>
> Hmm, good question. What I was hoping was that I could do something like:
>
> doc := Stream on: 'http://foo.com/somecontents'.
>

Well, not that way :)

But You can fetch the CSV asynchronous and then stream over that
string.

| aStream |
jQuery
ajax: 'http://foo.com/somecontents'
options: #{
'type' -> 'GET'.
'success' -> [ :responseText | aStream := Stream on:
responseText].
'error' -> [window alert: 'error'].
'dataType' -> 'text'
}.

You could replace the success block's code with a success: method
which parses the stream.

Cheers...

Andy Burnett

unread,
Mar 27, 2012, 4:13:27 PM3/27/12
to amber...@googlegroups.com
Brilliant! That's what I need to know

Thanks
Cheers
Andy

Tom

unread,
Mar 28, 2012, 10:13:54 AM3/28/12
to amber-lang
Sorry,

but the code will not work, because aStream is a new symbol inside the
success block. So, one MUST replace this block like i.e...

...
'success' -> [ :responseText | self parseStream: (Stream on:
responseText)].
...

...where everything is encapsulated in a new class and parseStream: is
an instance method.

Cheers...

On 27 Mrz., 22:13, Andy Burnett <andy.burn...@knowinnovation.com>
wrote:
Reply all
Reply to author
Forward
0 new messages