Skip to content

Commit

Permalink
+ add project
Browse files Browse the repository at this point in the history
  • Loading branch information
markus621 committed Nov 26, 2020
1 parent 9abcaab commit 36fe73a
Show file tree
Hide file tree
Showing 4 changed files with 1,553 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ func (v *Client) call(method, path string, req json.Marshaler, resp json.Unmarsh
err error
)

switch method {
case http.MethodGet, http.MethodHead, http.MethodConnect, http.MethodOptions, http.MethodDelete:
body = nil
default:
if req != nil {
body, err = req.MarshalJSON()
if err != nil {
return 0, errors.Wrap(err, "marshal request")
Expand Down Expand Up @@ -97,9 +94,12 @@ func (v *Client) call(method, path string, req json.Marshaler, resp json.Unmarsh
case 204:
case 404:
body, err = nil, errors.New(cresp.Status)
case 401, 403:
case 400, 401, 403:
msg := ErrorResponse{}
body, err = v.readBody(cresp.Body, &msg)
if err != nil {
err = ErrorResponse{Message: string(body)}
}
default:
var raw json.RawMessage
body, err = v.readBody(cresp.Body, &raw)
Expand All @@ -122,7 +122,7 @@ func (v *Client) call(method, path string, req json.Marshaler, resp json.Unmarsh

func (v *Client) readBody(rc io.ReadCloser, resp json.Unmarshaler) (b []byte, err error) {
b, err = ioutil.ReadAll(rc)
if err != nil {
if err != nil || resp == nil {
return
}
err = resp.UnmarshalJSON(b)
Expand Down
6 changes: 6 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {

_, _ = client.GetAccount()
_, _ = client.GetAccountMTEngines()

_, _ = client.SetCallback(cli.Callback{
URL: "https://demo.example/callback",
AdditionalHeaders: []cli.AdditionalHeader{
Expand All @@ -29,4 +30,9 @@ func main() {
_, _ = client.GetCallback()
_ = client.DelCallback()
_, _ = client.GetCallbackLastErrors(10)

_, _ = client.ListProject()
_, _ = client.GetProject("0")
_, _ = client.SetProject("0", cli.PatchProject{})
_ = client.DelProject("0")
}
131 changes: 131 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package smartcatclient

import "net/http"

//go:generate easyjson

const (
uriProject = "/api/integration/v1/project"
uriProjectList = "/api/integration/v1/project/list"
)

//easyjson:json
type (
//ProjectsList model
ProjectsList []Project
//Project model
Project struct {
ID string `json:"id"`
AccountID string `json:"accountId"`
Name string `json:"name"`
Description string `json:"description"`
Deadline string `json:"deadline"`
CreationDate string `json:"creationDate"`
CreatedByUserID string `json:"createdByUserId"`
CreatedByUserEmail string `json:"createdByUserEmail"`
ModificationDate string `json:"modificationDate"`
SourceLanguageID uint64 `json:"sourceLanguageId"`
SourceLanguage string `json:"sourceLanguage"`
TargetLanguages []string `json:"targetLanguages"`
Status string `json:"status"`
StatusModificationDate string `json:"statusModificationDate"`
DomainID uint64 `json:"domainId"`
ClientID uint64 `json:"clientId"`
Vendors []Vendor `json:"vendors"`
WorkflowStages []WorkflowStage `json:"workflowStages"`
Documents []Document `json:"documents"`
ExternalTag string `json:"externalTag"`
Specializations []string `json:"specializations"`
Managers []string `json:"managers"`
Number []string `json:"number"`
}
//Cost model
Cost struct {
Value float64 `json:"value"`
Currency string `json:"currency"`
AccuracyDegree string `json:"accuracyDegree"`
DetailsFileName string `json:"detailsFileName"`
PaymentStatus string `json:"paymentStatus"`
}
//Vendor model
Vendor struct {
VendorAccountID string `json:"vendorAccountId"`
RemovedFromProject bool `json:"removedFromProject"`
Cost Cost `json:"cost"`
CostDetailsFileID string `json:"costDetailsFileId"`
}
//WorkflowStage model
WorkflowStage struct {
Progress uint `json:"progress"`
StageType string `json:"stageType"`
}
//DocumentWorkflowStage model
DocumentWorkflowStage struct {
Progress uint `json:"progress"`
WordsTranslated uint64 `json:"wordsTranslated"`
UnassignedWordsCount uint64 `json:"unassignedWordsCount"`
Status string `json:"status"`
Executives []Executive `json:"executives"`
}
//Executive model
Executive struct {
ID string `json:"id"`
AssignedWordsCount uint64 `json:"assignedWordsCount"`
Progress uint `json:"progress"`
SupplierType string `json:"supplierType"`
}
//Document model
Document struct {
ID string `json:"id"`
Name string `json:"name"`
CreationDate string `json:"creationDate"`
Deadline string `json:"deadline"`
SourceLanguage string `json:"sourceLanguage"`
DisassemblingStatus string `json:"documentDisassemblingStatus"`
TargetLanguage string `json:"targetLanguage"`
Status string `json:"status"`
WordsCount uint64 `json:"wordsCount"`
StatusModificationDate string `json:"statusModificationDate"`
PretranslateCompleted bool `json:"pretranslateCompleted"`
WorkflowStages []DocumentWorkflowStage `json:"workflowStages"`
ExternalID string `json:"externalId"`
MetaInfo string `json:"metaInfo"`
PlaceholdersAreEnabled bool `json:"placeholdersAreEnabled"`
}
//PatchProject model
PatchProject struct {
Name string `json:"name"`
Description string `json:"description"`
Deadline string `json:"deadline"`
ClientID string `json:"clientId"`
DomainID uint64 `json:"domainId"`
VendorAccountIDs []string `json:"vendorAccountIds"`
ExternalTag string `json:"externalTag"`
Specializations []string `json:"specializations"`
WorkflowStages []string `json:"workflowStages"`
}
)

//DelProject Delete the project
func (v *Client) DelProject(id string) (err error) {
_, err = v.call(http.MethodDelete, uriProject+"/"+id, nil, nil)
return
}

//GetProject Receive the project model
func (v *Client) GetProject(id string) (out Project, err error) {
_, err = v.call(http.MethodGet, uriProject+"/"+id, nil, &out)
return
}

//SetProject Change the project model
func (v *Client) SetProject(id string, in PatchProject) (out Project, err error) {
_, err = v.call(http.MethodPut, uriProject+"/"+id, &in, &out)
return
}

//ListProject List all projects
func (v *Client) ListProject() (out ProjectsList, err error) {
_, err = v.call(http.MethodGet, uriProjectList, nil, &out)
return
}
Loading

0 comments on commit 36fe73a

Please sign in to comment.