File tree Expand file tree Collapse file tree 3 files changed +65
-6
lines changed Expand file tree Collapse file tree 3 files changed +65
-6
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+
7
+ tmdb "github.com/cyruzin/golang-tmdb"
8
+ )
9
+
10
+ func main () {
11
+ tmdbClient , err := tmdb .Init (os .Getenv ("APIKey" ))
12
+
13
+ if err != nil {
14
+ fmt .Println (err )
15
+ }
16
+
17
+ trending , err := tmdbClient .GetTrending ("movie" , "week" , nil )
18
+
19
+ if err != nil {
20
+ fmt .Println (err )
21
+ }
22
+
23
+ for _ , result := range trending .Results {
24
+ fmt .Println (result .Title )
25
+ }
26
+
27
+ fmt .Println ("------" )
28
+
29
+ // With options
30
+ options := make (map [string ]string )
31
+ options ["page" ] = "2"
32
+ options ["language" ] = "es-ES"
33
+
34
+ trending , err = tmdbClient .GetTrending ("tv" , "day" , options )
35
+
36
+ if err != nil {
37
+ fmt .Println (err )
38
+ }
39
+
40
+ for _ , result := range trending .Results {
41
+ fmt .Println (result .Name )
42
+ }
43
+ }
Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
)
6
6
7
- // Trending type is a struct for treding JSON response.
7
+ // Trending type is a struct for trending JSON response.
8
8
type Trending struct {
9
9
Page int `json:"page"`
10
10
* TrendingResults
@@ -19,18 +19,18 @@ type Trending struct {
19
19
// list tracks items over a 7 day period, with a 7 day
20
20
// half life.
21
21
//
22
- // Valid Media Types
22
+ // # Valid Media Types
23
23
//
24
24
// all - Include all movies, TV shows and people in the
25
25
// results as a global trending list.
26
26
//
27
27
// movie - Show the trending movies in the results.
28
28
//
29
- // tv - Show the trending tv shows in the results.
29
+ // tv - Show the trending TV shows in the results.
30
30
//
31
31
// person - Show the trending people in the results.
32
32
//
33
- // Valid Time Windows
33
+ // # Valid Time Windows
34
34
//
35
35
// day - View the trending list for the day.
36
36
//
@@ -40,6 +40,7 @@ type Trending struct {
40
40
func (c * Client ) GetTrending (
41
41
mediaType string ,
42
42
timeWindow string ,
43
+ options map [string ]string ,
43
44
) (* Trending , error ) {
44
45
tmdbURL := fmt .Sprintf (
45
46
"%s/trending/%s/%s?api_key=%s" ,
@@ -48,6 +49,11 @@ func (c *Client) GetTrending(
48
49
timeWindow ,
49
50
c .apiKey ,
50
51
)
52
+ if options != nil {
53
+ for key , value := range options {
54
+ tmdbURL += fmt .Sprintf ("&%s=%s" , key , value )
55
+ }
56
+ }
51
57
trending := Trending {}
52
58
if err := c .get (tmdbURL , & trending ); err != nil {
53
59
return nil , err
Original file line number Diff line number Diff line change 1
1
package tmdb
2
2
3
3
func (suite * TMBDTestSuite ) TestGetTrending () {
4
- trending , err := suite .client .GetTrending ("movie" , "day" )
4
+ trending , err := suite .client .GetTrending ("movie" , "day" , nil )
5
+ suite .Nil (err )
6
+ suite .NotNil (trending )
7
+ }
8
+
9
+ func (suite * TMBDTestSuite ) TestGetTrendingWithOptions () {
10
+ options := map [string ]string {
11
+ "language" : "en-US" ,
12
+ "region" : "US" ,
13
+ }
14
+ trending , err := suite .client .GetTrending ("tv" , "week" , options )
5
15
suite .Nil (err )
6
16
suite .NotNil (trending )
7
17
}
8
18
9
19
func (suite * TMBDTestSuite ) TestGetTrendingFail () {
10
20
suite .client .apiKey = ""
11
- _ , err := suite .client .GetTrending ("movie" , "day" )
21
+ _ , err := suite .client .GetTrending ("movie" , "day" , nil )
12
22
suite .NotNil (err )
13
23
}
You can’t perform that action at this time.
0 commit comments