yo.lua 970 B

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