From 1061d106e68d4cb7d1f9742255950ee01a9a6a7a Mon Sep 17 00:00:00 2001 From: Stefan Bruhns Date: Fri, 15 Sep 2017 09:21:10 +0200 Subject: [PATCH] add jobs api --- Godeps/Godeps.json | 6 +- router.go | 613 ++++++++++++++++- .../phrase/phraseapp-go/phraseapp/client.go | 5 + .../phrase/phraseapp-go/phraseapp/config.go | 2 + .../phrase/phraseapp-go/phraseapp/error.go | 4 + .../phrase/phraseapp-go/phraseapp/lib.go | 632 +++++++++++++++++- 6 files changed, 1251 insertions(+), 11 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 275edf3..85fc004 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,7 +1,7 @@ { "ImportPath": "github.com/phrase/phraseapp-client", - "GoVersion": "go1.7", - "GodepVersion": "v75", + "GoVersion": "go1.9", + "GodepVersion": "v79", "Packages": [ "./..." ], @@ -56,7 +56,7 @@ }, { "ImportPath": "github.com/phrase/phraseapp-go/phraseapp", - "Rev": "9d8f995f286f559bc78f976fe2fe4cfbd78d7089" + "Rev": "df3251df611770a34e612f89c2e69b88342cce98" }, { "ImportPath": "gopkg.in/yaml.v2", diff --git a/router.go b/router.go index 6110ddb..fc3795c 100644 --- a/router.go +++ b/router.go @@ -9,8 +9,8 @@ import ( ) const ( - RevisionDocs = "ae7df97629e13d98990793ba65bfd94f6a50cda8" - RevisionGenerator = "e51df86b2d0cf519540791cefb4f6d24751d38b0" + RevisionDocs = "" + RevisionGenerator = "" ) func router(cfg *phraseapp.Config) (*cli.Router, error) { @@ -152,6 +152,64 @@ func router(cfg *phraseapp.Config) (*cli.Router, error) { r.Register("invitations/list", newInvitationsList(cfg), "List invitations for an account. It will also list the accessible resources like projects and locales the invited user has access to. In case nothing is shown the default access from the role is used. Access token scope must include team.manage.") + r.Register("job/complete", newJobComplete(cfg), "Mark a job as completed.") + + if cmd, err := newJobCreate(cfg); err != nil { + return nil, err + } else { + r.Register("job/create", cmd, "Create a new job.") + } + + r.Register("job/delete", newJobDelete(cfg), "Delete an existing job.") + + if cmd, err := newJobKeysCreate(cfg); err != nil { + return nil, err + } else { + r.Register("job/keys/create", cmd, "Add multiple keys to a existing job.") + } + + if cmd, err := newJobKeysDelete(cfg); err != nil { + return nil, err + } else { + r.Register("job/keys/delete", cmd, "Remove multiple keys from existing job.") + } + + r.Register("job/show", newJobShow(cfg), "Get details on a single job for a given project.") + + r.Register("job/start", newJobStart(cfg), "Starts an existing job in state draft.") + + if cmd, err := newJobUpdate(cfg); err != nil { + return nil, err + } else { + r.Register("job/update", cmd, "Update an existing job.") + } + + r.Register("job_locale/complete", newJobLocaleComplete(cfg), "Mark a JobLocale as completed.") + + r.Register("job_locale/delete", newJobLocaleDelete(cfg), "Delete an existing JobLocale.") + + r.Register("job_locale/show", newJobLocaleShow(cfg), "Get a single JobLocale for a given job.") + + if cmd, err := newJobLocaleUpdate(cfg); err != nil { + return nil, err + } else { + r.Register("job_locale/update", cmd, "Update an existing job.") + } + + if cmd, err := newJobLocalesCreate(cfg); err != nil { + return nil, err + } else { + r.Register("job_locales/create", cmd, "Create a new JobLocale.") + } + + r.Register("job_locales/list", newJobLocalesList(cfg), "List all JobLocales for a given job.") + + if cmd, err := newJobsList(cfg); err != nil { + return nil, err + } else { + r.Register("jobs/list", cmd, "List all jobs for the given project.") + } + if cmd, err := newKeyCreate(cfg); err != nil { return nil, err } else { @@ -351,13 +409,13 @@ func router(cfg *phraseapp.Config) (*cli.Router, error) { if cmd, err := newTranslationsUnverify(cfg); err != nil { return nil, err } else { - r.Register("translations/unverify", cmd, "Mark translations matching query as unverified.") + r.Register("translations/unverify", cmd, "
Only available in the Control Package.
Mark translations matching query as unverified.") } if cmd, err := newTranslationsVerify(cfg); err != nil { return nil, err } else { - r.Register("translations/verify", cmd, "Verify translations matching query.") + r.Register("translations/verify", cmd, "
Only available in the Control Package.
Verify translations matching query.") } if cmd, err := newUploadCreate(cfg); err != nil { @@ -1802,6 +1860,553 @@ func (cmd *InvitationsList) Run() error { return json.NewEncoder(os.Stdout).Encode(&res) } +type JobComplete struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobComplete(cfg *phraseapp.Config) *JobComplete { + + actionJobComplete := &JobComplete{Config: *cfg} + actionJobComplete.ProjectID = cfg.DefaultProjectID + + return actionJobComplete +} + +func (cmd *JobComplete) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobComplete(cmd.ProjectID, cmd.ID) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobCreate struct { + phraseapp.Config + + phraseapp.JobParams + + ProjectID string `cli:"arg required"` +} + +func newJobCreate(cfg *phraseapp.Config) (*JobCreate, error) { + + actionJobCreate := &JobCreate{Config: *cfg} + actionJobCreate.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobCreate.Config.Defaults["job/create"] + if defaultsPresent { + if err := actionJobCreate.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobCreate, nil +} + +func (cmd *JobCreate) Run() error { + params := &cmd.JobParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobCreate(cmd.ProjectID, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobDelete struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobDelete(cfg *phraseapp.Config) *JobDelete { + + actionJobDelete := &JobDelete{Config: *cfg} + actionJobDelete.ProjectID = cfg.DefaultProjectID + + return actionJobDelete +} + +func (cmd *JobDelete) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + err = client.JobDelete(cmd.ProjectID, cmd.ID) + + if err != nil { + return err + } + + return nil +} + +type JobKeysCreate struct { + phraseapp.Config + + phraseapp.JobKeysCreateParams + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobKeysCreate(cfg *phraseapp.Config) (*JobKeysCreate, error) { + + actionJobKeysCreate := &JobKeysCreate{Config: *cfg} + actionJobKeysCreate.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobKeysCreate.Config.Defaults["job/keys/create"] + if defaultsPresent { + if err := actionJobKeysCreate.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobKeysCreate, nil +} + +func (cmd *JobKeysCreate) Run() error { + params := &cmd.JobKeysCreateParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobKeysCreate(cmd.ProjectID, cmd.ID, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobKeysDelete struct { + phraseapp.Config + + phraseapp.JobKeysDeleteParams + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobKeysDelete(cfg *phraseapp.Config) (*JobKeysDelete, error) { + + actionJobKeysDelete := &JobKeysDelete{Config: *cfg} + actionJobKeysDelete.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobKeysDelete.Config.Defaults["job/keys/delete"] + if defaultsPresent { + if err := actionJobKeysDelete.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobKeysDelete, nil +} + +func (cmd *JobKeysDelete) Run() error { + params := &cmd.JobKeysDeleteParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + err = client.JobKeysDelete(cmd.ProjectID, cmd.ID, params) + + if err != nil { + return err + } + + return nil +} + +type JobShow struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobShow(cfg *phraseapp.Config) *JobShow { + + actionJobShow := &JobShow{Config: *cfg} + actionJobShow.ProjectID = cfg.DefaultProjectID + + return actionJobShow +} + +func (cmd *JobShow) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobShow(cmd.ProjectID, cmd.ID) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobStart struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobStart(cfg *phraseapp.Config) *JobStart { + + actionJobStart := &JobStart{Config: *cfg} + actionJobStart.ProjectID = cfg.DefaultProjectID + + return actionJobStart +} + +func (cmd *JobStart) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobStart(cmd.ProjectID, cmd.ID) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobUpdate struct { + phraseapp.Config + + phraseapp.JobUpdateParams + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobUpdate(cfg *phraseapp.Config) (*JobUpdate, error) { + + actionJobUpdate := &JobUpdate{Config: *cfg} + actionJobUpdate.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobUpdate.Config.Defaults["job/update"] + if defaultsPresent { + if err := actionJobUpdate.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobUpdate, nil +} + +func (cmd *JobUpdate) Run() error { + params := &cmd.JobUpdateParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobUpdate(cmd.ProjectID, cmd.ID, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobLocaleComplete struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobLocaleComplete(cfg *phraseapp.Config) *JobLocaleComplete { + + actionJobLocaleComplete := &JobLocaleComplete{Config: *cfg} + actionJobLocaleComplete.ProjectID = cfg.DefaultProjectID + + return actionJobLocaleComplete +} + +func (cmd *JobLocaleComplete) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobLocaleComplete(cmd.ProjectID, cmd.ID) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobLocaleDelete struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + JobID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobLocaleDelete(cfg *phraseapp.Config) *JobLocaleDelete { + + actionJobLocaleDelete := &JobLocaleDelete{Config: *cfg} + actionJobLocaleDelete.ProjectID = cfg.DefaultProjectID + + return actionJobLocaleDelete +} + +func (cmd *JobLocaleDelete) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + err = client.JobLocaleDelete(cmd.ProjectID, cmd.JobID, cmd.ID) + + if err != nil { + return err + } + + return nil +} + +type JobLocaleShow struct { + phraseapp.Config + + ProjectID string `cli:"arg required"` + JobID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobLocaleShow(cfg *phraseapp.Config) *JobLocaleShow { + + actionJobLocaleShow := &JobLocaleShow{Config: *cfg} + actionJobLocaleShow.ProjectID = cfg.DefaultProjectID + + return actionJobLocaleShow +} + +func (cmd *JobLocaleShow) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobLocaleShow(cmd.ProjectID, cmd.JobID, cmd.ID) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobLocaleUpdate struct { + phraseapp.Config + + phraseapp.JobLocaleParams + + ProjectID string `cli:"arg required"` + JobID string `cli:"arg required"` + ID string `cli:"arg required"` +} + +func newJobLocaleUpdate(cfg *phraseapp.Config) (*JobLocaleUpdate, error) { + + actionJobLocaleUpdate := &JobLocaleUpdate{Config: *cfg} + actionJobLocaleUpdate.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobLocaleUpdate.Config.Defaults["job_locale/update"] + if defaultsPresent { + if err := actionJobLocaleUpdate.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobLocaleUpdate, nil +} + +func (cmd *JobLocaleUpdate) Run() error { + params := &cmd.JobLocaleParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobLocaleUpdate(cmd.ProjectID, cmd.JobID, cmd.ID, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobLocalesCreate struct { + phraseapp.Config + + phraseapp.JobLocaleParams + + ProjectID string `cli:"arg required"` + JobID string `cli:"arg required"` +} + +func newJobLocalesCreate(cfg *phraseapp.Config) (*JobLocalesCreate, error) { + + actionJobLocalesCreate := &JobLocalesCreate{Config: *cfg} + actionJobLocalesCreate.ProjectID = cfg.DefaultProjectID + + val, defaultsPresent := actionJobLocalesCreate.Config.Defaults["job_locales/create"] + if defaultsPresent { + if err := actionJobLocalesCreate.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobLocalesCreate, nil +} + +func (cmd *JobLocalesCreate) Run() error { + params := &cmd.JobLocaleParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobLocalesCreate(cmd.ProjectID, cmd.JobID, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobLocalesList struct { + phraseapp.Config + + Page int `cli:"opt --page default=1"` + PerPage int `cli:"opt --per-page default=25"` + + ProjectID string `cli:"arg required"` + JobID string `cli:"arg required"` +} + +func newJobLocalesList(cfg *phraseapp.Config) *JobLocalesList { + + actionJobLocalesList := &JobLocalesList{Config: *cfg} + actionJobLocalesList.ProjectID = cfg.DefaultProjectID + if cfg.Page != nil { + actionJobLocalesList.Page = *cfg.Page + } + if cfg.PerPage != nil { + actionJobLocalesList.PerPage = *cfg.PerPage + } + + return actionJobLocalesList +} + +func (cmd *JobLocalesList) Run() error { + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobLocalesList(cmd.ProjectID, cmd.JobID, cmd.Page, cmd.PerPage) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + +type JobsList struct { + phraseapp.Config + + phraseapp.JobsListParams + + Page int `cli:"opt --page default=1"` + PerPage int `cli:"opt --per-page default=25"` + + ProjectID string `cli:"arg required"` +} + +func newJobsList(cfg *phraseapp.Config) (*JobsList, error) { + + actionJobsList := &JobsList{Config: *cfg} + actionJobsList.ProjectID = cfg.DefaultProjectID + if cfg.Page != nil { + actionJobsList.Page = *cfg.Page + } + if cfg.PerPage != nil { + actionJobsList.PerPage = *cfg.PerPage + } + + val, defaultsPresent := actionJobsList.Config.Defaults["jobs/list"] + if defaultsPresent { + if err := actionJobsList.ApplyValuesFromMap(val); err != nil { + return nil, err + } + } + return actionJobsList, nil +} + +func (cmd *JobsList) Run() error { + params := &cmd.JobsListParams + + client, err := newClient(cmd.Config.Credentials, cmd.Config.Debug) + if err != nil { + return err + } + + res, err := client.JobsList(cmd.ProjectID, cmd.Page, cmd.PerPage, params) + + if err != nil { + return err + } + + return json.NewEncoder(os.Stdout).Encode(&res) +} + type KeyCreate struct { phraseapp.Config diff --git a/vendor/github.com/phrase/phraseapp-go/phraseapp/client.go b/vendor/github.com/phrase/phraseapp-go/phraseapp/client.go index cbb70cb..d589e71 100644 --- a/vendor/github.com/phrase/phraseapp-go/phraseapp/client.go +++ b/vendor/github.com/phrase/phraseapp-go/phraseapp/client.go @@ -1,3 +1,4 @@ +// Package phraseapp is a library for easier usage of the PhraseApp API package phraseapp import ( @@ -13,12 +14,14 @@ import ( "github.com/bgentry/speakeasy" ) +// Client is a generic PhraseApp client. It manages a connection to the PhraseApp API type Client struct { http.Client Credentials Credentials debug bool } +// Credentials contains all information to authenticate against phraseapp.com or a custom host. type Credentials struct { Username string `cli:"opt --username -u desc='username used for authentication'"` Token string `cli:"opt --access-token -t desc='access token used for authentication'"` @@ -26,6 +29,8 @@ type Credentials struct { Host string `cli:"opt --host desc='Host to send Request to'"` } +// NewClient initializes a new client. +// Uses PHRASEAPP_HOST and PHRASEAPP_ACCESS_TOKEN environment variables for host and access token with specified in environment. func NewClient(credentials Credentials, debug bool) (*Client, error) { client := &Client{ Credentials: credentials, diff --git a/vendor/github.com/phrase/phraseapp-go/phraseapp/config.go b/vendor/github.com/phrase/phraseapp-go/phraseapp/config.go index e0152e6..3e8c118 100644 --- a/vendor/github.com/phrase/phraseapp-go/phraseapp/config.go +++ b/vendor/github.com/phrase/phraseapp-go/phraseapp/config.go @@ -9,6 +9,7 @@ import ( "gopkg.in/yaml.v2" ) +// Config contains all information from a .phraseapp.yml config file type Config struct { Credentials Debug bool `cli:"opt --verbose -v desc='Verbose output'"` @@ -27,6 +28,7 @@ type Config struct { const configName = ".phraseapp.yml" +// ReadConfig reads a .phraseapp.yml config file func ReadConfig() (*Config, error) { cfg := &Config{} rawCfg := struct{ PhraseApp *Config }{PhraseApp: cfg} diff --git a/vendor/github.com/phrase/phraseapp-go/phraseapp/error.go b/vendor/github.com/phrase/phraseapp-go/phraseapp/error.go index eb189d2..db23d71 100644 --- a/vendor/github.com/phrase/phraseapp-go/phraseapp/error.go +++ b/vendor/github.com/phrase/phraseapp-go/phraseapp/error.go @@ -17,6 +17,7 @@ func IsErrNotFound(err error) bool { return ok } +// ErrNotFound represents an error for requests of non existing resources type ErrNotFound struct { Message string } @@ -33,6 +34,7 @@ func (err *ErrorResponse) Error() string { return err.Message } +// ValidationErrorResponse represents the response for a failed validation of content type ValidationErrorResponse struct { ErrorResponse @@ -47,6 +49,7 @@ func (err *ValidationErrorResponse) Error() string { return fmt.Sprintf("%s\n%s", err.Message, strings.Join(msgs, "\n")) } +// ValidationErrorMessage represents an error for a failed validation of content type ValidationErrorMessage struct { Resource string Field string @@ -57,6 +60,7 @@ func (msg *ValidationErrorMessage) String() string { return fmt.Sprintf("\t[%s:%s] %s", msg.Resource, msg.Field, msg.Message) } +// RateLimitingError is returned when hitting the API rate limit type RateLimitingError struct { Limit int Remaining int diff --git a/vendor/github.com/phrase/phraseapp-go/phraseapp/lib.go b/vendor/github.com/phrase/phraseapp-go/phraseapp/lib.go index 36af4d6..cc39873 100644 --- a/vendor/github.com/phrase/phraseapp-go/phraseapp/lib.go +++ b/vendor/github.com/phrase/phraseapp-go/phraseapp/lib.go @@ -14,8 +14,8 @@ import ( ) const ( - RevisionDocs = "ae7df97629e13d98990793ba65bfd94f6a50cda8" - RevisionGenerator = "4b761c876a388e244383b8a2218aca140d23fe12" + RevisionDocs = "" + RevisionGenerator = "" ) type Account struct { @@ -118,6 +118,38 @@ type Invitation struct { UpdatedAt *time.Time `json:"updated_at"` } +type Job struct { + Briefing string `json:"briefing"` + CreatedAt *time.Time `json:"created_at"` + DueDate *time.Time `json:"due_date"` + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + UpdatedAt *time.Time `json:"updated_at"` +} + +type JobDetails struct { + Job + + JobTagName string `json:"job_tag_name"` + Keys []*KeyPreview `json:"keys"` + Locales []*LocalePreview `json:"locales"` + Owner *UserPreview `json:"owner"` +} + +type JobLocale struct { + ID string `json:"id"` + Job *JobPreview `json:"job"` + Locale *LocalePreview `json:"locale"` + Users []*UserPreview `json:"users"` +} + +type JobPreview struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` +} + type KeyPreview struct { ID string `json:"id"` Name string `json:"name"` @@ -564,6 +596,87 @@ func (params *GlossaryTermParams) ApplyValuesFromMap(defaults map[string]interfa return nil } +type JobLocaleParams struct { + LocaleID *string `json:"locale_id,omitempty" cli:"opt --locale-id"` + UserIDs []string `json:"user_ids,omitempty" cli:"opt --user-ids"` +} + +func (params *JobLocaleParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "locale_id": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.LocaleID = &val + + case "user_ids": + ok := false + params.UserIDs, ok = v.([]string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + +type JobParams struct { + Briefing *string `json:"briefing,omitempty" cli:"opt --briefing"` + DueDate **time.Time `json:"due_date,omitempty" cli:"opt --due-date"` + Name *string `json:"name,omitempty" cli:"opt --name"` + Tags []string `json:"tags,omitempty" cli:"opt --tags"` + TranslationKeyIDs []string `json:"translation_key_ids,omitempty" cli:"opt --translation-key-ids"` +} + +func (params *JobParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "briefing": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.Briefing = &val + + case "due_date": + val, ok := v.(*time.Time) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.DueDate = &val + + case "name": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.Name = &val + + case "tags": + ok := false + params.Tags, ok = v.([]string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + case "translation_key_ids": + ok := false + params.TranslationKeyIDs, ok = v.([]string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + type TranslationKeyParams struct { DataType *string `json:"data_type,omitempty" cli:"opt --data-type"` Description *string `json:"description,omitempty" cli:"opt --description"` @@ -2373,6 +2486,517 @@ func (client *Client) InvitationsList(account_id string, page, perPage int) ([]* return retVal, err } +// Mark a job as completed. +func (client *Client) JobComplete(project_id, id string) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/complete", project_id, id) + + rc, err := client.sendRequest("POST", url, "", nil, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Create a new job. +func (client *Client) JobCreate(project_id string, params *JobParams) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs", project_id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("POST", url, "application/json", paramsBuf, 201) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Delete an existing job. +func (client *Client) JobDelete(project_id, id string) error { + + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s", project_id, id) + + rc, err := client.sendRequest("DELETE", url, "", nil, 204) + if err != nil { + return err + } + defer rc.Close() + + return nil + }() + return err +} + +type JobKeysCreateParams struct { + TranslationKeyIDs []string `json:"translation_key_ids,omitempty" cli:"opt --translation-key-ids"` +} + +func (params *JobKeysCreateParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "translation_key_ids": + ok := false + params.TranslationKeyIDs, ok = v.([]string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + +// Add multiple keys to a existing job. +func (client *Client) JobKeysCreate(project_id, id string, params *JobKeysCreateParams) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/keys", project_id, id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("POST", url, "application/json", paramsBuf, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +type JobKeysDeleteParams struct { + TranslationKeyIDs []string `json:"translation_key_ids,omitempty" cli:"opt --translation-key-ids"` +} + +func (params *JobKeysDeleteParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "translation_key_ids": + ok := false + params.TranslationKeyIDs, ok = v.([]string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + +// Remove multiple keys from existing job. +func (client *Client) JobKeysDelete(project_id, id string, params *JobKeysDeleteParams) error { + + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/keys", project_id, id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("DELETE", url, "application/json", paramsBuf, 204) + if err != nil { + return err + } + defer rc.Close() + + return nil + }() + return err +} + +// Get details on a single job for a given project. +func (client *Client) JobShow(project_id, id string) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s", project_id, id) + + rc, err := client.sendRequest("GET", url, "", nil, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Starts an existing job in state draft. +func (client *Client) JobStart(project_id, id string) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/start", project_id, id) + + rc, err := client.sendRequest("POST", url, "", nil, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +type JobUpdateParams struct { + Briefing *string `json:"briefing,omitempty" cli:"opt --briefing"` + DueDate **time.Time `json:"due_date,omitempty" cli:"opt --due-date"` + Name *string `json:"name,omitempty" cli:"opt --name"` +} + +func (params *JobUpdateParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "briefing": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.Briefing = &val + + case "due_date": + val, ok := v.(*time.Time) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.DueDate = &val + + case "name": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.Name = &val + + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + +// Update an existing job. +func (client *Client) JobUpdate(project_id, id string, params *JobUpdateParams) (*JobDetails, error) { + retVal := new(JobDetails) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s", project_id, id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("PATCH", url, "application/json", paramsBuf, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Mark a JobLocale as completed. +func (client *Client) JobLocaleComplete(project_id, id string) (*JobLocale, error) { + retVal := new(JobLocale) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/complete", project_id, id) + + rc, err := client.sendRequest("POST", url, "", nil, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Delete an existing JobLocale. +func (client *Client) JobLocaleDelete(project_id, job_id, id string) error { + + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/locale/%s", project_id, job_id, id) + + rc, err := client.sendRequest("DELETE", url, "", nil, 204) + if err != nil { + return err + } + defer rc.Close() + + return nil + }() + return err +} + +// Get a single JobLocale for a given job. +func (client *Client) JobLocaleShow(project_id, job_id, id string) (*JobLocale, error) { + retVal := new(JobLocale) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/locale/%s", project_id, job_id, id) + + rc, err := client.sendRequest("GET", url, "", nil, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Update an existing job. +func (client *Client) JobLocaleUpdate(project_id, job_id, id string, params *JobLocaleParams) (*JobLocale, error) { + retVal := new(JobLocale) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/locales/%s", project_id, job_id, id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("PATCH", url, "application/json", paramsBuf, 200) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// Create a new JobLocale. +func (client *Client) JobLocalesCreate(project_id, job_id string, params *JobLocaleParams) (*JobLocale, error) { + retVal := new(JobLocale) + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/locales", project_id, job_id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequest("POST", url, "application/json", paramsBuf, 201) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +// List all JobLocales for a given job. +func (client *Client) JobLocalesList(project_id, job_id string, page, perPage int) ([]*JobLocale, error) { + retVal := []*JobLocale{} + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs/%s/locales", project_id, job_id) + + rc, err := client.sendRequestPaginated("GET", url, "", nil, 200, page, perPage) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + +type JobsListParams struct { + AssignedTo *string `json:"assigned_to,omitempty" cli:"opt --assigned-to"` + OwnedBy *string `json:"owned_by,omitempty" cli:"opt --owned-by"` + State *string `json:"state,omitempty" cli:"opt --state"` +} + +func (params *JobsListParams) ApplyValuesFromMap(defaults map[string]interface{}) error { + for k, v := range defaults { + switch k { + case "assigned_to": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.AssignedTo = &val + + case "owned_by": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.OwnedBy = &val + + case "state": + val, ok := v.(string) + if !ok { + return fmt.Errorf(cfgValueErrStr, k, v) + } + params.State = &val + + default: + return fmt.Errorf(cfgInvalidKeyErrStr, k) + } + } + + return nil +} + +// List all jobs for the given project. +func (client *Client) JobsList(project_id string, page, perPage int, params *JobsListParams) ([]*Job, error) { + retVal := []*Job{} + err := func() error { + url := fmt.Sprintf("/v2/projects/%s/jobs", project_id) + + paramsBuf := bytes.NewBuffer(nil) + err := json.NewEncoder(paramsBuf).Encode(¶ms) + if err != nil { + return err + } + + rc, err := client.sendRequestPaginated("GET", url, "application/json", paramsBuf, 200, page, perPage) + if err != nil { + return err + } + defer rc.Close() + + var reader io.Reader + if client.debug { + reader = io.TeeReader(rc, os.Stderr) + } else { + reader = rc + } + + return json.NewDecoder(reader).Decode(&retVal) + + }() + return retVal, err +} + // Create a new key. func (client *Client) KeyCreate(project_id string, params *TranslationKeyParams) (*TranslationKeyDetails, error) { retVal := new(TranslationKeyDetails) @@ -4522,7 +5146,7 @@ func (params *TranslationsUnverifyParams) ApplyValuesFromMap(defaults map[string return nil } -// Mark translations matching query as unverified. +//
Only available in the Control Package.
Mark translations matching query as unverified. func (client *Client) TranslationsUnverify(project_id string, params *TranslationsUnverifyParams) (*AffectedCount, error) { retVal := new(AffectedCount) err := func() error { @@ -4591,7 +5215,7 @@ func (params *TranslationsVerifyParams) ApplyValuesFromMap(defaults map[string]i return nil } -// Verify translations matching query. +//
Only available in the Control Package.
Verify translations matching query. func (client *Client) TranslationsVerify(project_id string, params *TranslationsVerifyParams) (*AffectedCount, error) { retVal := new(AffectedCount) err := func() error {