This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
companies.go
98 lines (90 loc) · 2.73 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
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 *ParentCompany `json:"parent_company"`
}
type ParentCompany struct {
Name string `json:"name"`
ID int64 `json:"id"`
LogoPath string `json:"logo_path"`
}
// CompanyAlternativeNames type is a struct for alternative
// names JSON response.
type CompanyAlternativeNames struct {
ID int64 `json:"id"`
*CompanyAlternativeNamesResults
}
// CompanyImages type is a struct for images JSON response.
type CompanyImages struct {
ID int64 `json:"id"`
Logos []*Image `json:"logos"`
}
// GetCompanyDetails get a companies details by id.
//
// https://developers.themoviedb.org/3/companies/get-company-details
func (c *Client) GetCompanyDetails(id int64) (*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
}
// GetCompanyAlternativeNames get the alternative names of a company.
//
// https://developers.themoviedb.org/3/companies/get-company-alternative-names
func (c *Client) GetCompanyAlternativeNames(id int64) (*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
}
// 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 int64) (*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
}