Skip to content

Commit

Permalink
add stat + create project
Browse files Browse the repository at this point in the history
  • Loading branch information
markus621 committed Dec 7, 2020
1 parent 36fe73a commit 342ae18
Show file tree
Hide file tree
Showing 3 changed files with 1,122 additions and 158 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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 400, 401, 403:
case 400, 401, 403, 202:
msg := ErrorResponse{}
body, err = v.readBody(cresp.Body, &msg)
if err != nil {
Expand Down
142 changes: 120 additions & 22 deletions project.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package smartcatclient

import "net/http"
import (
"fmt"
"net/http"
"time"
)

//go:generate easyjson

const (
uriProject = "/api/integration/v1/project"
uriProjectList = "/api/integration/v1/project/list"
uriProject = "/api/integration/v1/project/%s"
uriProjectList = "/api/integration/v1/project/list"
uriProjectCancel = "/api/integration/v1/project/cancel"
uriProjectRestore = "/api/integration/v1/project/restore"
uriProjectComplete = "/api/integration/v1/project/complete"
uriProjectCreate = "/api/integration/v1/project/create"
uriProjectDocument = "/api/integration/v1/project/document"
uriProjectStatistics = "/api/integration/v2/project/%s/statistics"
uriProjectCWStatistics = "/api/integration/v2/project/%s/completedWorkStatistics"
uriProjectTranslationMemories = "/api/integration/v2/project/%s/translationmemories"
)

//easyjson:json
Expand All @@ -19,16 +31,16 @@ type (
AccountID string `json:"accountId"`
Name string `json:"name"`
Description string `json:"description"`
Deadline string `json:"deadline"`
CreationDate string `json:"creationDate"`
Deadline time.Time `json:"deadline"`
CreationDate time.Time `json:"creationDate"`
CreatedByUserID string `json:"createdByUserId"`
CreatedByUserEmail string `json:"createdByUserEmail"`
ModificationDate string `json:"modificationDate"`
ModificationDate time.Time `json:"modificationDate"`
SourceLanguageID uint64 `json:"sourceLanguageId"`
SourceLanguage string `json:"sourceLanguage"`
TargetLanguages []string `json:"targetLanguages"`
Status string `json:"status"`
StatusModificationDate string `json:"statusModificationDate"`
StatusModificationDate time.Time `json:"statusModificationDate"`
DomainID uint64 `json:"domainId"`
ClientID uint64 `json:"clientId"`
Vendors []Vendor `json:"vendors"`
Expand Down Expand Up @@ -78,14 +90,14 @@ type (
Document struct {
ID string `json:"id"`
Name string `json:"name"`
CreationDate string `json:"creationDate"`
Deadline string `json:"deadline"`
CreationDate time.Time `json:"creationDate"`
Deadline time.Time `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"`
StatusModificationDate time.Time `json:"statusModificationDate"`
PretranslateCompleted bool `json:"pretranslateCompleted"`
WorkflowStages []DocumentWorkflowStage `json:"workflowStages"`
ExternalID string `json:"externalId"`
Expand All @@ -94,33 +106,95 @@ type (
}
//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"`
Name string `json:"name"`
Description string `json:"description"`
Deadline time.Time `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"`
}
//StatisticsList model
StatisticsList []Statistics
//Statistics model
Statistics struct {
Language string `json:"language"`
Statistics []StatisticsItem `json:"statistics"`
Documents []StatisticsDocumentsItem `json:"documents"`
}
//StatisticsItem model
StatisticsItem struct {
Name string `json:"name"`
Words uint64 `json:"words"`
Percent uint `json:"percent"`
Segments uint16 `json:"segments"`
Pages float64 `json:"pages"`
CharsWithoutSpaces uint64 `json:"charsWithoutSpaces"`
CharsWithSpaces uint64 `json:"charsWithSpaces"`
EffectiveWordsForBilling uint64 `json:"effectiveWordsForBilling"`
}
//StatisticsDocumentsItem model
StatisticsDocumentsItem struct {
Name string `json:"name"`
Statistics []StatisticsItem `json:"statistics"`
}
//CompletedWorkStatisticsList model
CompletedWorkStatisticsList []CompletedWorkStatistics
//CompletedWorkStatistics model
CompletedWorkStatistics struct {
Executive struct {
ID string `json:"id"`
SupplierType string `json:"supplierType"`
} `json:"executive"`
StageType string `json:"stageType"`
StageNumber int `json:"stageNumber"`
TargetLanguage string `json:"targetLanguage"`
Total []StatisticsItem `json:"total"`
Documents []StatisticsDocumentsItem `json:"documents"`
}
//TranslationMemories model
TranslationMemories []struct {
ID string `json:"id"`
MatchThreshold int `json:"matchThreshold"`
IsWritable bool `json:"isWritable"`
}
)

//DelProject Delete the project
func (v *Client) DelProject(id string) (err error) {
_, err = v.call(http.MethodDelete, uriProject+"/"+id, nil, nil)
_, err = v.call(http.MethodDelete, fmt.Sprintf(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)
_, err = v.call(http.MethodGet, fmt.Sprintf(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)
_, err = v.call(http.MethodPut, fmt.Sprintf(uriProject, id), &in, &out)
return
}

//CancelProject Cancel the project
func (v *Client) CancelProject(id string) (err error) {
_, err = v.call(http.MethodPost, uriProjectCancel+"?projectId="+id, nil, nil)
return
}

//RestoreProject Restore the project
func (v *Client) RestoreProject(id string) (err error) {
_, err = v.call(http.MethodPost, uriProjectRestore+"?projectId="+id, nil, nil)
return
}

//CompleteProject Complete the project
func (v *Client) CompleteProject(id string) (err error) {
_, err = v.call(http.MethodPost, uriProjectComplete+"?projectId="+id, nil, nil)
return
}

Expand All @@ -129,3 +203,27 @@ func (v *Client) ListProject() (out ProjectsList, err error) {
_, err = v.call(http.MethodGet, uriProjectList, nil, &out)
return
}

//GetProjectStatistics Receive statistics
func (v *Client) GetProjectStatistics(id string) (out StatisticsList, err error) {
_, err = v.call(http.MethodGet, uriProjectStatistics, nil, &out)
return
}

//GetProjectCompletedWorkStatistics Receiving statistics for the completed parts of the project
func (v *Client) GetProjectCompletedWorkStatistics(id string) (out CompletedWorkStatisticsList, err error) {
_, err = v.call(http.MethodGet, uriProjectCWStatistics, nil, &out)
return
}

//GetProjectTranslationMemories Receiving a list of the TMs plugged into the project
func (v *Client) GetProjectTranslationMemories(id string) (out TranslationMemories, err error) {
_, err = v.call(http.MethodGet, uriProjectTranslationMemories, nil, &out)
return
}

//SetProjectTranslationMemories Receiving a list of the TMs plugged into the project
func (v *Client) SetProjectTranslationMemories(id string, in TranslationMemories) (err error) {
_, err = v.call(http.MethodGet, uriProjectTranslationMemories, &in, nil)
return
}
Loading

0 comments on commit 342ae18

Please sign in to comment.