Skip to content

Notifying with post

lukes edited this page May 4, 2011 · 1 revision

Use action :post to have Herald post data of what it finds to a URI. You'll always need to specify a source in a :uri => "uri" (or :uris) parameter,

Herald.watch_twitter do
  _for "keywords"
  action :post, :uri => "localhost"
end

Posted data

The parameters posted to the URI will depend on what kind of source you're watching, although Herald makes sure there will always be at least a title and message.

An example of the parameters posted when watching Twitter

{
  "message"=>"@blockhead4eva @Kaotickara An example of what takes the whole bakery: http://www.yinyuetai.com/video/98705 :P", 
  "from_user_id_str"=>"32367165", 
  "title"=>"@carrietmd", 
  "id_str"=>"65276503990087680", 
  "text"=>"@blockhead4eva @Kaotickara An example of what takes the whole bakery: http://www.yinyuetai.com/video/98705 :P", 
  "from_user"=>"carrietmd", 
  "metadata"=>"[\"result_type\", \"recent\"]", 
  "to_user_id"=>"1668601", 
  "to_user"=>"blockhead4eva", 
  "id"=>"65276503990087680", 
  "to_user_id_str"=>"1668601", 
  "from_user_id"=>"32367165", 
  "iso_language_code"=>"en", 
  "source"=>"<a href="http://twitter.com/">web</a>", 
  "profile_image_url"=>"http://a1.twimg.com/profile_images/1306897982/lookalikememe_normal.jpg", 
  "created_at"=>"Tue, 03 May 2011 04:48:25 +0000"
}

If your receiving URI was a PHP script, this code

<?php echo $_POST["from_user"]; ?>

Would print the from_user value

Multiple sources

Give :uris an array value to ping more than one URI

Herald.watch_twitter do
  _for "keywords"
  action :ping, :uris => ["localhost", "remotehost.com"]
end

See also