forked from tzmfreedom/spm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforce.go
44 lines (37 loc) · 1.26 KB
/
force.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
package main
import (
"encoding/base64"
)
type ForceClient struct {
portType *MetadataPortType
loginResult *LoginResult
}
func NewForceClient(endpoint string, apiversion string) *ForceClient {
portType := NewMetadataPortType("https://"+endpoint+"/services/Soap/u/"+apiversion, true, nil)
return &ForceClient{portType: portType}
}
func (client *ForceClient) Login(username string, password string) error {
loginRequest := LoginRequest{Username: username, Password: password}
loginResponse, err := client.portType.Login(&loginRequest)
if err != nil {
return err
}
client.loginResult = &loginResponse.LoginResult
return nil
}
func (client *ForceClient) Deploy(buf []byte) (*DeployResponse, error) {
request := Deploy{
ZipFile: base64.StdEncoding.EncodeToString(buf),
DeployOptions: nil,
}
sessionHeader := SessionHeader{
SessionId: client.loginResult.SessionId,
}
client.portType.SetHeader(&sessionHeader)
client.portType.SetServerUrl(client.loginResult.MetadataServerUrl)
return client.portType.Deploy(&request)
}
func (client *ForceClient) CheckDeployStatus(resultId *ID) (*CheckDeployStatusResponse, error) {
check_request := CheckDeployStatus{AsyncProcessId: resultId, IncludeDetails: true}
return client.portType.CheckDeployStatus(&check_request)
}