forked from cyruzin/golang-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompanies.go
114 lines (106 loc) · 3.05 KB
/
companies.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
package tmdb
import (
"fmt"
)
// CompanyDetails type is a struct for details JSON response.
type CompanyDetails struct {
Description string `json:"description"`
Headquarters string `json:"headquarters"`
Homepage string `json:"homepage"`
ID int64 `json:"id"`
LogoPath string `json:"logo_path"`
Name string `json:"name"`
OriginCountry string `json:"origin_country"`
ParentCompany struct {
Name string `json:"name"`
ID int64 `json:"id"`
LogoPath string `json:"logo_path"`
} `json:"parent_company"`
}
// GetCompanyDetails get a companies details by id.
//
// https://developers.themoviedb.org/3/companies/get-company-details
func (c *Client) GetCompanyDetails(
id int,
) (*CompanyDetails, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d?api_key=%s",
baseURL,
companyURL,
id,
c.apiKey,
)
companyDetails := CompanyDetails{}
if err := c.get(tmdbURL, &companyDetails); err != nil {
return nil, err
}
return &companyDetails, nil
}
// CompanyAlternativeNames type is a struct for alternative
// names JSON response.
type CompanyAlternativeNames struct {
ID int64 `json:"id"`
*CompanyAlternativeNamesResult
}
// GetCompanyAlternativeNames get the alternative names of a company.
//
// https://developers.themoviedb.org/3/companies/get-company-alternative-names
func (c *Client) GetCompanyAlternativeNames(
id int,
) (*CompanyAlternativeNames, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/alternative_names?api_key=%s",
baseURL,
companyURL,
id,
c.apiKey,
)
companyAlternativeNames := CompanyAlternativeNames{}
if err := c.get(tmdbURL, &companyAlternativeNames); err != nil {
return nil, err
}
return &companyAlternativeNames, nil
}
// CompanyImage type is a struct for a single image.
type CompanyImage struct {
AspectRatio float32 `json:"aspect_ratio"`
FilePath string `json:"file_path"`
Height int `json:"height"`
ID string `json:"id"`
FileType string `json:"file_type"`
VoteAverage float32 `json:"vote_average"`
VoteCount int64 `json:"vote_count"`
Width int `json:"width"`
}
// CompanyImages type is a struct for images JSON response.
type CompanyImages struct {
ID int64 `json:"id"`
Logos []CompanyImage `json:"logos"`
}
// GetCompanyImages get a companies logos by id.
//
// There are two image formats that are supported for companies,
// PNG's and SVG's. You can see which type the original file is
// by looking at the file_type field. We prefer SVG's as they
// are resolution independent and as such, the width and height
// are only there to reflect the original asset that was uploaded.
// An SVG can be scaled properly beyond those dimensions if you
// call them as a PNG.
//
// https://developers.themoviedb.org/3/companies/get-company-images
func (c *Client) GetCompanyImages(
id int,
) (*CompanyImages, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/images?api_key=%s",
baseURL,
companyURL,
id,
c.apiKey,
)
companyImages := CompanyImages{}
if err := c.get(tmdbURL, &companyImages); err != nil {
return nil, err
}
return &companyImages, nil
}