-
Notifications
You must be signed in to change notification settings - Fork 36
/
configuration.go
200 lines (187 loc) · 6.19 KB
/
configuration.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package tmdb
import "fmt"
// ConfigurationAPI type is a struct for api configuration JSON response.
type ConfigurationAPI struct {
Images struct {
BaseURL string `json:"base_url"`
SecureBaseURL string `json:"secure_base_url"`
BackdropSizes []string `json:"backdrop_sizes"`
LogoSizes []string `json:"logo_sizes"`
PosterSizes []string `json:"poster_sizes"`
ProfileSizes []string `json:"profile_sizes"`
StillSizes []string `json:"still_sizes"`
} `json:"images"`
ChangeKeys []string `json:"change_keys"`
}
// GetConfigurationAPI get the system wide configuration information.
//
// Some elements of the API require some knowledge of
// this configuration data. The purpose of this is to
// try and keep the actual API responses as light as possible.
// It is recommended you cache this data within your application
// and check for updates every few days.
//
// This method currently holds the data relevant to building image
// URLs as well as the change key map.
//
// To build an image URL, you will need 3 pieces of data. The base_url,
// size and file_path. Simply combine them all and you will have a fully
// qualified URL. Here’s an example URL:
//
// https://image.tmdb.org/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg
//
// The configuration method also contains the list of change keys which
// can be useful if you are building an app that consumes data from the
// change feed.
//
// https://developers.themoviedb.org/3/configuration/get-api-configuration
func (c *Client) GetConfigurationAPI() (*ConfigurationAPI, error) {
tmdbURL := fmt.Sprintf(
"%s/configuration?api_key=%s",
baseURL,
c.apiKey,
)
configurationAPI := ConfigurationAPI{}
if err := c.get(tmdbURL, &configurationAPI); err != nil {
return nil, err
}
return &configurationAPI, nil
}
// ConfigurationCountries type is a struct for countries configuration JSON response.
type ConfigurationCountries []struct {
Iso3166_1 string `json:"iso_3166_1"`
EnglishName string `json:"english_name"`
NativeName string `json:"native_name"`
}
// GetConfigurationCountries get the list of countries
// (ISO 3166-1 tags) used throughout TMDb.
//
// https://developers.themoviedb.org/3/configuration/get-countries
func (c *Client) GetConfigurationCountries() (
*ConfigurationCountries,
error,
) {
tmdbURL := fmt.Sprintf(
"%s%scountries?api_key=%s",
baseURL,
configurationURL,
c.apiKey,
)
configurationCountries := ConfigurationCountries{}
if err := c.get(tmdbURL, &configurationCountries); err != nil {
return nil, err
}
return &configurationCountries, nil
}
// ConfigurationJobs type is a struct for jobs configuration JSON response.
type ConfigurationJobs []struct {
Department string `json:"department"`
Jobs []string `json:"jobs"`
}
// GetConfigurationJobs get a list of the jobs and departments we use on TMDb.
//
// https://developers.themoviedb.org/3/configuration/get-jobs
func (c *Client) GetConfigurationJobs() (*ConfigurationJobs, error) {
tmdbURL := fmt.Sprintf(
"%s%sjobs?api_key=%s",
baseURL,
configurationURL,
c.apiKey,
)
configurationJobs := ConfigurationJobs{}
if err := c.get(tmdbURL, &configurationJobs); err != nil {
return nil, err
}
return &configurationJobs, nil
}
// ConfigurationLanguages type is a struct for languages configuration JSON response.
type ConfigurationLanguages []struct {
Iso639_1 string `json:"iso_639_1"`
EnglishName string `json:"english_name"`
Name string `json:"name"`
}
// GetConfigurationLanguages get the list of languages
// (ISO 639-1 tags) used throughout TMDb.
//
// https://developers.themoviedb.org/3/configuration/get-languages
func (c *Client) GetConfigurationLanguages() (
*ConfigurationLanguages,
error,
) {
tmdbURL := fmt.Sprintf(
"%s%slanguages?api_key=%s",
baseURL,
configurationURL,
c.apiKey,
)
configurationLanguages := ConfigurationLanguages{}
if err := c.get(tmdbURL, &configurationLanguages); err != nil {
return nil, err
}
return &configurationLanguages, nil
}
// ConfigurationPrimaryTranslations type is a struct for
// primary translations configuration JSON response.
type ConfigurationPrimaryTranslations []string
// GetConfigurationPrimaryTranslations get a list of the officially
// supported translations on TMDb.
//
// While it's technically possible to add a translation in any one
// of the languages we have added to TMDb (we don't restrict content),
// the ones listed in this method are the ones we also support for
// localizing the website with which means they are what we refer to
// as the "primary" translations.
//
// These are all specified as IETF tags to identify the languages
// we use on TMDb. There is one exception which is image languages.
// They are currently only designated by a ISO-639-1 tag. This is
// a planned upgrade for the future.
//
// We're always open to adding more if you think one should be added.
// You can ask about getting a new primary translation added by posting
// on the forums.
//
// One more thing to mention, these are the translations that map to
// our website translation project.
//
// https://developers.themoviedb.org/3/configuration/get-primary-translations
func (c *Client) GetConfigurationPrimaryTranslations() (
*ConfigurationPrimaryTranslations,
error,
) {
tmdbURL := fmt.Sprintf(
"%s%sprimary_translations?api_key=%s",
baseURL, configurationURL, c.apiKey,
)
configurationPrimaryTranslations := ConfigurationPrimaryTranslations{}
if err := c.get(tmdbURL, &configurationPrimaryTranslations); err != nil {
return nil, err
}
return &configurationPrimaryTranslations, nil
}
// ConfigurationTimezones type is a struct for timezones
// configuration JSON response.
type ConfigurationTimezones []struct {
Iso3166_1 string `json:"iso_3166_1"`
Zones []string `json:"zones"`
}
// GetConfigurationTimezones get the list of timezones
// used throughout TMDb.
//
// https://developers.themoviedb.org/3/configuration/get-timezones
func (c *Client) GetConfigurationTimezones() (
*ConfigurationTimezones,
error,
) {
tmdbURL := fmt.Sprintf(
"%s%stimezones?api_key=%s",
baseURL,
configurationURL,
c.apiKey,
)
configurationTimeZones := ConfigurationTimezones{}
if err := c.get(tmdbURL, &configurationTimeZones); err != nil {
return nil, err
}
return &configurationTimeZones, nil
}