trends.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package anaconda
  2. import (
  3. "net/url"
  4. "strconv"
  5. )
  6. type Location struct {
  7. Name string `json:"name"`
  8. Woeid int `json:"woeid"`
  9. }
  10. type Trend struct {
  11. Name string `json:"name"`
  12. Query string `json:"query"`
  13. Url string `json:"url"`
  14. PromotedContent string `json:"promoted_content"`
  15. }
  16. type TrendResponse struct {
  17. Trends []Trend `json:"trends"`
  18. AsOf string `json:"as_of"`
  19. CreatedAt string `json:"created_at"`
  20. Locations []Location `json:"locations"`
  21. }
  22. type TrendLocation struct {
  23. Country string `json:"country"`
  24. CountryCode string `json:"countryCode"`
  25. Name string `json:"name"`
  26. ParentId int `json:"parentid"`
  27. PlaceType struct {
  28. Code int `json:"code"`
  29. Name string `json:"name"`
  30. } `json:"placeType"`
  31. Url string `json:"url"`
  32. Woeid int32 `json:"woeid"`
  33. }
  34. // https://developer.twitter.com/en/docs/trends/trends-for-location/api-reference/get-trends-place
  35. func (a TwitterApi) GetTrendsByPlace(id int64, v url.Values) (trendResp TrendResponse, err error) {
  36. response_ch := make(chan response)
  37. v = cleanValues(v)
  38. v.Set("id", strconv.FormatInt(id, 10))
  39. a.queryQueue <- query{a.baseUrl + "/trends/place.json", v, &[]interface{}{&trendResp}, _GET, response_ch}
  40. return trendResp, (<-response_ch).err
  41. }
  42. // https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-available
  43. func (a TwitterApi) GetTrendsAvailableLocations(v url.Values) (locations []TrendLocation, err error) {
  44. response_ch := make(chan response)
  45. a.queryQueue <- query{a.baseUrl + "/trends/available.json", v, &locations, _GET, response_ch}
  46. return locations, (<-response_ch).err
  47. }
  48. // https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-closest
  49. func (a TwitterApi) GetTrendsClosestLocations(lat float64, long float64, v url.Values) (locations []TrendLocation, err error) {
  50. response_ch := make(chan response)
  51. v = cleanValues(v)
  52. v.Set("lat", strconv.FormatFloat(lat, 'f', 6, 64))
  53. v.Set("long", strconv.FormatFloat(long, 'f', 6, 64))
  54. a.queryQueue <- query{a.baseUrl + "/trends/closest.json", v, &locations, _GET, response_ch}
  55. return locations, (<-response_ch).err
  56. }