forked from MaulIlham/wc-api-go
/
options.go
112 lines (94 loc) · 2.93 KB
/
options.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
package options // import "github.com/Buccaneer69/wc-api-go/options"
import (
"strconv"
"time"
)
// Default WooCommerce REST API version
const defaultVersion string = "v3"
// Default request timeout.
const timeout int = 15
// Default WP API prefix. Including leading and trailing slashes.
const defaultPrefix string = "/wp-json/"
// DefaultAPIPrefix ...
const DefaultAPIPrefix = "/wc-api/"
// DefaultUserAgent ... No version number.
const DefaultUserAgent string = "WooCommerce API Client-Go"
// Basic options of WooCommerce API Client
type Basic struct {
URL string // Store URL
Key string // API Consumer Key
Secret string // API Consumer Secret
Options Advanced // Advanced Options (see below)
}
// Advanced options of WooCommerce API Client
type Advanced struct {
WPAPI bool // Allow make requests to the new WP REST API integration
WPAPIPrefix string // Custom WP REST API URL prefix
Version string // API version, default is v3
Timeout int // Request timeout, default is 15
FollowRedirects bool // Allow the API call to follow redirects
verifySslInitialized bool
VerifySsl bool // Verify SSL when connect
QueryStringAuth bool // Force Basic Authentication
OAuthTimestamp string // Custom oAuth timestamp
UserAgent string // Custom user-agent
}
// Version of WooCommerce API which will be used
func (o *Basic) Version() string {
if "" == o.Options.Version {
return defaultVersion
}
return o.Options.Version
}
// VerifySsl return requirement of SSL certificate check
func (o *Basic) VerifySsl() bool {
if false == o.Options.verifySslInitialized {
return true
}
return o.Options.VerifySsl
}
// DisableSslVerification in case of debug
func (o *Basic) DisableSslVerification() {
o.Options.verifySslInitialized = true
o.Options.VerifySsl = false
}
// Timeout per request to WooCommerce API
func (o *Basic) Timeout() int {
if 0 == o.Options.Timeout {
return timeout
}
return o.Options.Timeout
}
// QueryStringAuth returns true when credentials will pass through query string
func (o *Basic) QueryStringAuth() bool {
return o.Options.QueryStringAuth
}
// WPAPI returns if used WordPress API or not
func (o *Basic) WPAPI() bool {
return o.Options.WPAPI
}
// WPAPIPrefix is a prefix for WordPress API requests
func (o *Basic) WPAPIPrefix() string {
if "" == o.Options.WPAPIPrefix {
return defaultPrefix
}
return o.Options.WPAPIPrefix
}
// OAuthTimestamp return OAuth specific timestamp
func (o *Basic) OAuthTimestamp() string {
if "" == o.Options.OAuthTimestamp {
return strconv.FormatInt(time.Now().Unix(), 10)
}
return o.Options.OAuthTimestamp
}
// UserAgent which will be use for requests
func (o *Basic) UserAgent() string {
if "" == o.Options.UserAgent {
return DefaultUserAgent
}
return o.Options.UserAgent
}
// FollowRedirects during requests
func (o *Basic) FollowRedirects() bool {
return o.Options.FollowRedirects
}