yo.lua 1.0 KB

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