oembed.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package anaconda
  2. import (
  3. "net/http"
  4. "net/url"
  5. "strconv"
  6. )
  7. type OEmbed struct {
  8. Type string
  9. Width int
  10. Cache_age string
  11. Height int
  12. Author_url string
  13. Html string
  14. Version string
  15. Provider_name string
  16. Provider_url string
  17. Url string
  18. Author_name string
  19. }
  20. // No authorization on this endpoint. Its the only one.
  21. func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error) {
  22. resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
  23. if err != nil {
  24. return
  25. }
  26. defer resp.Body.Close()
  27. err = decodeResponse(resp, &o)
  28. return
  29. }
  30. // Calls GetOEmbed with the corresponding id. Convenience wrapper for GetOEmbed()
  31. func (a TwitterApi) GetOEmbedId(id int64, v url.Values) (o OEmbed, err error) {
  32. v = cleanValues(v)
  33. v.Set("id", strconv.FormatInt(id, 10))
  34. resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
  35. if err != nil {
  36. return
  37. }
  38. defer resp.Body.Close()
  39. err = decodeResponse(resp, &o)
  40. return
  41. }
  42. func (a TwitterApi) baseUrlV1() string {
  43. if a.baseUrl == BaseUrl {
  44. return BaseUrlV1
  45. }
  46. if a.baseUrl == "" {
  47. return BaseUrlV1
  48. }
  49. return a.baseUrl
  50. }