-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssetActions.cs
108 lines (98 loc) · 5.14 KB
/
AssetActions.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MondayApi.Schema;
//https://developer.monday.com/api-reference/docs/files
namespace MondayApi.Assets {
public class AssetActions : IAssetActions {
private readonly IMondayApiClient client;
public AssetActions(IMondayApiClient client) {
this.client = client;
}
public async Task<IEnumerable<IEnumerable<IFileValueItem>>> GetItemFiles(string itemID, string[] columnIDs = null) {
var query = new QueryQueryBuilder().WithItems(
new ItemQueryBuilder().WithColumnValues(
new ColumnValueQueryBuilder().WithAllScalarFields().WithFileValueFragment(
new FileValueQueryBuilder().WithFiles(
new FileValueItemQueryBuilder().WithAllScalarFields() // ExceptCreatedAt to work around bug in current version of API - returns values like `55686-09-26T02:33:47+00:00`
.WithFileAssetValueFragment(new FileAssetValueQueryBuilder().WithAllScalarFields().ExceptCreatedAt().WithAsset(new AssetQueryBuilder().WithAllScalarFields()))
.WithFileDocValueFragment(new FileDocValueQueryBuilder().WithAllScalarFields().ExceptCreatedAt().WithDoc(new DocumentQueryBuilder().WithAllScalarFields()))
.WithFileLinkValueFragment(new FileLinkValueQueryBuilder().WithAllScalarFields().ExceptCreatedAt())
)
),
ids: columnIDs,
types: new ColumnType?[] { ColumnType.File }
),
ids: new string[] { itemID }
);
var response = await client.RunQuery(query);
return response.Items?.FirstOrDefault()?.ColumnValues?.OfType<FileValue>()?.Select(fv => fv.Files);
}
public async Task<IEnumerable<Asset>> GetByItem(string itemID) {
var query = new QueryQueryBuilder().WithItems(
new ItemQueryBuilder().WithAssets(
new AssetQueryBuilder().WithAllScalarFields()
),
ids: new string[] { itemID }
);
var response = await client.RunQuery(query);
return response.Items?.FirstOrDefault()?.Assets;
}
public async Task<IEnumerable<Update>> GetByItemUpdates(string itemID) {
var query = new QueryQueryBuilder().WithItems(
new ItemQueryBuilder().WithUpdates(
new UpdateQueryBuilder().WithID().WithAssets(
new AssetQueryBuilder().WithAllScalarFields()
)
),
ids: new string[] { itemID }
);
var response = await client.RunQuery(query);
return response.Items?.FirstOrDefault()?.Updates;
}
public async Task<Asset> GetOne(string id) {
var query = new QueryQueryBuilder().WithAssets(
new AssetQueryBuilder().WithAllScalarFields(),
ids: new string[] { id }
);
var response = await client.RunQuery(query);
return response.Assets?.FirstOrDefault();
}
public async Task<Asset> UploadFileToUpdate(string updateID, System.IO.Stream file, string filename) {
var fileParam = new GraphQlQueryParameter<object>("file", "File!");
var mutation = new MutationQueryBuilder().WithAddFileToUpdate(
new AssetQueryBuilder().WithAllScalarFields(),
updateID: updateID,
file: fileParam
).WithParameter(fileParam);
var response = await client.RunFileMutation(mutation, file, filename);
return response.AddFileToUpdate;
}
public async Task<Asset> UploadFileToItem(string itemID, string columnID, System.IO.Stream file, string filename) {
var fileParam = new GraphQlQueryParameter<object>("file", "File!");
var mutation = new MutationQueryBuilder().WithAddFileToColumn(
new AssetQueryBuilder().WithAllScalarFields(),
itemID: itemID,
columnID: columnID,
file: fileParam
).WithParameter(fileParam);
var response = await client.RunFileMutation(mutation, file, filename);
return response.AddFileToColumn;
}
// https://developer.monday.com/api-reference/reference/files-1#clear-the-files-column
public async Task<Item> ClearItemFilesColumn(string boardID, string itemID, string columnID) {
var mutation = new MutationQueryBuilder().WithChangeColumnValue(
new ItemQueryBuilder().WithAllScalarFields().WithColumnValues(
new ColumnValueQueryBuilder().WithAllScalarFields(),
ids: new string[] { columnID }
),
boardID: boardID,
itemID: itemID,
columnID: columnID,
value: "{\"clear_all\": true}"
);
var response = await client.RunMutation(mutation);
return response.ChangeColumnValue;
}
}
}