-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommunicatorBuilder.go
63 lines (48 loc) · 2.02 KB
/
CommunicatorBuilder.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
package connectsdk
import (
"net/url"
"github.com/Worldline-Global-Collect/connect-sdk-go/authentication"
"github.com/Worldline-Global-Collect/connect-sdk-go/communicator"
"github.com/Worldline-Global-Collect/connect-sdk-go/json"
)
// CommunicatorBuilder is the builder for Communicator objects
type CommunicatorBuilder struct {
APIEndpoint *url.URL
Connection communicator.Connection
MetadataProvider *communicator.MetadataProvider
Authenticator authentication.Authenticator
Marshaller json.Marshaller
}
// WithAPIEndpoint sets the Worldline Global Collect platform API endpoint to be used by the Communicator
func (c *CommunicatorBuilder) WithAPIEndpoint(endpoint *url.URL) *CommunicatorBuilder {
c.APIEndpoint = endpoint
return c
}
// WithConnection sets the Connection to be used by the Communicator
func (c *CommunicatorBuilder) WithConnection(connection communicator.Connection) *CommunicatorBuilder {
c.Connection = connection
return c
}
// WithMetadataProvider sets the MetadataProvider to be used by the Communicator
func (c *CommunicatorBuilder) WithMetadataProvider(provider *communicator.MetadataProvider) *CommunicatorBuilder {
c.MetadataProvider = provider
return c
}
// WithAuthenticator sets the Authenticator to be used by the Communicator
func (c *CommunicatorBuilder) WithAuthenticator(auth authentication.Authenticator) *CommunicatorBuilder {
c.Authenticator = auth
return c
}
// WithMarshaller sets the Marshaller to be used by the Communicator
func (c *CommunicatorBuilder) WithMarshaller(marshaller json.Marshaller) *CommunicatorBuilder {
c.Marshaller = marshaller
return c
}
// Build creates a Communicator object based on the builder parameters
func (c *CommunicatorBuilder) Build() (*communicator.Communicator, error) {
return communicator.NewCommunicator(c.APIEndpoint, c.Connection, c.Authenticator, c.MetadataProvider, c.Marshaller)
}
// NewCommunicatorBuilder creates a CommunicatorBuilder object
func NewCommunicatorBuilder() *CommunicatorBuilder {
return &CommunicatorBuilder{}
}