Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple twitter streaming client to hit the sampled statuses stream
Usage: ./twitstream <user> <pass>
- Loading branch information
R. Tyler Croy
committed
Aug 18, 2011
1 parent
8f6ff5c
commit c00e177
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
with Ada.Command_Line, | ||
Ada.Text_IO, | ||
AWS.Client, | ||
AWS.Messages, | ||
AWS.Response; | ||
|
||
procedure TwitStream is | ||
use Ada.Text_IO; | ||
|
||
package CLI renames Ada.Command_Line; | ||
|
||
Host : constant String := "http://stream.twitter.com/1/statuses/sample.json"; | ||
Conn : AWS.Client.HTTP_Connection; | ||
Result : AWS.Response.Data; | ||
begin | ||
if CLI.Argument_Count < 2 then | ||
Put_Line ("Missing some arguments!"); | ||
CLI.Set_Exit_Status (1); | ||
return; | ||
end if; | ||
|
||
Put_Line ("Starting TwitStream.."); | ||
|
||
AWS.Client.Create (Conn, Host, Server_Push => True); | ||
AWS.Client.Set_WWW_Authentication (Conn, CLI.Argument (1), | ||
CLI.Argument (2), | ||
AWS.Client.Basic); | ||
|
||
Put_Line ("..connection created"); | ||
|
||
AWS.Client.Get (Conn, Result); | ||
|
||
Status_Check : declare | ||
use AWS.Messages; | ||
|
||
Code : AWS.Messages.Status_Code := AWS.Response.Status_Code (Result); | ||
begin | ||
if Code = AWS.Messages.S200 then | ||
Put_Line ("200 Status"); | ||
else | ||
Put_Line ("Bad status: " & AWS.Messages.Image (Code)); | ||
Put_Line (AWS.Messages.Reason_Phrase (Code)); | ||
CLI.Set_Exit_Status (1); | ||
return; | ||
end if; | ||
end Status_Check; | ||
|
||
while true loop | ||
Put (AWS.Client.Read_Until (Conn, "" & ASCII.LF)); | ||
delay 0.1; | ||
end loop; | ||
|
||
end TwitStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
with "aws"; | ||
|
||
project TwitStream is | ||
for Source_Dirs use ("."); | ||
for Main use ("twitstream.adb"); | ||
|
||
package Builder is | ||
for Default_Switches ("Ada") use ("-gnat05"); | ||
end Builder; | ||
|
||
end TwitStream; |