yo.lua 898 B

12345678910111213141516171819202122232425
  1. module(..., package.seeall)
  2. function yo(yo_user, api_token)
  3. assert(type(yo_user) == 'string', 'yo_user must be a string')
  4. assert(type(api_token) == 'string', 'api_token must be a string')
  5. assert(yo_user ~= '', 'yo_user must not be empty string')
  6. assert(api_token ~= '', 'api_token must not be empty string')
  7. local contentString = "api_token=" .. api_token .. "&username="..string.upper(yo_user)
  8. local contentLength = string.len(contentString)
  9. debug('yo.yo: sending Yo')
  10. wifi.sleeptype(wifi.NONE_SLEEP)
  11. http.post(
  12. 'https://api.justyo.co/yo/',
  13. 'Content-Type: application/x-www-form-urlencoded\r\n' ..
  14. 'Content-length: ' .. contentLength .. '\r\n',
  15. contentString,
  16. function(status_code, response_data)
  17. wifi.sleeptype(wifi.LIGHT_SLEEP)
  18. debug('yo.yo: status code ' .. status_code)
  19. debug('yo.yo: response data ' .. response_data)
  20. end
  21. )
  22. end