Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created June 30, 2012 00:42
Show Gist options
  • Save tim-smart/3021609 to your computer and use it in GitHub Desktop.
Save tim-smart/3021609 to your computer and use it in GitHub Desktop.
local http = require('http')
local qs = require('querystring')
local json = require('json')
local table = require('table')
local headers =
{ ['Accept'] = 'application/json'
, ['Content-Length'] = 0
}
local body = qs.stringify(
{ user = 'rj'
, api_key = 'b25b959554ed76058ac220b7b2e0a026'
, method = 'user.getRecentTracks'
, format = 'json'
}
)
local request = http.request(
{ headers = headers
, path = table.concat({ '/2.0/?', body })
, host = 'ws.audioscrobbler.com'
, method = 'GET'
}
)
request:on('response', function (res)
local buf = {}
res:on('data', function (chunk)
buf[#buf + 1] = chunk
end)
res:on('end', function ()
p('end event emitted')
end)
end)
request:done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment