-
Notifications
You must be signed in to change notification settings - Fork 0
/
streaming_test.go
167 lines (160 loc) · 4.61 KB
/
streaming_test.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package streaming_test
import (
"context"
"log"
"os"
"strings"
"testing"
"github.com/movieofthenight/go-streaming-availability/v4"
)
func TestShowsAPIService_GetShow(t *testing.T) {
rapidApiKey, rapidApiKeyFound := os.LookupEnv("RAPID_API_KEY")
if !rapidApiKeyFound {
t.Fatal("RAPID_API_KEY not found")
}
client := streaming.NewAPIClientFromRapidAPIKey(rapidApiKey, 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")
}
t.Logf("Title: %s\n", show.Title)
t.Logf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
t.Logf("Available on %s", streamingOption.Service.Name)
switch streamingOption.Type {
case streaming.ADDON:
t.Logf(" via addon %s", streamingOption.Addon.Name)
case streaming.BUY:
t.Log(" to buy")
case streaming.RENT:
t.Log(" to rent")
case streaming.FREE:
t.Log(" for free")
}
if streamingOption.Price != nil {
t.Logf(" for %s", streamingOption.Price.Formatted)
}
if streamingOption.Quality != nil {
t.Logf(" in %s quality", strings.ToUpper(*streamingOption.Quality))
}
t.Logf(" at %s\n", streamingOption.Link)
}
}
func TestShowsAPIService_SearchShowsByFilters(t *testing.T) {
rapidApiKey, rapidApiKeyFound := os.LookupEnv("RAPID_API_KEY")
if !rapidApiKeyFound {
t.Fatal("RAPID_API_KEY not found")
}
client := streaming.NewAPIClientFromRapidAPIKey(rapidApiKey, 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 {
t.Logf("Title: %s\n", show.Title)
t.Logf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
if streamingOption.Service.Id != "netflix" {
continue
}
t.Logf("Link: %s\n", streamingOption.Link)
}
}
}
func TestApiSearchShowsByFiltersRequest_ExecuteWithAutoPagination(t *testing.T) {
rapidApiKey, rapidApiKeyFound := os.LookupEnv("RAPID_API_KEY")
if !rapidApiKeyFound {
t.Fatal("RAPID_API_KEY not found")
}
client := streaming.NewAPIClientFromRapidAPIKey(rapidApiKey, 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()
t.Logf("Title: %s\n", show.Title)
t.Logf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
if streamingOption.Service.Id != "netflix" {
continue
}
t.Logf("Link: %s\n", streamingOption.Link)
}
}
if shows.Err() != nil {
log.Fatal(shows.Err())
}
}
func TestApiSearchShowsByFiltersRequest_ExecuteWithAutoPagination2(t *testing.T) {
rapidApiKey, rapidApiKeyFound := os.LookupEnv("RAPID_API_KEY")
if !rapidApiKeyFound {
t.Fatal("RAPID_API_KEY not found")
}
client := streaming.NewAPIClientFromRapidAPIKey(rapidApiKey, nil)
shows, err := client.ShowsAPI.SearchShowsByFilters(context.Background()).
Genres([]string{"comedy"}).
OrderBy("popularity_1year").
YearMax(2020).
YearMin(2019).
Country("us").
Catalogs([]string{"netflix"}).ExecuteWithAutoPagination(0)
if err != nil {
log.Fatal(err)
}
for shows.Next() {
show := shows.Get()
t.Logf("Title: %s\n", show.Title)
t.Logf("Overview: %s\n", show.Overview)
for _, streamingOption := range show.StreamingOptions["us"] {
if streamingOption.Service.Id != "netflix" {
continue
}
t.Logf("Link: %s\n", streamingOption.Link)
}
}
if shows.Err() != nil {
log.Fatal(shows.Err())
}
}
func TestApiGetChangesRequest_ExecuteWithAutoPagination(t *testing.T) {
rapidApiKey, rapidApiKeyFound := os.LookupEnv("RAPID_API_KEY")
if !rapidApiKeyFound {
t.Fatal("RAPID_API_KEY not found")
}
client := streaming.NewAPIClientFromRapidAPIKey(rapidApiKey, nil)
changes, err := client.ChangesAPI.GetChanges(context.Background()).
Catalogs([]string{"netflix"}).
ItemType("show").
ChangeType("new").
Country("us").
ExecuteWithAutoPagination(2)
if err != nil {
log.Fatal(err)
}
for changes.Next() {
change := changes.Get()
t.Logf("Title: %s\n", change.Show.Title)
t.Logf("Overview: %s\n", change.Show.Overview)
}
if changes.Err() != nil {
log.Fatal(changes.Err())
}
}