index.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package libamuse
  2. import (
  3. "notabug.org/apiote/amuse/accounts"
  4. "notabug.org/apiote/amuse/tmdb"
  5. "notabug.org/apiote/gott"
  6. )
  7. func getRandomTitle(args ...interface{}) (interface{}, error) {
  8. result := args[1].(*Result)
  9. languages := result.languages
  10. randomTitle, err := tmdb.GetRandomComedy(languages[0].String())
  11. result.result = randomTitle
  12. return gott.Tuple(args), err
  13. }
  14. func renderIndex(args ...interface{}) interface{} {
  15. result := args[1].(*Result)
  16. randomTitle := result.result.(string)
  17. result.page = result.renderer.RenderIndex(randomTitle, result.languages)
  18. return gott.Tuple(args)
  19. }
  20. func ShowIndex(language, mimetype string, authentication accounts.Authentication) (string, error) {
  21. authentication.Necessary = false
  22. r, err := gott.
  23. NewResult(gott.Tuple{&RequestData{language: language, mimetype: mimetype, auth: authentication}, &Result{}}).
  24. Bind(parseLanguage).
  25. Bind(verifyToken).
  26. Bind(getRandomTitle).
  27. Bind(createRenderer).
  28. Map(renderIndex).
  29. Finish()
  30. if err != nil {
  31. return "", err
  32. } else {
  33. return r.(gott.Tuple)[1].(*Result).page, nil
  34. }
  35. }