|
22 | 22 | using FigmaDotNet.Enums; |
23 | 23 | using FigmaDotNet.Models.Response; |
24 | 24 | using FigmaDotNet.Models.Webhook; |
| 25 | +using FigmaDotNet.Models; |
25 | 26 |
|
26 | 27 | namespace FigmaDotNet; |
27 | 28 |
|
@@ -432,6 +433,80 @@ public async Task PostWebhookAsync(WebHook requestPayload, CancellationToken can |
432 | 433 | _logger.LogInformation($"Webhook was created: {result}"); |
433 | 434 | } |
434 | 435 |
|
| 436 | + /// <summary> |
| 437 | + /// Get dev resources in a file. |
| 438 | + /// </summary> |
| 439 | + /// <param name="fileKey"></param> |
| 440 | + /// <param name="cancellationToken"></param> |
| 441 | + /// <returns></returns> |
| 442 | + public async Task<GetDevResourceResponse> GetDevResourcesAsync(string fileKey, CancellationToken cancellationToken = default) |
| 443 | + { |
| 444 | + string fetchUrl = $"/v1/files/{fileKey}/dev_resources"; |
| 445 | + var result = await RateLimitedFigmaApiCallAsync<GetDevResourceResponse>(fetchUrl, _fileCostRateLimiter, cancellationToken: cancellationToken); |
| 446 | + |
| 447 | + return result; |
| 448 | + } |
| 449 | + |
| 450 | + /// <summary> |
| 451 | + /// Bulk create dev resources across multiple files. |
| 452 | + /// |
| 453 | + /// Dev resources that are successfully created will show up in the links_created array in the response. |
| 454 | + /// |
| 455 | + /// If there are any dev resources that cannot be created, you may still get a 200 response.These resources will show up in the errors array. Some reasons a dev resource cannot be created include: |
| 456 | + /// - Resource points to a file_key that cannot be found. |
| 457 | + /// - The node already has the maximum of 10 dev resources. |
| 458 | + /// - Another dev resource for the node has the same url. |
| 459 | + /// </summary> |
| 460 | + /// <param name="fileKey"></param> |
| 461 | + /// <param name="devResource"></param> |
| 462 | + /// <param name="cancellationToken"></param> |
| 463 | + /// <returns></returns> |
| 464 | + public async Task<PostDevResourceResponse> PostDevResourceAsync(string fileKey, DevResource devResource, CancellationToken cancellationToken = default) |
| 465 | + { |
| 466 | + string fetchUrl = $"/v1/files/{fileKey}/dev_resources"; |
| 467 | + var content = new StringContent(JsonSerializer.Serialize(devResource), Encoding.UTF8, "application/json"); |
| 468 | + var result = await RateLimitedFigmaApiCallAsync<PostDevResourceResponse>(fetchUrl, _fileCostRateLimiter, HttpMethod.Post, content, cancellationToken); |
| 469 | + |
| 470 | + return result; |
| 471 | + } |
| 472 | + |
| 473 | + /// <summary> |
| 474 | + /// Bulk update dev resources across multiple files. |
| 475 | + /// |
| 476 | + /// Ids for dev resources that are successfully updated will show up in the links_updated array in the response. |
| 477 | + /// |
| 478 | + /// If there are any dev resources that cannot be updated, you may still get a 200 response.These resources will show up in the errors array. |
| 479 | + /// </summary> |
| 480 | + /// <param name="fileKey"></param> |
| 481 | + /// <param name="devResourceId"></param> |
| 482 | + /// <param name="devResource"></param> |
| 483 | + /// <param name="cancellationToken"></param> |
| 484 | + /// <returns></returns> |
| 485 | + public async Task<PutDevResourceResponse> PutDevResourceAsync(string fileKey, string devResourceId, DevResource devResource, CancellationToken cancellationToken = default) |
| 486 | + { |
| 487 | + string fetchUrl = $"/v1/files/{fileKey}/dev_resources/{devResourceId}"; |
| 488 | + var content = new StringContent(JsonSerializer.Serialize(devResource), Encoding.UTF8, "application/json"); |
| 489 | + var result = await RateLimitedFigmaApiCallAsync<PutDevResourceResponse>(fetchUrl, _fileCostRateLimiter, HttpMethod.Put, content, cancellationToken); |
| 490 | + |
| 491 | + return result; |
| 492 | + } |
| 493 | + |
| 494 | + /// <summary> |
| 495 | + /// Delete a dev resources from a file. |
| 496 | + /// </summary> |
| 497 | + /// <param name="fileKey"></param> |
| 498 | + /// <param name="devResourceId"></param> |
| 499 | + /// <param name="cancellationToken"></param> |
| 500 | + /// <returns></returns> |
| 501 | + public async Task<bool> DeleteDevResourceAsync(string fileKey, string devResourceId, CancellationToken cancellationToken = default) |
| 502 | + { |
| 503 | + string fetchUrl = $"/v1/files/{fileKey}/dev_resources/{devResourceId}"; |
| 504 | + var result = await RateLimitedFigmaApiCallAsync<string>(fetchUrl, _fileCostRateLimiter, HttpMethod.Delete, cancellationToken: cancellationToken); |
| 505 | + |
| 506 | + _logger.LogInformation($"Deleted dev resource with ID: '{devResourceId}'"); |
| 507 | + return true; |
| 508 | + } |
| 509 | + |
435 | 510 | public void Dispose() |
436 | 511 | { |
437 | 512 | _commentCostRateLimiter.Dispose(); |
|
0 commit comments