Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crowdin/model/source_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,37 @@
}
return nil
}

// AddAssetReferenceRequest describes a structure to add a reference file for an asset.
type AddAssetReferenceRequest struct {
StorageID int `json:"storageId"`

Check failure on line 600 in crowdin/model/source_files.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
Name string `json:"name"`
}

// UserInfo describes a structure for user received in response.
type UserInfo struct {
UserID int `json:"id"`

Check failure on line 606 in crowdin/model/source_files.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
UserName string `json:"username"`
FullName string `json:"fullName"`
AvatarURL string `json:"avatarUrl"`
}

// AssetReference describes the structure for Asset Reference.
type AssetReference struct {
ID int `json:"id"`

Check failure on line 614 in crowdin/model/source_files.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
Name string `json:"name"`
URL string `json:"url"`
User UserInfo `json:"user"`
CreatedAt string `json:"createdAt"`
MimeType string `json:"mimeType"`
}

// AssetReferenceResponse describes the structure of a single Asset Reference.
type AssetReferenceResponse struct {
Data *AssetReference `json:"data"`
}

// AssetReferencesListResponse describes the structure array of an AssetReferenceResponse
type AssetReferencesListResponse struct {
Data []*AssetReferenceResponse `json:"data"`
}
45 changes: 45 additions & 0 deletions crowdin/source_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,51 @@ func (s *SourceFilesService) DownloadFile(ctx context.Context, projectID, fileID
return res.Data, resp, err
}

// ListAssetReferences returns a list of all reference files for an asset.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.files.references.getMany
func (s *SourceFilesService) ListAssetReferences(ctx context.Context, projectID, fileID int, opt *model.ListOptions) ([]*model.AssetReference, *Response, error) {
res := new(model.AssetReferencesListResponse)
resp, err := s.client.Get(ctx, fmt.Sprintf("/api/v2/projects/%d/files/%d/references", projectID, fileID), opt, res)

assetReferences := make([]*model.AssetReference, 0, len(res.Data))
for _, a := range res.Data {
assetReferences = append(assetReferences, a.Data)
}

return assetReferences, resp, err
}

// AddAssetReference uploads a reference file for an asset.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.files.references.post
func (s *SourceFilesService) AddAssetReference(ctx context.Context, projectID, fileID int, req *model.AddAssetReferenceRequest) (
*model.AssetReference, *Response, error) {
res := new(model.AssetReferenceResponse)
resp, err := s.client.Post(ctx, fmt.Sprintf("/api/v2/projects/%d/files/%d/references", projectID, fileID), req, res)

return res.Data, resp, err
}

// GetAssetReference returns information about a specific asset reference.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.files.references.get
func (s *SourceFilesService) GetAssetReference(ctx context.Context, projectID, fileID int, referenceID int) (*model.AssetReference, *Response, error) {
res := new(model.AssetReferenceResponse)
resp, err := s.client.Get(ctx, fmt.Sprintf("/api/v2/projects/%d/files/%d/references/%d", projectID, fileID, referenceID), nil, res)

return res.Data, resp, err
}

// DeleteAssetReference deletes a reference file for an asset.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.files.references.delete
func (s *SourceFilesService) DeleteAssetReference(ctx context.Context, projectID, fileID int, referenceID int) (*Response, error) {
resp, err := s.client.Delete(ctx, fmt.Sprintf("/api/v2/projects/%d/files/%d/references/%d", projectID, fileID, referenceID), nil)

return resp, err
}

// ListFileRevisions returns a list of file revisions.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.files.revisions.getMany
Expand Down
Loading