Changeset 2297


Ignore:
Timestamp:
Jun 25, 2013, 3:49:35 PM (5 years ago)
Author:
matthijs
Message:

luci-twitter: Update to REST API v1.1

On 2013.06.11, Twitter deprecated and removed the REST API v1 which the
Fonera was using. This commit updates the application to use the newer
API.

This consists of:

  • All requests now use HTTPS, since HTTP is no longer supported
  • The rate limit check is removed, since posting Tweets is no longer rate limited (though apparently posting might start returning 403's when a lot of (similar) Tweets are posted in quick succession).
  • The post url was updated to have 1.1 in the url.

Closes: #1307

Location:
trunk/luci/libs/twitter/luasrc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/luci/libs/twitter/luasrc/bbl-twitter.lua

    r1940 r2297  
    2121        -- scheme you put in the url, using HTTP, breaking the signature). At
    2222        -- least version 2.0.2 does.
    23         url = "http://api.twitter.com",
     23        url = "https://api.twitter.com",
    2424}
    2525
  • trunk/luci/libs/twitter/luasrc/twitter.lua

    r1944 r2297  
    7575end
    7676
    77 local function remaining_hits(client)
    78         -- Make an authenticated request
    79         succes, response = pcall(signed_request, client, "/1/account/rate_limit_status.json", {}, "GET")
    80         if not succes then
    81                 log("Error getting Twitter rate limit: " .. response)
    82                 return 0
    83         end
    84 
    85         -- Decode the response as JSON
    86         local ltn12 = require "luci.ltn12"
    87         local decoder = require "luci.json".Decoder()
    88         ltn12.pump.all(ltn12.source.string(response), decoder:sink())
    89         local data = decoder:get()
    90         if data and data.remaining_hits then
    91                 return data.remaining_hits
    92         end
    93         log("Failed to get Twitter rate limit, response was: " .. (data or "No response received") )
    94         return 0
    95 end
    96 
    9777-- does the actual tweeting. Returns true or false depending on whether
    9878-- the Tweet succeeded. If problems were encountered, they are logged to
    9979-- syslog.
    10080local function do_tweet(client, msg)
    101         -- Check if we're not flooding the API
    102         if remaining_hits(client) == 0 then
    103                 log("Twitter rate limit reached, not posting tweet")
    104                 return false
    105         end
    106 
    10781        -- Make an authenticated request
    108         succes, response = pcall(signed_request, client, "/1/statuses/update.json", {status = msg})
     82        succes, response = pcall(signed_request, client, "/1.1/statuses/update.json", {status = msg})
    10983        if not succes then
    11084                log("Failed to post tweet to Twitter: " .. response)
Note: See TracChangeset for help on using the changeset viewer.