-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
57 lines (45 loc) · 1.31 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
47
48
49
50
51
52
53
54
55
56
57
package lmpm
import "fmt"
// Client to access LMPM API
type Client struct {
CompanyID CompanyID
APIKey string
BaseUrl Environment
}
func Init(companyIDAsString string, apiKey string, environment Environment) (*Client, error) {
errValidatingInput := validateInput(companyIDAsString, apiKey, environment)
if errValidatingInput != nil {
return nil, errValidatingInput
}
return &Client{
CompanyID: CompanyID(companyIDAsString),
APIKey: apiKey,
BaseUrl: environment,
}, nil
}
func validateInput(companyID string, apiKey string, environment Environment) error {
if companyID == "" {
return fmt.Errorf("Company ID is empty")
}
if apiKey == "" {
return fmt.Errorf("API Key not provided")
}
if environment != environments.Production && environment != environments.Development {
return fmt.Errorf("Unknown environment %s", string(environment))
}
return nil
}
type CompanyID string
type Environment string
type allEnvironments struct {
Production Environment
Development Environment
}
func GetEnvironments() *allEnvironments {
return &allEnvironments{
Production: EnvironmentProduction,
Development: EnvironmentDevelopment,
}
}
const EnvironmentProduction Environment = "https://integrations.api.lmpm.com/v1"
const EnvironmentDevelopment Environment = "https://integrations.api.lmpm.biz/v1"