-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
118 lines (112 loc) · 3.15 KB
/
Copy pathexample_test.go
File metadata and controls
118 lines (112 loc) · 3.15 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package streaming_test
import (
"context"
"fmt"
"log"
"os"
"strings"
streaming "github.com/movieofthenight/go-streaming-availability/v4"
)
func ExampleNewAPIClientFromApiKey() {
apiKey, apiKeyFound := os.LookupEnv("API_KEY")
if !apiKeyFound {
log.Fatal("API_KEY not found")
}
streaming.NewAPIClientFromApiKey(apiKey, nil)
}
func ExampleShowsAPIService_GetShow() {
apiKey, apiKeyFound := os.LookupEnv("API_KEY")
if !apiKeyFound {
log.Fatal("API_KEY not found")
}
client := streaming.NewAPIClientFromApiKey(apiKey, nil)
show, _, err := client.ShowsAPI.GetShow(context.Background(), "tt0068646").Country("us").Execute()
if err != nil {
log.Fatal(err)
}
if show == nil {
log.Fatal("Show not found")
}
fmt.Printf("Title: %s\n", show.Title)
fmt.Printf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
fmt.Printf("Available on %s", streamingOption.Service.Name)
switch streamingOption.Type {
case streaming.ADDON:
fmt.Printf(" via addon %s", streamingOption.Addon.Name)
case streaming.BUY:
fmt.Print(" to buy")
case streaming.RENT:
fmt.Print(" to rent")
case streaming.FREE:
fmt.Print(" for free")
}
if streamingOption.HasPrice() {
fmt.Printf(" for %s", streamingOption.Price.Formatted)
}
if streamingOption.HasQuality() {
fmt.Printf(" in %s quality", strings.ToUpper(*streamingOption.Quality))
}
fmt.Printf(" at %s\n", streamingOption.Link)
}
}
func ExampleShowsAPIService_SearchShowsByFilters() {
apiKey, apiKeyFound := os.LookupEnv("API_KEY")
if !apiKeyFound {
log.Fatal("API_KEY not found")
}
client := streaming.NewAPIClientFromApiKey(apiKey, nil)
searchResult, _, err := client.ShowsAPI.SearchShowsByFilters(context.Background()).
Genres([]string{"comedy"}).
OrderBy("popularity_1year").
Country("us").
Catalogs([]string{"netflix"}).Execute()
if err != nil {
log.Fatal(err)
}
if searchResult == nil {
log.Fatal("Search result not found")
}
if len(searchResult.Shows) == 0 {
log.Fatal("No shows found")
}
for _, show := range searchResult.Shows {
fmt.Printf("Title: %s\n", show.Title)
fmt.Printf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
if streamingOption.Service.Id != "netflix" {
continue
}
fmt.Printf("Link: %s\n", streamingOption.Link)
}
}
}
func ExampleApiSearchShowsByFiltersRequest_ExecuteWithAutoPagination() {
apiKey, apiKeyFound := os.LookupEnv("API_KEY")
if !apiKeyFound {
log.Fatal("API_KEY not found")
}
client := streaming.NewAPIClientFromApiKey(apiKey, nil)
shows, err := client.ShowsAPI.SearchShowsByFilters(context.Background()).
Genres([]string{"comedy"}).
OrderBy("popularity_1year").
Country("us").
Catalogs([]string{"netflix"}).ExecuteWithAutoPagination(3)
if err != nil {
log.Fatal(err)
}
for shows.Next() {
show := shows.Get()
fmt.Printf("Title: %s\n", show.Title)
fmt.Printf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
if streamingOption.Service.Id != "netflix" {
continue
}
fmt.Printf("Link: %s\n", streamingOption.Link)
}
}
if shows.Err() != nil {
log.Fatal(shows.Err())
}
}