examples/shortenurl.lua
changeset 136 2b04fad2f61a
parent 127 9157566033e8
child 141 1e36a08d7734
equal deleted inserted replaced
135:0e407455faca 136:2b04fad2f61a
    46 				if data then
    46 				if data then
    47 					replystring = replystring .. data
    47 					replystring = replystring .. data
    48 					return true
    48 					return true
    49 				else -- eof
    49 				else -- eof
    50 					local reply = json.decode ( replystring )
    50 					local reply = json.decode ( replystring )
    51 					if reply and reply.id then
    51 					if ( type ( reply ) == 'table' ) and reply.id then
    52 						if jid and main.yesno ( main.option ( 'lua_shorten_post_url' ) ) then
    52 						if jid and main.yesno ( main.option ( 'lua_shorten_post_url' ) ) then
    53 							main.run ( ('say_to -q %s %s'):format ( jid, reply.id ) )
    53 							main.run ( ('say_to -q %s %s'):format ( jid, reply.id ) )
    54 						else
    54 						else
    55 							print ( ('Shortened url: %s'):format ( reply.id ) )
    55 							print ( ('Shortened url: %s'):format ( reply.id ) )
    56 						end
    56 						end
    57 					else
    57 					else
    58 						if type ( reply.error ) == 'table' then
    58 						if type ( reply ) == 'table' and ( type ( reply.error ) == 'table' ) then
    59 							print ( ('Failed to shorten url: %u %s'):format ( reply.error.code, reply.error.message ) )
    59 							print ( ('Failed to shorten url: %u %s'):format ( reply.error.code, reply.error.message ) )
    60 						else
    60 						else
    61 							print ( ('Failed to shorten url: Unknown response:\n%s'):format ( replystring ) )
    61 							print ( ('Failed to shorten url: Unknown response:\n%s'):format ( replystring ) )
    62 						end
    62 						end
    63 					end
    63 					end