This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
/
trends.go
102 lines (88 loc) · 3.19 KB
/
trends.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package twitter
import (
"net/http"
"github.com/dghubble/sling"
)
// TrendsService provides methods for accessing Twitter trends API endpoints.
type TrendsService struct {
sling *sling.Sling
}
// newTrendsService returns a new TrendsService.
func newTrendsService(sling *sling.Sling) *TrendsService {
return &TrendsService{
sling: sling.Path("trends/"),
}
}
// PlaceType represents a twitter trends PlaceType.
type PlaceType struct {
Code int `json:"code"`
Name string `json:"name"`
}
// Location represents a twitter Location.
type Location struct {
Country string `json:"country"`
CountryCode string `json:"countryCode"`
Name string `json:"name"`
ParentID int `json:"parentid"`
PlaceType PlaceType `json:"placeType"`
URL string `json:"url"`
WOEID int64 `json:"woeid"`
}
// Available returns the locations that Twitter has trending topic information for.
// https://dev.twitter.com/rest/reference/get/trends/available
func (s *TrendsService) Available() ([]Location, *http.Response, error) {
locations := new([]Location)
apiError := new(APIError)
resp, err := s.sling.New().Get("available.json").Receive(locations, apiError)
return *locations, resp, relevantError(err, *apiError)
}
// Trend represents a twitter trend.
type Trend struct {
Name string `json:"name"`
URL string `json:"url"`
PromotedContent string `json:"promoted_content"`
Query string `json:"query"`
TweetVolume int64 `json:"tweet_volume"`
}
// TrendsList represents a list of twitter trends.
type TrendsList struct {
Trends []Trend `json:"trends"`
AsOf string `json:"as_of"`
CreatedAt string `json:"created_at"`
Locations []TrendsLocation `json:"locations"`
}
// TrendsLocation represents a twitter trend location.
type TrendsLocation struct {
Name string `json:"name"`
WOEID int64 `json:"woeid"`
}
// TrendsPlaceParams are the parameters for Trends.Place.
type TrendsPlaceParams struct {
WOEID int64 `url:"id,omitempty"`
Exclude string `url:"exclude,omitempty"`
}
// Place returns the top 50 trending topics for a specific WOEID.
// https://dev.twitter.com/rest/reference/get/trends/place
func (s *TrendsService) Place(woeid int64, params *TrendsPlaceParams) ([]TrendsList, *http.Response, error) {
if params == nil {
params = &TrendsPlaceParams{}
}
trendsList := new([]TrendsList)
params.WOEID = woeid
apiError := new(APIError)
resp, err := s.sling.New().Get("place.json").QueryStruct(params).Receive(trendsList, apiError)
return *trendsList, resp, relevantError(err, *apiError)
}
// ClosestParams are the parameters for Trends.Closest.
type ClosestParams struct {
Lat float64 `url:"lat"`
Long float64 `url:"long"`
}
// Closest returns the locations that Twitter has trending topic information for, closest to a specified location.
// https://dev.twitter.com/rest/reference/get/trends/closest
func (s *TrendsService) Closest(params *ClosestParams) ([]Location, *http.Response, error) {
locations := new([]Location)
apiError := new(APIError)
resp, err := s.sling.New().Get("closest.json").QueryStruct(params).Receive(locations, apiError)
return *locations, resp, relevantError(err, *apiError)
}