monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] Twitter Hook


From: Marty Vance
Subject: [Monotone-devel] Twitter Hook
Date: Thu, 3 Dec 2009 17:23:00 -0700

I've been tinkering with creating a hook that will post to Twitter.
This isn't a complete hook, but rather a function that gets called
from note_netsync_revision_received() in hooks.lua.  Unfortunately,
I'm not familiar enough with Monotone or Lua to get past the seemingly
endless string of errors I've run into.

What it intends to do is fairly simple:

- Construct a ViewMTN URI
- Feed that to TinyURL.com's API and retrieve the result, via spawn_pipe("curl")
- Construct a Twitter status: "Revision: [branch] [revid] [tinyurl]
- Authenticate and post to Twitter using Kamil Kapron's LuaTwitter

The code is included below.  I would appreciate some guidance, or if
anyone feels compelled to make it work and repost it, be my guest.

--
-- Send a notice to Twitter
--
-- @param config table   with twitter configuration
-- @param revid  string  revision id for which the notice is sent
-- @param cv     table   contains cert values where key is cert name
-- @param rdat   string  contains revision data
function send_notice_to_twitter(config, revid, cv, rdat)
   if ( config.enabled ~= true ) then return false end -- nothing to
be done here
   if ( string.find( cv.branch, config.link.pat) == nil ) then return false end

   local revuri = config.link.base .. config.link.revuri .. revid
   local i, o, p = spawn_pipe( "curl", "-s",
"http://tinyurl.com/api-create.php?url="; .. revuri )

   if ( i == -1 ) then return false end

   line, errstr = o:read()
   local tinyurl = line
   twstatus = 'Revision: ' .. cv.branch .. ' ' .. tinyurl

   require( "/etc/monotone/twitter" )
   me = twitter.Client( twitter_name, twitter_pass )
   ret = me:VerifyCredentials()
   -- Config must be wrong
   if ( me.credentialsVerified ~= true ) then return false end

   t = me.UpdateStatus( twstatus )
   if ( type( t ) ~= "table" ) then return false end

  return true
end




reply via email to

[Prev in Thread] Current Thread [Next in Thread]