forked from koffeinsource/go-imgur
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
47 lines (39 loc) · 1.04 KB
/
client.go
File metadata and controls
47 lines (39 loc) · 1.04 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
package imgur
import (
"errors"
"net/http"
"os"
"github.com/rs/zerolog"
)
// ClientAccount describe authontification
type ClientAccount struct {
clientID string // client ID received after registration
accessToken string // is your secret key used to access the user's data
}
// Client used to for go-imgur
type Client struct {
Log zerolog.Logger
httpClient *http.Client
imgurAccount ClientAccount
rapidAPIKey string
}
// NewClient simply creates an imgur client. RapidAPIKEY is "" if you are using the free API.
func NewClient(httpClient *http.Client, clientID string, rapidAPIKey string) (*Client, error) {
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
if len(clientID) == 0 {
msg := "imgur client ID is empty"
logger.Error().Msg(msg)
return nil, errors.New(msg)
}
if len(rapidAPIKey) == 0 {
logger.Info().Msg("rapid api key is empty")
}
return &Client{
httpClient: httpClient,
Log: logger,
rapidAPIKey: rapidAPIKey,
imgurAccount: ClientAccount{
clientID: clientID,
},
}, nil
}