forked from nathanjjohnson/GoSchedulesDirect
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathavailable_services.go
133 lines (100 loc) · 3.1 KB
/
available_services.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
package schedulesdirect
import (
"encoding/json"
"fmt"
"net/http"
)
// Service describes an available service such as countries.
type Service struct {
Description string `json:"description"`
Type string `json:"type"`
URI string `json:"uri"`
}
// Country describes a country that Schedules Direct supports.
type Country struct {
FullName string `json:"fullName"`
PostalCode string `json:"postalCode"`
PostalCodeExample string `json:"postalCodeExample"`
ShortName string `json:"shortName"`
OnePostalCode bool `json:"onePostalCode"`
}
// AvailableDVBS is a single satellite available via DVB-S.
type AvailableDVBS struct {
Lineup string `json:"lineup"`
}
// GetAvailableServices returns the available services.
func (c *Client) GetAvailableServices() ([]Service, error) {
url := fmt.Sprint(c.BaseURL, APIVersion, "/available")
req, httpErr := http.NewRequest("GET", url, nil)
if httpErr != nil {
return nil, httpErr
}
_, data, err := c.SendRequest(req, false)
if err != nil {
return nil, err
}
r := make([]Service, 0)
err = json.Unmarshal(data, &r)
return r, err
}
// GetAvailableCountries returns the list of countries, grouped by region, supported by Schedules Direct.
func (c *Client) GetAvailableCountries() (map[string][]Country, error) {
url := fmt.Sprint(c.BaseURL, APIVersion, "/available/countries")
req, httpErr := http.NewRequest("GET", url, nil)
if httpErr != nil {
return nil, httpErr
}
_, data, err := c.SendRequest(req, false)
if err != nil {
return nil, err
}
r := make(map[string][]Country)
err = json.Unmarshal(data, &r)
return r, err
}
// GetAvailableLanguages returns the list of language digraphs and their language names.
func (c *Client) GetAvailableLanguages() (map[string]string, error) {
url := fmt.Sprint(c.BaseURL, APIVersion, "/available/languages")
req, httpErr := http.NewRequest("GET", url, nil)
if httpErr != nil {
return nil, httpErr
}
_, data, err := c.SendRequest(req, false)
if err != nil {
return nil, err
}
r := make(map[string]string)
err = json.Unmarshal(data, &r)
return r, err
}
// GetAvailableDVBS returns the list of satellites which are available.
func (c *Client) GetAvailableDVBS() ([]AvailableDVBS, error) {
url := fmt.Sprint(c.BaseURL, APIVersion, "/available/dvb-s")
req, httpErr := http.NewRequest("GET", url, nil)
if httpErr != nil {
return nil, httpErr
}
_, data, err := c.SendRequest(req, false)
if err != nil {
return nil, err
}
r := make([]AvailableDVBS, 0)
err = json.Unmarshal(data, &r)
return r, err
}
// GetAvailableTransmitters returns the list of freeview transmitters in a country for the given countryCode.
// Country options: GBR.
func (c *Client) GetAvailableTransmitters(countryCode string) (map[string]string, error) {
url := fmt.Sprint(c.BaseURL, APIVersion, "/available/transmitters/", countryCode)
req, httpErr := http.NewRequest("GET", url, nil)
if httpErr != nil {
return nil, httpErr
}
_, data, err := c.SendRequest(req, false)
if err != nil {
return nil, err
}
r := make(map[string]string)
err = json.Unmarshal(data, &r)
return r, err
}