-
Notifications
You must be signed in to change notification settings - Fork 10
/
client.go
46 lines (38 loc) · 1.01 KB
/
client.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
package imgur
import (
"fmt"
"net/http"
"github.com/koffeinsource/go-klogger"
)
// 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 klogger.KLogger
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 := new(klogger.CLILogger)
if len(clientID) == 0 {
msg := "imgur client ID is empty"
logger.Errorf(msg)
return nil, fmt.Errorf(msg)
}
if len(rapidAPIKey) == 0 {
logger.Infof("rapid api key is empty")
}
return &Client{
httpClient: httpClient,
Log: logger,
rapidAPIKey: rapidAPIKey,
imgurAccount: ClientAccount{
clientID: clientID,
},
}, nil
}