[Seaside] Zinc - Twitter - Streaming API - Long lived connections

Sven Van Caekenberghe sven at beta9.be
Wed Oct 26 13:10:49 UTC 2011


On 21 Oct 2011, at 15:00, Andreas Raab wrote:

> On 10/21/2011 10:20, Davorin Rusevljan wrote:
>> Can Zinc do that? (or some other HTTP Client)
> 
> WebClient [1] + SqueakSSL [2] does it quite nicely:
> 
> | wc |
> wc := WebClient new.
> wc username: 'YOUR_TWITTER_USERNAME'.
> wc password: 'YOUR_TWITTER_PASSWORD'.
> resp := wc httpGet: 'https://stream.twitter.com/1/statuses/sample.json'.
> resp isSuccess ifFalse:[^self error: 'Request failed'].
> 
> "Process incoming data"
> stream := resp contentStream.
[…]

Thanks for the actual code example, Andreas, that is what I meant by writing some loop. If that is indeed the answer, an 'indefinitive' but regular HTTP response, then that can be done with Zinc + Zodiac as well, through its streaming capabilities: 

| stream |
stream := ZnNeoClient new
	username: 'twitter_username' password: 'twitter_password';
	streaming: true;
	get: 'https://stream.twitter.com/1/statuses/sample.json'.
[…]

With error handling:

| stream |
stream := ZnNeoClient new
	username: 'twitter_username' password: 'twitter_password';
	streaming: true;
	enforceHttpSuccess: true; 
	accept: ZnMimeType applicationJson;
	enforceAcceptContentType: true; 
	ifFail: [ :exception | ^ self error: 'Failed with: ', exception printString ]; 
	get: 'https://stream.twitter.com/1/statuses/sample.json'.
[…]

Using JsJsonParser from Seaside's JavaScript-Core-JSON package, you could do streaming parsing, if the stream contains separate, independent JSON objects:

| parser |
parser := JsJsonParser on: stream.
[ stream atEnd ] whileFalse: [ | nextObject |
	nextObject := parser whitespace; parseValue ]
	
Sven

PS: Soon, ZnNeoClient will be renamed to simply ZnClient




More information about the seaside mailing list