SHOUT.go 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package SHOUTCLOUD
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "errors"
  6. "io/ioutil"
  7. "net/http"
  8. "time"
  9. )
  10. type SHOUTREQUEST struct {
  11. INPUT string
  12. }
  13. type SHOUTRESPONSE struct {
  14. INPUT string
  15. OUTPUT string
  16. }
  17. func UPCASE(THING_TO_YELL string) (string, error) {
  18. REQUEST := &SHOUTREQUEST{THING_TO_YELL}
  19. ENCODED, ERR := json.Marshal(REQUEST)
  20. if ERR != nil {
  21. return "", errors.New("COULDN'T MARSHALL THE REQUEST")
  22. }
  23. READER := bytes.NewReader(ENCODED)
  24. CLIENT := &http.Client{
  25. Timeout:time.Second * 20,
  26. }
  27. // NO TLS, SO MUCH SADNESS.
  28. RESP, ERR := CLIENT.Post("http://API.SHOUTCLOUD.IO/V1/SHOUT",
  29. "application/json", READER)
  30. if ERR != nil {
  31. return "", errors.New("REQUEST FAILED CAN'T UPCASE ERROR MESSAGE HALP")
  32. }
  33. defer RESP.Body.Close()
  34. BODYBYTES, ERR := ioutil.ReadAll(RESP.Body)
  35. if ERR != nil {
  36. return "", errors.New("COULDN'T READ BODY HALP")
  37. }
  38. var BODY SHOUTRESPONSE
  39. if json.Unmarshal(BODYBYTES, &BODY) != nil {
  40. return "", errors.New("COULDN'T UNPACK RESPONSE")
  41. }
  42. return BODY.OUTPUT, nil
  43. }