-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathclient.go
More file actions
66 lines (57 loc) · 1.39 KB
/
Copy pathclient.go
File metadata and controls
66 lines (57 loc) · 1.39 KB
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
package psn
import (
"fmt"
"net/http"
)
// Client represents the PSN API client.
type Client struct {
http *http.Client
lang string
region string
npsso string
accessToken string
refreshToken string
accessExp int32
refreshExp int32
}
// Options holds the configuration for the PSN API client.
type Options struct {
Lang string
Region string
Npsso string
}
// NewClient creates a new PSN API client.
func NewClient(opts *Options) (*Client, error) {
if !isContain(languages, opts.Lang) {
return nil, fmt.Errorf("unsupported language: %s", opts.Lang)
}
if !isContain(regions, opts.Region) {
return nil, fmt.Errorf("unsupported region: %s", opts.Region)
}
return &Client{
http: &http.Client{},
lang: opts.Lang,
region: opts.Region,
npsso: opts.Npsso,
}, nil
}
// Lang returns the client's language.
func (c *Client) Lang() string {
return c.lang
}
// Region returns the client's region.
func (c *Client) Region() string {
return c.region
}
// Npsso returns the client's NPSSO code.
func (c *Client) Npsso() string {
return c.npsso
}
// AccessToken returns the access token and its expiration time.
func (c *Client) AccessToken() (string, int32) {
return c.accessToken, c.accessExp
}
// RefreshToken returns the refresh token and its expiration time.
func (c *Client) RefreshToken() (string, int32) {
return c.refreshToken, c.refreshExp
}