From 553b18b1b4e9dee3882a6e9f4331e0a44c8094b5 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Wed, 28 Nov 2012 16:29:27 -0800 Subject: [PATCH 1/8] Implemented more functions for Application and Item services. --- Podio.API/Constants.cs | 1 + Podio.API/ExportType.cs | 26 ++ Podio.API/Podio.API.csproj | 362 ++++++++------- Podio.API/Services/ApplicationService.cs | 214 ++++++--- Podio.API/Services/ItemService.cs | 566 ++++++++++++++++------- Podio.API/Utils/ItemReference.cs | 19 + 6 files changed, 770 insertions(+), 418 deletions(-) create mode 100644 Podio.API/ExportType.cs create mode 100644 Podio.API/Utils/ItemReference.cs diff --git a/Podio.API/Constants.cs b/Podio.API/Constants.cs index 350b083..117fd46 100644 --- a/Podio.API/Constants.cs +++ b/Podio.API/Constants.cs @@ -11,4 +11,5 @@ public struct Constants public const string PODIO_BASEURL = "https://podio.com"; public const string PODIOAPI_BASEURL = "https://api.podio.com"; } + } diff --git a/Podio.API/ExportType.cs b/Podio.API/ExportType.cs new file mode 100644 index 0000000..ef12728 --- /dev/null +++ b/Podio.API/ExportType.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Podio.API +{ + public sealed class ExportType + { + private readonly string name; + private readonly int value; + + public static readonly ExportType XLS = new ExportType(0, "xls"); + public static readonly ExportType XLSX = new ExportType(1, "xlsx"); + + private ExportType(int value, string name) + { + this.name = name; + this.value = value; + } + public override string ToString() + { + return name; + } + } +} diff --git a/Podio.API/Podio.API.csproj b/Podio.API/Podio.API.csproj index 9beabaa..de345d4 100644 --- a/Podio.API/Podio.API.csproj +++ b/Podio.API/Podio.API.csproj @@ -1,181 +1,183 @@ - - - - - Debug - AnyCPU - {1A3252AD-C2AD-4236-8DF8-8E69227D0743} - Library - Properties - Podio.API - Podio.API - v3.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\Podio.API.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.4.5.9\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {1A3252AD-C2AD-4236-8DF8-8E69227D0743} + Library + Properties + Podio.API + Podio.API + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\Podio.API.XML + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.4.5.9\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Podio.API/Services/ApplicationService.cs b/Podio.API/Services/ApplicationService.cs index 7ca058f..d1d59ea 100644 --- a/Podio.API/Services/ApplicationService.cs +++ b/Podio.API/Services/ApplicationService.cs @@ -1,61 +1,153 @@ -using Podio.API.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - - -namespace Podio.API.Services -{ - /// - /// https://developers.podio.com/doc/applications - /// - public class ApplicationService - { - Client _client; - internal ApplicationService(Client client) - { - _client = client; - } - - /// - /// https://developers.podio.com/doc/applications/get-apps-by-space-22478 - /// - public IEnumerable GetAppsBySpace(int spaceId) - { - { - return PodioRestHelper.Request>(Constants.PODIOAPI_BASEURL + "/app/space/" + spaceId + "/", _client.AuthInfo.AccessToken).Data; - } - } - - public Model.Application GetApp(int appId) - { - return PodioRestHelper.Request(Constants.PODIOAPI_BASEURL + "/app/" + appId, _client.AuthInfo.AccessToken).Data; - } - - - #region notimplemented - //ActivateApp - //AddNewApp - //AddNewAppField - //DeactivateApp - //DeleteApp - //DeleteAppField - //GetAllUserApps - //GetAppDependencies - //GetAppField - //GetAppOnSpaceByURLLabel - //GetAppsAvailableForSpace - //GetCalculationsForApp - //GetFeatures - //GetSpaceAppDependencies - //GetTopApps - //GetTopAppsForOrganization - //InstallApp - //UpdateAnAppField - //UpdateApp - //UpdateAppOrder - #endregion - - } -} +using Podio.API.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace Podio.API.Services +{ + /// + /// https://developers.podio.com/doc/applications + /// + public class ApplicationService + { + Client _client; + internal ApplicationService(Client client) + { + _client = client; + } + + /// + /// https://developers.podio.com/doc/applications/activate-app-43822 + /// + public PodioRestHelper.PodioResponse ActivateApp(int appId) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/app/{1}/activate", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.POST); + } + + /// + /// https://developers.podio.com/doc/applications/deactivate-app-43821 + /// + public PodioRestHelper.PodioResponse DeactivateApp(int appId) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/app/{1}/deactivate", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.POST); + } + + /// + /// https://developers.podio.com/doc/applications/delete-app-43693 + /// + public PodioRestHelper.PodioResponse DeleteApp(int appId) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/app/{1}", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/applications/delete-app-field-22355 + /// + public PodioRestHelper.PodioResponse DeleteAppField(int appId, int fieldId, bool deleteValues = null) + { + Dictionary args = new Dictionary(); + if (deleteValues != null) { args.Add("delete_values", deleteValues.ToString()); } + return PodioRestHelper.JSONRequest(String.Format("{0}/app/{1}/field/{2}", Constants.PODIOAPI_BASEURL, appId, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/applications/get-apps-by-space-22478 + /// + public IEnumerable GetAppsBySpace(int spaceId) + { + return PodioRestHelper.Request>(String.Format("{0}/app/space/{1}/", Constants.PODIOAPI_BASEURL, spaceId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-app-22349 + /// + public Model.Application GetApp(int appId) + { + return PodioRestHelper.Request(String.Format("{0}/app/{1}", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-all-user-apps-5902728 + /// + public IEnumerable GetUserApps() + { + return PodioRestHelper.Request>(String.Format("{0}/app/v2/", Constants.PODIOAPI_BASEURL), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-app-dependencies-39159 + /// + public IEnumerable GetAppDependencies(int appId) + { + return PodioRestHelper.Request>(String.Format("{0}/app/{1}/dependencies/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-app-field-22353 + /// + public Model.ApplicationField GetAppField(int appId, int fieldId) + { + return PodioRestHelper.Request(String.Format("{0}/app/{1}/field/{2}", Constants.PODIOAPI_BASEURL, appId, fieldId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-apps-available-for-space-29761 + /// + public IEnumerable GetAvailableAppsForSpace(int spaceId) + { + return PodioRestHelper.Request>(String.Format("{0}/app/space/{1}/available/", Constants.PODIOAPI_BASEURL, spaceId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-top-apps-22476 + /// + public IEnumerable GetTopApps(int? limit = null) + { + Dictionary args = new Dictionary(); + if (limit == null) { args.Add("limit", limit.ToString()); } + return PodioRestHelper.Request>(String.Format("{0}/app/top/", Constants.PODIOAPI_BASEURL), _client.AuthInfo.AccessToken,args).Data; + } + + /// + /// https://developers.podio.com/doc/applications/get-top-apps-for-organization-1671395 + /// + public IEnumerable GetTopAppsForOrganization(int orgId) + { + return PodioRestHelper.Request>(String.Format("{0}/app/org/{1}/top/", Constants.PODIOAPI_BASEURL,orgId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/applications/install-app-22506 + /// + public PodioRestHelper.PodioResponse InstallApp(int appId, int spaceId) + { + Dictionary args = new Dictionary(); + args.Add("space_id", spaceId.ToString()); + return PodioRestHelper.JSONRequest(String.Format("{0}/app/{1}/install", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.POST); + } + + /// + /// https://developers.podio.com/doc/applications/update-app-order-22463 + /// + public PodioRestHelper.PodioResponse UpdateAppOrder(int spaceId, IEnumerable appIds) + { + Dictionary args = new Dictionary(); + args.Add("app_ids", String.Join(",", appIds.Select(id => id.ToString()).ToArray())); + return PodioRestHelper.JSONRequest(String.Format("{0}/app/space/{1}/order", Constants.PODIOAPI_BASEURL, spaceId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.POST); + } + #region notimplemented + + //AddNewApp + //AddNewAppField + //GetAppOnSpaceByURLLabel + //GetCalculationsForApp + //GetFeatures + //GetSpaceAppDependencies + //UpdateAnAppField + //UpdateApp + #endregion + + } +} diff --git a/Podio.API/Services/ItemService.cs b/Podio.API/Services/ItemService.cs index 13485b9..9e90d6a 100644 --- a/Podio.API/Services/ItemService.cs +++ b/Podio.API/Services/ItemService.cs @@ -1,177 +1,389 @@ -using Podio.API.Model; -using Podio.API.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; - - -namespace Podio.API.Services -{ - public class ItemService - { - private Client _client; - /// - /// Add a client and you can use this as a shortcut to the Podio REST API - /// - public ItemService(Client client) - { - _client = client; - } - - /// - /// https://developers.podio.com/doc/items/get-item-22360 - /// - public Item GetItem(int itemId, bool markAsViewed = true) - { - Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; - return PodioRestHelper.Request(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, args).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-items-27803 - /// - public PodioCollection GetItems(int appId, int limit, int offset, string key = null, bool? remembered = null, string sortBy = null, bool? sortDesc = null, int? viewId = null) - { - Dictionary args = new Dictionary(); - - args.Add("limit", limit.ToString()); - args.Add("offset", offset.ToString()); - - if (!string.IsNullOrEmpty(key)) - args.Add("{key}", key); - - if (remembered != null) - args.Add("remembered", remembered.ToString()); - - if (!string.IsNullOrEmpty(sortBy)) - args.Add("sort_by", sortBy); - if (sortDesc != null) - args.Add("sort_desc", sortDesc.ToString()); - if (viewId != null) - args.Add("view_id", viewId.ToString()); - - return PodioRestHelper.Request>(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken,args).Data; - } - - [DataContract] - public struct CreateUpdateRequest - { - [DataMember(IsRequired = false, Name = "fields")] - public IEnumerable> Fields { get; set; } - - [DataMember(IsRequired = false, Name = "file_ids")] - public IEnumerable FileIds { get; set; } - - [DataMember(IsRequired = false, Name = "tags")] - public IEnumerable Tags { get; set; } - - [DataMember(IsRequired = false, Name = "reminder")] - public Reminder Reminder { get; set; } - - [DataMember(IsRequired = false, Name = "recurrence")] - public Recurrence Recurrence { get; set; } - - [DataMember(IsRequired = false, Name = "linked_account_id")] - public int? LinkedAccountId { get; set; } - - [DataMember(IsRequired = false, Name = "ref")] - public Ref Ref { get; set; } - } - - /// - /// https://developers.podio.com/doc/items/add-new-item-22362 - /// - public int AddNewItem(int appId, Item item) { - var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); - var requestData = new CreateUpdateRequest() - { - Fields = fieldValues, - FileIds = item.FileIds, - Tags = item.Tags.Select(tag => tag.Text) - }; - var newItem = AddNewItem(appId, requestData); - item.ItemId = newItem.ItemId; - item.Title = newItem.Title; - return (int)item.ItemId; - } - - /// - /// https://developers.podio.com/doc/items/add-new-item-22362 - /// - public Item AddNewItem(int appId, CreateUpdateRequest requestData) - { - return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; - } - - /// - /// https://developers.podio.com/doc/items/update-item-22363 - /// - public void UpdateItem(Item item) - { - var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); - var requestData = new CreateUpdateRequest() - { - Fields = fieldValues, - FileIds = item.FileIds, - Tags = item.Tags.Select(tag => tag.Text), - - }; - UpdateItem((int)item.ItemId, requestData); - } - - /// - /// https://developers.podio.com/doc/items/update-item-22363 - /// - public void UpdateItem(int itemId, CreateUpdateRequest requestData) - { - PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.PUT); - } - /// - /// https://developers.podio.com/doc/items/delete-item-s-22364 - /// - public PodioRestHelper.PodioResponse DeleteItems(IEnumerable itemIds, bool silent = false) - { - return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + String.Join(",", itemIds.Select(id => id.ToString()).ToArray()), _client.AuthInfo.AccessToken, new { silent = silent }, PodioRestHelper.RequestMethod.DELETE); - } - - /// - /// https://developers.podio.com/doc/items/delete-item-s-22364 - /// - public PodioRestHelper.PodioResponse DeleteItem(int itemId, bool silent = false) - { - return DeleteItems(new int[] { itemId }, silent); - } - - /* - * -Calculate -Delete item reference -Export items -Filter items -Filter items by view -Find items by field and title -Get app values -Get item basic -Get item field values -Get item preview for field reference -Get item references -Get item revision -Get item revision difference -Get item revisions -Get item values -Get items -Get items as Xlsx -Get meeting URL -Get references to item by field -Get top values for field -Revert item revision -Set participation -Update item -Update item field values -Update item reference -Update item values - */ - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using Podio.API.Model; +using Podio.API.Utils; + + +namespace Podio.API.Services +{ + public class ItemService + { + private Client _client; + + /// + /// Add a client and you can use this as a shortcut to the Podio REST API + /// + public ItemService(Client client) + { + _client = client; + } + + /// + /// https://developers.podio.com/doc/items/add-new-item-22362 + /// + public Item AddNewItem(int appId, CreateUpdateRequest requestData) + { + return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/add-new-item-22362 + /// + public int AddNewItem(int appId, Item item) + { + var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); + var requestData = new CreateUpdateRequest() + { + ExternalId = item.ExternalId, + Fields = fieldValues, + FileIds = item.FileIds, + Tags = item.Tags.Select(tag => tag.Text) + }; + var newItem = AddNewItem(appId, requestData); + item.ItemId = newItem.ItemId; + item.Title = newItem.Title; + return (int)item.ItemId; + } + + /// + /// https://developers.podio.com/doc/items/calculate-67633 + /// + public void Calculate(int appId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-s-22364 + /// + public PodioRestHelper.PodioResponse DeleteItem(int itemId, bool silent = false) + { + return DeleteItems(new int[] { itemId }, silent); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-reference-7302326 + /// + public PodioRestHelper.PodioResponse DeleteItemReference(int itemId) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}/ref", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-s-22364 + /// + public PodioRestHelper.PodioResponse DeleteItems(IEnumerable itemIds, bool silent = false) + { + return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + String.Join(",", itemIds.Select(id => id.ToString()).ToArray()), _client.AuthInfo.AccessToken, new { silent = silent }, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/items/export-items-4235696 + /// + public Batch ExportItems(int appId, ExportType export, FilterItemRequest request) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/app/{1}/export/{2}", Constants.PODIOAPI_BASEURL, appId, export.ToString()), _client.AuthInfo.AccessToken, request, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/filter-items-4496747 + /// + public PodioCollection FilterItems(int appId, FilterItemRequest requestData) + { + return PodioRestHelper.JSONRequest>(String.Format("{0}/item/app/{1}/filter/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/filter-items-by-view-4540284 + /// + public PodioCollection FilterItemsByView(int appId, int viewId, int? limit = null, int? offset = null, bool? remembered = null) + { + Dictionary args = new Dictionary(); + + if (limit != null) + args.Add("limit", limit.ToString()); + if (offset != null) + args.Add("offset", offset.ToString()); + + if (remembered != null) + args.Add("remembered", remembered.ToString()); + + return PodioRestHelper.Request>(String.Format("{0}/item/app/{1}/filter/{2}/", Constants.PODIOAPI_BASEURL, appId, viewId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/find-referenceable-items-22485 + /// + public List FindReferenceableItems(int fieldId, int? limit = null, IEnumerable excludeItemIds =null, string sort =null, string search = null) + { + Dictionary args = new Dictionary(); + if (limit != null) { args.Add("limit", limit.ToString()); } + if (sort != null) { args.Add("sort", sort); } + if (search != null) { args.Add("text", search); } + if (excludeItemIds != null) + { + args.Add("not_item_id", String.Join(",", excludeItemIds.Select(id => id.ToString()).ToArray())); + } + return PodioRestHelper.Request>(String.Format("{0}/item/field/{1}/find", Constants.PODIOAPI_BASEURL, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-app-values-22455 + /// + public void GetAppValues(int appId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/get-field-ranges-24242866 + /// + public void GetFieldRanges(int fieldId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/get-item-22360 + /// + public Item GetItem(int itemId, bool markAsViewed = true) + { + Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; + return PodioRestHelper.Request(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-basic-61768 + /// + public Item GetItemBasic(int itemId, bool markAsViewed = true) + { + Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; + return PodioRestHelper.Request(String.Format("{0}/item/{1}/basic", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-by-external-id-19556702 + /// + public Item GetItemByExternalId(int appId, int externalId) + { + return PodioRestHelper.Request(String.Format("{0}/item/app/{1}/external_id/{2}", Constants.PODIOAPI_BASEURL, appId, externalId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-field-values-22368 + /// + public List> GetItemFieldValues(int itemId, int fieldId) + { + return PodioRestHelper.Request>>(String.Format("{0}/item/{1}/value/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-preview-for-field-reference-7529318 + /// + public void GetItemPreviewForFieldReference(int itemId, int fieldId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/get-item-references-22439 + /// + public List GetItemReferences(int itemId) + { + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-references-to-item-by-field-7403920 + /// + public List GetItemReferencesByField(int itemId, int fieldId, int? limit = null) + { + Dictionary args = new Dictionary(); + if (limit != null) { args.Add("limit", limit.ToString()); } + + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/field/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-22373 + /// + public ItemRevision GetItemRevision(int itemId, int revisionId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}", Constants.PODIOAPI_BASEURL, itemId, revisionId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 + /// + public ItemDiff GetItemRevisionDifference(int itemId, int revisionFromId, int revisionToId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}/{3}", Constants.PODIOAPI_BASEURL, itemId, revisionFromId, revisionToId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 + /// + public ICollection GetItemRevisions(int itemId) + { + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/revision/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-items-27803 + /// + public PodioCollection GetItems(int appId, int limit, int offset, Dictionary filters = null, bool? remembered = null, string sortBy = null, bool? sortDesc = null, int? viewId = null) + { + Dictionary args = new Dictionary(); + args.Add("limit", limit.ToString()); + args.Add("offset", offset.ToString()); + + if (remembered != null) { args.Add("remembered", remembered.ToString()); } + if (!string.IsNullOrEmpty(sortBy)) { args.Add("sort_by", sortBy); } + if (sortDesc != null) { args.Add("sort_desc", sortDesc.ToString()); } + if (viewId != null) { args.Add("view_id", viewId.ToString()); } + + if (filters != null) + { + foreach (KeyValuePair f in filters) + { + if (!args.ContainsKey(f.Key)) + { + args.Add(f.Key, f.Value); + } + } + } + + return PodioRestHelper.Request>(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-items-as-xlsx-63233 + /// + public void GetItemsAsXLSX(int appId, FilterItemRequest req) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/get-meeting-url-14763260 + /// + public string GetMeetingURL(int itemId) + { + string retval = String.Empty; + Dictionary o = PodioRestHelper.JSONRequest>(String.Format("{0}/item/{1}/meeting/url", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; + if (o.ContainsKey("url")) { retval = o["url"].ToString(); } + return retval; + } + + /// + /// https://developers.podio.com/doc/items/get-top-values-for-field-68334 + /// + public List GetTopValuesByField(int fieldId, int? limit =null, IEnumerable excludeItems = null) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/revert-item-revision-953195 + /// + public void RevertItemRevision(int itemId, int revisionId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/set-participation-7156154 + /// + public void SetParticipation(int itemId, string status) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/update-item-22363 + /// + public void UpdateItem(Item item) + { + var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); + var requestData = new CreateUpdateRequest() + { + ExternalId = item.ExternalId, + Fields = fieldValues, + FileIds = item.FileIds, + Tags = item.Tags.Select(tag => tag.Text), + + }; + UpdateItem((int)item.ItemId, requestData); + } + + /// + /// https://developers.podio.com/doc/items/update-item-22363 + /// + public void UpdateItem(int itemId, CreateUpdateRequest requestData) + { + PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.PUT); + } + /// + /// https://developers.podio.com/doc/items/update-item-field-values-22367 + /// + public void UpdateItemFieldValues(int itemId, int fieldId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/update-item-values-22366 + /// + public void UpdateItemValues(int itemId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + [DataContract] + public struct CreateUpdateRequest + { + [DataMember(IsRequired = false, Name = "external_id")] + public string ExternalId { get; set; } + + [DataMember(IsRequired = false, Name = "fields")] + public IEnumerable> Fields { get; set; } + + [DataMember(IsRequired = false, Name = "file_ids")] + public IEnumerable FileIds { get; set; } + + [DataMember(IsRequired = false, Name = "tags")] + public IEnumerable Tags { get; set; } + + [DataMember(IsRequired = false, Name = "reminder")] + public Reminder Reminder { get; set; } + + [DataMember(IsRequired = false, Name = "recurrence")] + public Recurrence Recurrence { get; set; } + + [DataMember(IsRequired = false, Name = "linked_account_id")] + public int? LinkedAccountId { get; set; } + + [DataMember(IsRequired = false, Name = "ref")] + public Ref Ref { get; set; } + } + [DataContract] + public struct FilterItemRequest + { + [DataMember(IsRequired = false, Name = "sort_by")] + public string SortBy { get; set; } + [DataMember(IsRequired = false, Name = "sort_desc")] + public bool? SortDesc { get; set; } + [DataMember(IsRequired = false, Name = "limit")] + public int? Limit { get; set; } + [DataMember(IsRequired = false, Name = "offset")] + public int? Offset { get; set; } + [DataMember(IsRequired = false, Name = "remember")] + public bool? Remember { get; set; } + [DataMember(IsRequired = false, Name = "filters")] + public List> Filters { get; set; } + } + + } +} diff --git a/Podio.API/Utils/ItemReference.cs b/Podio.API/Utils/ItemReference.cs new file mode 100644 index 0000000..8f605d2 --- /dev/null +++ b/Podio.API/Utils/ItemReference.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Podio.API.Model +{ + [DataContract] + public partial class ItemReference + { + [DataMember(Name = "field", IsRequired = false)] + public ItemField Field { get; set; } + + [DataMember(Name = "app", IsRequired = false)] + public Application App { get; set; } + + [DataMember(Name = "items", IsRequired = false)] + public List Items { get; set; } + } +} From d34d691a23806e8f4d438c6cd28c6fd506371d75 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Wed, 2 Jan 2013 12:40:59 -0800 Subject: [PATCH 2/8] Changed Item Model to use ItemReference for Refs property. --- .../Exceptions/PodioRateLimitException.cs | 2 +- Podio.API/Model/Item.cs | 288 +++++++++--------- Podio.API/Services/ApplicationService.cs | 2 +- Podio.API/Services/ItemService.cs | 5 + 4 files changed, 151 insertions(+), 146 deletions(-) diff --git a/Podio.API/Exceptions/PodioRateLimitException.cs b/Podio.API/Exceptions/PodioRateLimitException.cs index 7e91979..c78b7e3 100644 --- a/Podio.API/Exceptions/PodioRateLimitException.cs +++ b/Podio.API/Exceptions/PodioRateLimitException.cs @@ -9,7 +9,7 @@ namespace Podio.API.Exceptions public class PodioRateLimitException : Exception { public PodioRateLimitException() - : base("Podio says no sir - thou cannot do shit for some time") + : base("Podio rate limit exceeded. https://developers.podio.com/index/limits") { } diff --git a/Podio.API/Model/Item.cs b/Podio.API/Model/Item.cs index 7c30732..727583b 100644 --- a/Podio.API/Model/Item.cs +++ b/Podio.API/Model/Item.cs @@ -1,144 +1,144 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - - -/// AUTOGENERATED FROM RUBYSOURCE -namespace Podio.API.Model -{ - [DataContract] - public partial class Item - { - - - [DataMember(Name = "item_id", IsRequired=false)] - public int? ItemId { get; set; } - - - [DataMember(Name = "app", IsRequired=false)] - public Dictionary App { get; set; } - - - [DataMember(Name = "external_id", IsRequired=false)] - public string ExternalId { get; set; } - - - [DataMember(Name = "title", IsRequired=false)] - public string Title { get; set; } - - - [DataMember(Name = "fields", IsRequired=false)] - public List Fields { get; set; } - - - [DataMember(Name = "rights", IsRequired=false)] - public string[] Rights { get; set; } - - - [DataMember(Name = "ratings", IsRequired=false)] - public Dictionary Ratings { get; set; } - - - [DataMember(Name = "conversations", IsRequired=false)] - public List Conversations { get; set; } - - - [DataMember(Name = "tasks", IsRequired=false)] - public List Tasks { get; set; } - - - [DataMember(Name = "references", IsRequired=false)] - public List References { get; set; } - - - [DataMember(Name = "refs", IsRequired=false)] - public List Refs { get; set; } - - - [DataMember(Name = "tags", IsRequired=false)] - public List Tags { get; set; } - - - [DataMember(Name = "subscribed", IsRequired=false)] - public bool? Subscribed { get; set; } - - - [DataMember(Name = "user_ratings", IsRequired=false)] - public Dictionary UserRatings { get; set; } - - - [DataMember(Name = "link", IsRequired=false)] - public string Link { get; set; } - - - [DataMember(Name = "invite", IsRequired=false)] - public Dictionary Invite { get; set; } - - - [DataMember(Name = "participants", IsRequired=false)] - public Dictionary Participants { get; set; } - - - [DataMember(Name = "linked_account_id", IsRequired=false)] - public int? LinkedAccountId { get; set; } - - - [DataMember(Name = "ref", IsRequired=false)] - public Dictionary Ref { get; set; } - - - [DataMember(Name = "priority", IsRequired=false)] - public float Priority { get; set; } - - - [DataMember(Name = "comment_count", IsRequired=false)] - public int? CommentCount { get; set; } - - - [DataMember(Name = "task_count", IsRequired=false)] - public int? TaskCount { get; set; } - - - [DataMember(Name = "file_ids", IsRequired=false)] - public List FileIds { get; set; } - - - [DataMember(Name = "initial_revision", IsRequired=false)] - public ItemRevision InitialRevision { get; set; } - - - [DataMember(Name = "current_revision", IsRequired=false)] - public ItemRevision CurrentRevision { get; set; } - - - [DataMember(Name = "reminder", IsRequired=false)] - public Reminder Reminder { get; set; } - - - [DataMember(Name = "recurrence", IsRequired=false)] - public Recurrence Recurrence { get; set; } - - - [DataMember(Name = "linked_account_data", IsRequired=false)] - public LinkedAccountData LinkedAccountData { get; set; } - - - [DataMember(Name = "revisions", IsRequired=false)] - public List Revisions { get; set; } - - - [DataMember(Name = "files", IsRequired=false)] - public List Files { get; set; } - - - [DataMember(Name = "comments", IsRequired=false)] - public List Comments { get; set; } - - - [DataMember(Name = "shares", IsRequired=false)] - public List Shares { get; set; } - - - } -} - +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + + +/// AUTOGENERATED FROM RUBYSOURCE +namespace Podio.API.Model +{ + [DataContract] + public partial class Item + { + + + [DataMember(Name = "item_id", IsRequired=false)] + public int? ItemId { get; set; } + + + [DataMember(Name = "app", IsRequired=false)] + public Dictionary App { get; set; } + + + [DataMember(Name = "external_id", IsRequired=false)] + public string ExternalId { get; set; } + + + [DataMember(Name = "title", IsRequired=false)] + public string Title { get; set; } + + + [DataMember(Name = "fields", IsRequired=false)] + public List Fields { get; set; } + + + [DataMember(Name = "rights", IsRequired=false)] + public string[] Rights { get; set; } + + + [DataMember(Name = "ratings", IsRequired=false)] + public Dictionary Ratings { get; set; } + + + [DataMember(Name = "conversations", IsRequired=false)] + public List Conversations { get; set; } + + + [DataMember(Name = "tasks", IsRequired=false)] + public List Tasks { get; set; } + + + [DataMember(Name = "references", IsRequired=false)] + public List References { get; set; } + + + [DataMember(Name = "refs", IsRequired=false)] + public List Refs { get; set; } + + + [DataMember(Name = "tags", IsRequired=false)] + public List Tags { get; set; } + + + [DataMember(Name = "subscribed", IsRequired=false)] + public bool? Subscribed { get; set; } + + + [DataMember(Name = "user_ratings", IsRequired=false)] + public Dictionary UserRatings { get; set; } + + + [DataMember(Name = "link", IsRequired=false)] + public string Link { get; set; } + + + [DataMember(Name = "invite", IsRequired=false)] + public Dictionary Invite { get; set; } + + + [DataMember(Name = "participants", IsRequired=false)] + public Dictionary Participants { get; set; } + + + [DataMember(Name = "linked_account_id", IsRequired=false)] + public int? LinkedAccountId { get; set; } + + + [DataMember(Name = "ref", IsRequired=false)] + public Dictionary Ref { get; set; } + + + [DataMember(Name = "priority", IsRequired=false)] + public float Priority { get; set; } + + + [DataMember(Name = "comment_count", IsRequired=false)] + public int? CommentCount { get; set; } + + + [DataMember(Name = "task_count", IsRequired=false)] + public int? TaskCount { get; set; } + + + [DataMember(Name = "file_ids", IsRequired=false)] + public List FileIds { get; set; } + + + [DataMember(Name = "initial_revision", IsRequired=false)] + public ItemRevision InitialRevision { get; set; } + + + [DataMember(Name = "current_revision", IsRequired=false)] + public ItemRevision CurrentRevision { get; set; } + + + [DataMember(Name = "reminder", IsRequired=false)] + public Reminder Reminder { get; set; } + + + [DataMember(Name = "recurrence", IsRequired=false)] + public Recurrence Recurrence { get; set; } + + + [DataMember(Name = "linked_account_data", IsRequired=false)] + public LinkedAccountData LinkedAccountData { get; set; } + + + [DataMember(Name = "revisions", IsRequired=false)] + public List Revisions { get; set; } + + + [DataMember(Name = "files", IsRequired=false)] + public List Files { get; set; } + + + [DataMember(Name = "comments", IsRequired=false)] + public List Comments { get; set; } + + + [DataMember(Name = "shares", IsRequired=false)] + public List Shares { get; set; } + + + } +} + diff --git a/Podio.API/Services/ApplicationService.cs b/Podio.API/Services/ApplicationService.cs index d1d59ea..88b1c11 100644 --- a/Podio.API/Services/ApplicationService.cs +++ b/Podio.API/Services/ApplicationService.cs @@ -45,7 +45,7 @@ public PodioRestHelper.PodioResponse DeleteApp(int appId) /// /// https://developers.podio.com/doc/applications/delete-app-field-22355 /// - public PodioRestHelper.PodioResponse DeleteAppField(int appId, int fieldId, bool deleteValues = null) + public PodioRestHelper.PodioResponse DeleteAppField(int appId, int fieldId, bool? deleteValues = null) { Dictionary args = new Dictionary(); if (deleteValues != null) { args.Add("delete_values", deleteValues.ToString()); } diff --git a/Podio.API/Services/ItemService.cs b/Podio.API/Services/ItemService.cs index 9e90d6a..fd479a5 100644 --- a/Podio.API/Services/ItemService.cs +++ b/Podio.API/Services/ItemService.cs @@ -373,14 +373,19 @@ public struct FilterItemRequest { [DataMember(IsRequired = false, Name = "sort_by")] public string SortBy { get; set; } + [DataMember(IsRequired = false, Name = "sort_desc")] public bool? SortDesc { get; set; } + [DataMember(IsRequired = false, Name = "limit")] public int? Limit { get; set; } + [DataMember(IsRequired = false, Name = "offset")] public int? Offset { get; set; } + [DataMember(IsRequired = false, Name = "remember")] public bool? Remember { get; set; } + [DataMember(IsRequired = false, Name = "filters")] public List> Filters { get; set; } } From 38986084ff65d23a86bf914b323801ed7290b4a6 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Wed, 2 Jan 2013 13:11:14 -0800 Subject: [PATCH 3/8] Bug fix: Item.Tags is now a list of strings. --- Podio.API/Model/Item.cs | 2 +- Podio.API/Services/ItemService.cs | 5 +- Podio.API/Utils/Item.cs | 86 +++++++++++++++---------------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Podio.API/Model/Item.cs b/Podio.API/Model/Item.cs index 727583b..a8c23a7 100644 --- a/Podio.API/Model/Item.cs +++ b/Podio.API/Model/Item.cs @@ -56,7 +56,7 @@ public partial class Item [DataMember(Name = "tags", IsRequired=false)] - public List Tags { get; set; } + public List Tags { get; set; } [DataMember(Name = "subscribed", IsRequired=false)] diff --git a/Podio.API/Services/ItemService.cs b/Podio.API/Services/ItemService.cs index fd479a5..c50bd3b 100644 --- a/Podio.API/Services/ItemService.cs +++ b/Podio.API/Services/ItemService.cs @@ -39,7 +39,7 @@ public int AddNewItem(int appId, Item item) ExternalId = item.ExternalId, Fields = fieldValues, FileIds = item.FileIds, - Tags = item.Tags.Select(tag => tag.Text) + Tags = item.Tags }; var newItem = AddNewItem(appId, requestData); item.ItemId = newItem.ItemId; @@ -312,8 +312,7 @@ public void UpdateItem(Item item) ExternalId = item.ExternalId, Fields = fieldValues, FileIds = item.FileIds, - Tags = item.Tags.Select(tag => tag.Text), - + Tags = item.Tags }; UpdateItem((int)item.ItemId, requestData); } diff --git a/Podio.API/Utils/Item.cs b/Podio.API/Utils/Item.cs index 0d536ee..8618bdb 100644 --- a/Podio.API/Utils/Item.cs +++ b/Podio.API/Utils/Item.cs @@ -1,43 +1,43 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Podio.API.Model -{ - public partial class Item - { - public Item() { - this.Fields = new List(); - this.FileIds = new List(); - this.Tags = new List(); - } - - public T Field(string externalId) - where T : ItemField, new() - { - var genericField = this.Fields.Find(field => field.ExternalId == externalId); - return fieldInstance(genericField); - } - - public T Field(int fieldId) - where T : ItemField, new() - { - var genericField = this.Fields.Find(field => field.FieldId == fieldId); - return fieldInstance(genericField); - } - - protected T fieldInstance(ItemField genericField) - where T : ItemField, new() - { - T specificField = new T(); - if(genericField != null) { - foreach (var property in genericField.GetType().GetProperties()) - { - specificField.GetType().GetProperty(property.Name).SetValue(specificField, property.GetValue(genericField, null), null); - } - } - return specificField; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Podio.API.Model +{ + public partial class Item + { + public Item() { + this.Fields = new List(); + this.FileIds = new List(); + this.Tags = new List(); + } + + public T Field(string externalId) + where T : ItemField, new() + { + var genericField = this.Fields.Find(field => field.ExternalId == externalId); + return fieldInstance(genericField); + } + + public T Field(int fieldId) + where T : ItemField, new() + { + var genericField = this.Fields.Find(field => field.FieldId == fieldId); + return fieldInstance(genericField); + } + + protected T fieldInstance(ItemField genericField) + where T : ItemField, new() + { + T specificField = new T(); + if(genericField != null) { + foreach (var property in genericField.GetType().GetProperties()) + { + specificField.GetType().GetProperty(property.Name).SetValue(specificField, property.GetValue(genericField, null), null); + } + } + return specificField; + } + } +} From 7c3052736f7525627aeec32bd180e5f6060e01d3 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Thu, 3 Jan 2013 15:52:02 -0800 Subject: [PATCH 4/8] Added support for raw file download. Added limit header information to PodioResponse. --- Podio.API/Services/FileService.cs | 13 +++++++++++++ Podio.API/Utils/RestHelper.cs | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Podio.API/Services/FileService.cs b/Podio.API/Services/FileService.cs index b1143ac..463d74c 100644 --- a/Podio.API/Services/FileService.cs +++ b/Podio.API/Services/FileService.cs @@ -32,5 +32,18 @@ public FileAttachment UploadFile(byte[] data, string filename, string mimetype) return PodioRestHelper.MultipartFormDataRequest(Constants.PODIOAPI_BASEURL + "/file/v2/", _client.AuthInfo.AccessToken, requestData).Data; } + /// + /// https://developers.podio.com/doc/files/get-raw-file-1004147 + /// + public byte[] GetRawFile(int fileId) + { + byte[] content; + using (var request = new System.Net.WebClient()) + { + string uri = String.Format("{0}/file/{1}/raw?oauth_token={2}", Constants.PODIOAPI_BASEURL, fileId, _client.AuthInfo.AccessToken); + content = request.DownloadData(uri); + } + return content; + } } } diff --git a/Podio.API/Utils/RestHelper.cs b/Podio.API/Utils/RestHelper.cs index 5154822..1f9ca2d 100644 --- a/Podio.API/Utils/RestHelper.cs +++ b/Podio.API/Utils/RestHelper.cs @@ -99,6 +99,8 @@ public class PodioResponse public HttpStatusCode HttpStatusCode { get; set; } public string ContentType { get; set; } public string RequestUri { get; set; } + public string LimitOfLastRequest { get; set; } + public string LimitRemaining { get; set; } public Dictionary RequestData { get; set; } public PodioError PodioError { @@ -316,7 +318,8 @@ private static PodioResponse GetResponse(HttpWebRequest request) { retval.ContentType = response.ContentType; retval.HttpStatusCode = ((HttpWebResponse)response).StatusCode; - + retval.LimitOfLastRequest =((HttpWebResponse)response).Headers["X-Rate-Limit-Limit"]; + retval.LimitRemaining = ((HttpWebResponse)response).Headers["X-Rate-Limit-Remaining"]; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { retval.Data = sr.ReadToEnd(); @@ -329,6 +332,8 @@ private static PodioResponse GetResponse(HttpWebRequest request) { retval.ContentType = response.ContentType; retval.HttpStatusCode = ((HttpWebResponse)response).StatusCode; + retval.LimitOfLastRequest = ((HttpWebResponse)response).Headers["X-Rate-Limit-Limit"]; + retval.LimitRemaining = ((HttpWebResponse)response).Headers["X-Rate-Limit-Remaining"]; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { retval.Data = sr.ReadToEnd(); From 6f006d89fbf22ba729fecb9859eb0661908c54b4 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Thu, 3 Jan 2013 23:12:11 -0800 Subject: [PATCH 5/8] Implemented more methods for ItemService. --- Podio.API/Model/Via.cs | 3 +- Podio.API/ParticipationStatus.cs | 28 ++ Podio.API/Podio.API.csproj | 366 +++++++------- Podio.API/Services/ItemService.cs | 796 +++++++++++++++--------------- Podio.API/Utils/AppValues.cs | 23 + Podio.API/Utils/ItemFieldRange.cs | 16 + 6 files changed, 656 insertions(+), 576 deletions(-) create mode 100644 Podio.API/ParticipationStatus.cs create mode 100644 Podio.API/Utils/AppValues.cs create mode 100644 Podio.API/Utils/ItemFieldRange.cs diff --git a/Podio.API/Model/Via.cs b/Podio.API/Model/Via.cs index d9018d0..a1dfccf 100644 --- a/Podio.API/Model/Via.cs +++ b/Podio.API/Model/Via.cs @@ -26,7 +26,8 @@ public partial class Via [DataMember(Name = "display", IsRequired=false)] public bool? Display { get; set; } - + [DataMember(Name = "auth_client_id", IsRequired = false)] + public int? AuthClientId { get; set; } } } diff --git a/Podio.API/ParticipationStatus.cs b/Podio.API/ParticipationStatus.cs new file mode 100644 index 0000000..2799ce7 --- /dev/null +++ b/Podio.API/ParticipationStatus.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Podio.API +{ + public sealed class ParticipationStatus + { + private readonly string name; + private readonly int value; + + public static readonly ParticipationStatus Invited = new ParticipationStatus(0, "invited"); + public static readonly ParticipationStatus Accepted = new ParticipationStatus(1, "accepted"); + public static readonly ParticipationStatus Declined = new ParticipationStatus(2, "declined"); + public static readonly ParticipationStatus Tentative = new ParticipationStatus(3, "tentative"); + + private ParticipationStatus(int value, string name) + { + this.name = name; + this.value = value; + } + public override string ToString() + { + return name; + } + } +} diff --git a/Podio.API/Podio.API.csproj b/Podio.API/Podio.API.csproj index de345d4..94e8d51 100644 --- a/Podio.API/Podio.API.csproj +++ b/Podio.API/Podio.API.csproj @@ -1,183 +1,185 @@ - - - - - Debug - AnyCPU - {1A3252AD-C2AD-4236-8DF8-8E69227D0743} - Library - Properties - Podio.API - Podio.API - v3.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\Podio.API.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.4.5.9\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {1A3252AD-C2AD-4236-8DF8-8E69227D0743} + Library + Properties + Podio.API + Podio.API + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\Podio.API.XML + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.4.5.9\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Podio.API/Services/ItemService.cs b/Podio.API/Services/ItemService.cs index c50bd3b..03cc52d 100644 --- a/Podio.API/Services/ItemService.cs +++ b/Podio.API/Services/ItemService.cs @@ -1,393 +1,403 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using Podio.API.Model; -using Podio.API.Utils; - - -namespace Podio.API.Services -{ - public class ItemService - { - private Client _client; - - /// - /// Add a client and you can use this as a shortcut to the Podio REST API - /// - public ItemService(Client client) - { - _client = client; - } - - /// - /// https://developers.podio.com/doc/items/add-new-item-22362 - /// - public Item AddNewItem(int appId, CreateUpdateRequest requestData) - { - return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; - } - - /// - /// https://developers.podio.com/doc/items/add-new-item-22362 - /// - public int AddNewItem(int appId, Item item) - { - var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); - var requestData = new CreateUpdateRequest() - { - ExternalId = item.ExternalId, - Fields = fieldValues, - FileIds = item.FileIds, - Tags = item.Tags - }; - var newItem = AddNewItem(appId, requestData); - item.ItemId = newItem.ItemId; - item.Title = newItem.Title; - return (int)item.ItemId; - } - - /// - /// https://developers.podio.com/doc/items/calculate-67633 - /// - public void Calculate(int appId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/delete-item-s-22364 - /// - public PodioRestHelper.PodioResponse DeleteItem(int itemId, bool silent = false) - { - return DeleteItems(new int[] { itemId }, silent); - } - - /// - /// https://developers.podio.com/doc/items/delete-item-reference-7302326 - /// - public PodioRestHelper.PodioResponse DeleteItemReference(int itemId) - { - return PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}/ref", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.DELETE); - } - - /// - /// https://developers.podio.com/doc/items/delete-item-s-22364 - /// - public PodioRestHelper.PodioResponse DeleteItems(IEnumerable itemIds, bool silent = false) - { - return PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + String.Join(",", itemIds.Select(id => id.ToString()).ToArray()), _client.AuthInfo.AccessToken, new { silent = silent }, PodioRestHelper.RequestMethod.DELETE); - } - - /// - /// https://developers.podio.com/doc/items/export-items-4235696 - /// - public Batch ExportItems(int appId, ExportType export, FilterItemRequest request) - { - return PodioRestHelper.JSONRequest(String.Format("{0}/item/app/{1}/export/{2}", Constants.PODIOAPI_BASEURL, appId, export.ToString()), _client.AuthInfo.AccessToken, request, PodioRestHelper.RequestMethod.POST).Data; - } - - /// - /// https://developers.podio.com/doc/items/filter-items-4496747 - /// - public PodioCollection FilterItems(int appId, FilterItemRequest requestData) - { - return PodioRestHelper.JSONRequest>(String.Format("{0}/item/app/{1}/filter/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; - } - - /// - /// https://developers.podio.com/doc/items/filter-items-by-view-4540284 - /// - public PodioCollection FilterItemsByView(int appId, int viewId, int? limit = null, int? offset = null, bool? remembered = null) - { - Dictionary args = new Dictionary(); - - if (limit != null) - args.Add("limit", limit.ToString()); - if (offset != null) - args.Add("offset", offset.ToString()); - - if (remembered != null) - args.Add("remembered", remembered.ToString()); - - return PodioRestHelper.Request>(String.Format("{0}/item/app/{1}/filter/{2}/", Constants.PODIOAPI_BASEURL, appId, viewId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.POST).Data; - } - - /// - /// https://developers.podio.com/doc/items/find-referenceable-items-22485 - /// - public List FindReferenceableItems(int fieldId, int? limit = null, IEnumerable excludeItemIds =null, string sort =null, string search = null) - { - Dictionary args = new Dictionary(); - if (limit != null) { args.Add("limit", limit.ToString()); } - if (sort != null) { args.Add("sort", sort); } - if (search != null) { args.Add("text", search); } - if (excludeItemIds != null) - { - args.Add("not_item_id", String.Join(",", excludeItemIds.Select(id => id.ToString()).ToArray())); - } - return PodioRestHelper.Request>(String.Format("{0}/item/field/{1}/find", Constants.PODIOAPI_BASEURL, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-app-values-22455 - /// - public void GetAppValues(int appId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/get-field-ranges-24242866 - /// - public void GetFieldRanges(int fieldId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/get-item-22360 - /// - public Item GetItem(int itemId, bool markAsViewed = true) - { - Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; - return PodioRestHelper.Request(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, args).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-basic-61768 - /// - public Item GetItemBasic(int itemId, bool markAsViewed = true) - { - Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; - return PodioRestHelper.Request(String.Format("{0}/item/{1}/basic", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, args).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-by-external-id-19556702 - /// - public Item GetItemByExternalId(int appId, int externalId) - { - return PodioRestHelper.Request(String.Format("{0}/item/app/{1}/external_id/{2}", Constants.PODIOAPI_BASEURL, appId, externalId), _client.AuthInfo.AccessToken).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-field-values-22368 - /// - public List> GetItemFieldValues(int itemId, int fieldId) - { - return PodioRestHelper.Request>>(String.Format("{0}/item/{1}/value/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-preview-for-field-reference-7529318 - /// - public void GetItemPreviewForFieldReference(int itemId, int fieldId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/get-item-references-22439 - /// - public List GetItemReferences(int itemId) - { - return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-references-to-item-by-field-7403920 - /// - public List GetItemReferencesByField(int itemId, int fieldId, int? limit = null) - { - Dictionary args = new Dictionary(); - if (limit != null) { args.Add("limit", limit.ToString()); } - - return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/field/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-revision-22373 - /// - public ItemRevision GetItemRevision(int itemId, int revisionId) - { - return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}", Constants.PODIOAPI_BASEURL, itemId, revisionId), _client.AuthInfo.AccessToken).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 - /// - public ItemDiff GetItemRevisionDifference(int itemId, int revisionFromId, int revisionToId) - { - return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}/{3}", Constants.PODIOAPI_BASEURL, itemId, revisionFromId, revisionToId), _client.AuthInfo.AccessToken).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 - /// - public ICollection GetItemRevisions(int itemId) - { - return PodioRestHelper.Request>(String.Format("{0}/item/{1}/revision/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-items-27803 - /// - public PodioCollection GetItems(int appId, int limit, int offset, Dictionary filters = null, bool? remembered = null, string sortBy = null, bool? sortDesc = null, int? viewId = null) - { - Dictionary args = new Dictionary(); - args.Add("limit", limit.ToString()); - args.Add("offset", offset.ToString()); - - if (remembered != null) { args.Add("remembered", remembered.ToString()); } - if (!string.IsNullOrEmpty(sortBy)) { args.Add("sort_by", sortBy); } - if (sortDesc != null) { args.Add("sort_desc", sortDesc.ToString()); } - if (viewId != null) { args.Add("view_id", viewId.ToString()); } - - if (filters != null) - { - foreach (KeyValuePair f in filters) - { - if (!args.ContainsKey(f.Key)) - { - args.Add(f.Key, f.Value); - } - } - } - - return PodioRestHelper.Request>(Constants.PODIOAPI_BASEURL + "/item/app/" + appId + "/", _client.AuthInfo.AccessToken, args).Data; - } - - /// - /// https://developers.podio.com/doc/items/get-items-as-xlsx-63233 - /// - public void GetItemsAsXLSX(int appId, FilterItemRequest req) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/get-meeting-url-14763260 - /// - public string GetMeetingURL(int itemId) - { - string retval = String.Empty; - Dictionary o = PodioRestHelper.JSONRequest>(String.Format("{0}/item/{1}/meeting/url", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; - if (o.ContainsKey("url")) { retval = o["url"].ToString(); } - return retval; - } - - /// - /// https://developers.podio.com/doc/items/get-top-values-for-field-68334 - /// - public List GetTopValuesByField(int fieldId, int? limit =null, IEnumerable excludeItems = null) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/revert-item-revision-953195 - /// - public void RevertItemRevision(int itemId, int revisionId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/set-participation-7156154 - /// - public void SetParticipation(int itemId, string status) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/update-item-22363 - /// - public void UpdateItem(Item item) - { - var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); - var requestData = new CreateUpdateRequest() - { - ExternalId = item.ExternalId, - Fields = fieldValues, - FileIds = item.FileIds, - Tags = item.Tags - }; - UpdateItem((int)item.ItemId, requestData); - } - - /// - /// https://developers.podio.com/doc/items/update-item-22363 - /// - public void UpdateItem(int itemId, CreateUpdateRequest requestData) - { - PodioRestHelper.JSONRequest(Constants.PODIOAPI_BASEURL + "/item/" + itemId, _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.PUT); - } - /// - /// https://developers.podio.com/doc/items/update-item-field-values-22367 - /// - public void UpdateItemFieldValues(int itemId, int fieldId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - /// - /// https://developers.podio.com/doc/items/update-item-values-22366 - /// - public void UpdateItemValues(int itemId) - { - throw new NotImplementedException("Method not implemented yet."); - } - - [DataContract] - public struct CreateUpdateRequest - { - [DataMember(IsRequired = false, Name = "external_id")] - public string ExternalId { get; set; } - - [DataMember(IsRequired = false, Name = "fields")] - public IEnumerable> Fields { get; set; } - - [DataMember(IsRequired = false, Name = "file_ids")] - public IEnumerable FileIds { get; set; } - - [DataMember(IsRequired = false, Name = "tags")] - public IEnumerable Tags { get; set; } - - [DataMember(IsRequired = false, Name = "reminder")] - public Reminder Reminder { get; set; } - - [DataMember(IsRequired = false, Name = "recurrence")] - public Recurrence Recurrence { get; set; } - - [DataMember(IsRequired = false, Name = "linked_account_id")] - public int? LinkedAccountId { get; set; } - - [DataMember(IsRequired = false, Name = "ref")] - public Ref Ref { get; set; } - } - [DataContract] - public struct FilterItemRequest - { - [DataMember(IsRequired = false, Name = "sort_by")] - public string SortBy { get; set; } - - [DataMember(IsRequired = false, Name = "sort_desc")] - public bool? SortDesc { get; set; } - - [DataMember(IsRequired = false, Name = "limit")] - public int? Limit { get; set; } - - [DataMember(IsRequired = false, Name = "offset")] - public int? Offset { get; set; } - - [DataMember(IsRequired = false, Name = "remember")] - public bool? Remember { get; set; } - - [DataMember(IsRequired = false, Name = "filters")] - public List> Filters { get; set; } - } - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using Podio.API.Model; +using Podio.API.Utils; + + +namespace Podio.API.Services +{ + public class ItemService + { + private Client _client; + + /// + /// Add a client and you can use this as a shortcut to the Podio REST API + /// + public ItemService(Client client) + { + _client = client; + } + + /// + /// https://developers.podio.com/doc/items/add-new-item-22362 + /// + public Item AddNewItem(int appId, CreateUpdateRequest requestData) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/app/{1}/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/add-new-item-22362 + /// + public int AddNewItem(int appId, Item item) + { + var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); + var requestData = new CreateUpdateRequest() + { + ExternalId = item.ExternalId, + Fields = fieldValues, + FileIds = item.FileIds, + Tags = item.Tags + }; + var newItem = AddNewItem(appId, requestData); + item.ItemId = newItem.ItemId; + item.Title = newItem.Title; + return (int)item.ItemId; + } + + /// + /// https://developers.podio.com/doc/items/calculate-67633 + /// + public void Calculate(int appId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-s-22364 + /// + public PodioRestHelper.PodioResponse DeleteItem(int itemId, bool silent = false) + { + return DeleteItems(new int[] { itemId }, silent); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-reference-7302326 + /// + public PodioRestHelper.PodioResponse DeleteItemReference(int itemId) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}/ref", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/items/delete-item-s-22364 + /// + public PodioRestHelper.PodioResponse DeleteItems(IEnumerable itemIds, bool silent = false) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}", Constants.PODIOAPI_BASEURL, String.Join(",", itemIds.Select(id => id.ToString()).ToArray())), _client.AuthInfo.AccessToken, new { silent = silent }, PodioRestHelper.RequestMethod.DELETE); + } + + /// + /// https://developers.podio.com/doc/items/export-items-4235696 + /// + public Batch ExportItems(int appId, ExportType export, FilterItemRequest request) + { + return PodioRestHelper.JSONRequest(String.Format("{0}/item/app/{1}/export/{2}", Constants.PODIOAPI_BASEURL, appId, export), _client.AuthInfo.AccessToken, request, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/filter-items-4496747 + /// + public PodioCollection FilterItems(int appId, FilterItemRequest requestData) + { + return PodioRestHelper.JSONRequest>(String.Format("{0}/item/app/{1}/filter/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/filter-items-by-view-4540284 + /// + public PodioCollection FilterItemsByView(int appId, int viewId, int? limit = null, int? offset = null, bool? remembered = null) + { + Dictionary args = new Dictionary(); + + if (limit != null) + args.Add("limit", limit.ToString()); + if (offset != null) + args.Add("offset", offset.ToString()); + + if (remembered != null) + args.Add("remembered", remembered.ToString()); + + return PodioRestHelper.Request>(String.Format("{0}/item/app/{1}/filter/{2}/", Constants.PODIOAPI_BASEURL, appId, viewId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.POST).Data; + } + + /// + /// https://developers.podio.com/doc/items/find-referenceable-items-22485 + /// + public List FindReferenceableItems(int fieldId, int? limit = null, IEnumerable excludeItemIds =null, string sort =null, string search = null) + { + Dictionary args = new Dictionary(); + if (limit != null) { args.Add("limit", limit.ToString()); } + if (sort != null) { args.Add("sort", sort); } + if (search != null) { args.Add("text", search); } + if (excludeItemIds != null) + { + args.Add("not_item_id", String.Join(",", excludeItemIds.Select(id => id.ToString()).ToArray())); + } + return PodioRestHelper.Request>(String.Format("{0}/item/field/{1}/find", Constants.PODIOAPI_BASEURL, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-app-values-22455 + /// + public AppValues GetAppValues(int appId) + { + return PodioRestHelper.Request(String.Format("{0}/item/app/{1}/values", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-field-ranges-24242866 + /// + public ItemFieldRange GetFieldRanges(int fieldId) + { + return PodioRestHelper.Request(String.Format("{0}/item/field/{1}/range", Constants.PODIOAPI_BASEURL, fieldId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-22360 + /// + public Item GetItem(int itemId, bool markAsViewed = true) + { + Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; + return PodioRestHelper.Request(String.Format("{0}/item/{1}", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-basic-61768 + /// + public Item GetItemBasic(int itemId, bool markAsViewed = true) + { + Dictionary args = new Dictionary() { { "mark_as_viewed", markAsViewed.ToString() } }; + return PodioRestHelper.Request(String.Format("{0}/item/{1}/basic", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-by-external-id-19556702 + /// + public Item GetItemByExternalId(int appId, int externalId) + { + return PodioRestHelper.Request(String.Format("{0}/item/app/{1}/external_id/{2}", Constants.PODIOAPI_BASEURL, appId, externalId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-field-values-22368 + /// + public List> GetItemFieldValues(int itemId, int fieldId) + { + return PodioRestHelper.Request>>(String.Format("{0}/item/{1}/value/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-preview-for-field-reference-7529318 + /// + public Item GetItemPreviewForFieldReference(int itemId, int fieldId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/reference/{2}/preview", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-references-22439 + /// + public List GetItemReferences(int itemId) + { + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-references-to-item-by-field-7403920 + /// + public List GetItemReferencesByField(int itemId, int fieldId, int? limit = null) + { + Dictionary args = new Dictionary(); + if (limit != null) { args.Add("limit", limit.ToString()); } + + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/reference/field/{2}", Constants.PODIOAPI_BASEURL, itemId, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-22373 + /// + public ItemRevision GetItemRevision(int itemId, int revisionId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}", Constants.PODIOAPI_BASEURL, itemId, revisionId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 + /// + public ItemDiff GetItemRevisionDifference(int itemId, int revisionFromId, int revisionToId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}/{3}", Constants.PODIOAPI_BASEURL, itemId, revisionFromId, revisionToId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-item-revision-difference-22374 + /// + public ICollection GetItemRevisions(int itemId) + { + return PodioRestHelper.Request>(String.Format("{0}/item/{1}/revision/", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-items-27803 + /// + public PodioCollection GetItems(int appId, int limit, int offset, Dictionary filters = null, bool? remembered = null, string sortBy = null, bool? sortDesc = null, int? viewId = null) + { + Dictionary args = new Dictionary(); + args.Add("limit", limit.ToString()); + args.Add("offset", offset.ToString()); + + if (remembered != null) { args.Add("remembered", remembered.ToString()); } + if (!string.IsNullOrEmpty(sortBy)) { args.Add("sort_by", sortBy); } + if (sortDesc != null) { args.Add("sort_desc", sortDesc.ToString()); } + if (viewId != null) { args.Add("view_id", viewId.ToString()); } + + if (filters != null) + { + foreach (KeyValuePair f in filters) + { + if (!args.ContainsKey(f.Key)) + { + args.Add(f.Key, f.Value); + } + } + } + + return PodioRestHelper.Request>(String.Format("{0}/item/app/{1}/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, args).Data; + } + + /// + /// https://developers.podio.com/doc/items/get-items-as-xlsx-63233 + /// + public void GetItemsAsXLSX(int appId, FilterItemRequest req) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/get-meeting-url-14763260 + /// + public string GetMeetingURL(int itemId) + { + string retval = String.Empty; + Dictionary o = PodioRestHelper.JSONRequest>(String.Format("{0}/item/{1}/meeting/url", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.GET).Data; + if (o.ContainsKey("url")) { retval = o["url"].ToString(); } + return retval; + } + + /// + /// https://developers.podio.com/doc/items/get-top-values-for-field-68334 + /// + public List GetTopValuesByField(int fieldId, int? limit = null, IEnumerable excludeItemIds = null) + { + Dictionary args = new Dictionary(); + if (limit != null) + { + args.Add("limit", limit.ToString()); + } + if (excludeItemIds != null) + { + args.Add("not_item_id", String.Join(",", excludeItemIds.Select(id => id.ToString()).ToArray())); + } + return PodioRestHelper.Request>(String.Format("{0}/item/field/{1}/top", Constants.PODIOAPI_BASEURL, fieldId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.GET).Data; + } + + /// + /// https://developers.podio.com/doc/items/revert-item-revision-953195 + /// + public ItemRevision RevertItemRevision(int itemId, int revisionId) + { + return PodioRestHelper.Request(String.Format("{0}/item/{1}/revision/{2}", Constants.PODIOAPI_BASEURL, itemId, revisionId), _client.AuthInfo.AccessToken, null, PodioRestHelper.RequestMethod.DELETE).Data; + } + + /// + /// https://developers.podio.com/doc/items/set-participation-7156154 + /// + public PodioRestHelper.PodioResponse SetParticipation(int itemId, ParticipationStatus status) + { + Dictionary args = new Dictionary(){{"status",status.ToString() }}; + return PodioRestHelper.Request(String.Format("{0}/item/{1}/participation", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, args, PodioRestHelper.RequestMethod.PUT); + } + + /// + /// https://developers.podio.com/doc/items/update-item-22363 + /// + public void UpdateItem(Item item) + { + var fieldValues = item.Fields.Select(f => f.Values == null ? null : new { external_id = f.ExternalId, values = f.Values }.AsDictionary()).Where(f => f != null); + var requestData = new CreateUpdateRequest() + { + ExternalId = item.ExternalId, + Fields = fieldValues, + FileIds = item.FileIds, + Tags = item.Tags + }; + UpdateItem((int)item.ItemId, requestData); + } + + /// + /// https://developers.podio.com/doc/items/update-item-22363 + /// + public void UpdateItem(int itemId, CreateUpdateRequest requestData) + { + PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.PUT); + } + /// + /// https://developers.podio.com/doc/items/update-item-field-values-22367 + /// + public void UpdateItemFieldValues(int itemId, int fieldId, bool silent = false) + { + throw new NotImplementedException("Method not implemented yet."); + } + + /// + /// https://developers.podio.com/doc/items/update-item-values-22366 + /// + public void UpdateItemValues(int itemId) + { + throw new NotImplementedException("Method not implemented yet."); + } + + [DataContract] + public struct CreateUpdateRequest + { + [DataMember(IsRequired = false, Name = "external_id")] + public string ExternalId { get; set; } + + [DataMember(IsRequired = false, Name = "fields")] + public IEnumerable> Fields { get; set; } + + [DataMember(IsRequired = false, Name = "file_ids")] + public IEnumerable FileIds { get; set; } + + [DataMember(IsRequired = false, Name = "tags")] + public IEnumerable Tags { get; set; } + + [DataMember(IsRequired = false, Name = "reminder")] + public Reminder Reminder { get; set; } + + [DataMember(IsRequired = false, Name = "recurrence")] + public Recurrence Recurrence { get; set; } + + [DataMember(IsRequired = false, Name = "linked_account_id")] + public int? LinkedAccountId { get; set; } + + [DataMember(IsRequired = false, Name = "ref")] + public Ref Ref { get; set; } + } + [DataContract] + public struct FilterItemRequest + { + [DataMember(IsRequired = false, Name = "sort_by")] + public string SortBy { get; set; } + + [DataMember(IsRequired = false, Name = "sort_desc")] + public bool? SortDesc { get; set; } + + [DataMember(IsRequired = false, Name = "limit")] + public int? Limit { get; set; } + + [DataMember(IsRequired = false, Name = "offset")] + public int? Offset { get; set; } + + [DataMember(IsRequired = false, Name = "remember")] + public bool? Remember { get; set; } + + [DataMember(IsRequired = false, Name = "filters")] + public List> Filters { get; set; } + } + + } +} diff --git a/Podio.API/Utils/AppValues.cs b/Podio.API/Utils/AppValues.cs new file mode 100644 index 0000000..ddcce54 --- /dev/null +++ b/Podio.API/Utils/AppValues.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Collections; + +namespace Podio.API.Model +{ + [DataContract] + public class AppValues + { + [DataMember(Name = "created_bys", IsRequired = false)] + public List Creators { get; set; } + + [DataMember(Name = "created_vias", IsRequired = false)] + public List CreatedVias { get; set; } + + [DataMember(Name = "tags", IsRequired = false)] + public List Tags { get; set; } + + [DataMember(Name = "fields", IsRequired = false)] + public List Fields { get; set; } + } +} diff --git a/Podio.API/Utils/ItemFieldRange.cs b/Podio.API/Utils/ItemFieldRange.cs new file mode 100644 index 0000000..1438991 --- /dev/null +++ b/Podio.API/Utils/ItemFieldRange.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Podio.API.Model +{ + [DataContract] + public class ItemFieldRange + { + [DataMember(Name = "min", IsRequired = false)] + public int? Min { get; set; } + + [DataMember(Name = "max", IsRequired = false)] + public int? Max { get; set; } + } +} From 9b411d8880c6f8f47d09ccdfd9b92641104ec004 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Thu, 3 Jan 2013 23:21:23 -0800 Subject: [PATCH 6/8] added class file to project --- Podio.API/Podio.API.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Podio.API/Podio.API.csproj b/Podio.API/Podio.API.csproj index 94e8d51..2798b4b 100644 --- a/Podio.API/Podio.API.csproj +++ b/Podio.API/Podio.API.csproj @@ -132,6 +132,7 @@ + From 1489fff30bfa464bc0a13c79bac0dfa9e5312a21 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Fri, 4 Jan 2013 16:25:26 -0800 Subject: [PATCH 7/8] bug fix: Check ItemField values before enumerating. --- Podio.API/Utils/ItemFields/EmbedItemField.cs | 20 ++++++++++++-------- Podio.API/Utils/ItemFields/ItemField.cs | 9 ++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Podio.API/Utils/ItemFields/EmbedItemField.cs b/Podio.API/Utils/ItemFields/EmbedItemField.cs index dbe1d4d..c39c017 100644 --- a/Podio.API/Utils/ItemFields/EmbedItemField.cs +++ b/Podio.API/Utils/ItemFields/EmbedItemField.cs @@ -17,18 +17,22 @@ public IEnumerable Embeds if (_embeds == null) { _embeds = new List(); - foreach (var embedFilePair in this.Values) + if (this.Values != null) { - var embed = this.valueAs(embedFilePair, "embed"); - if (embedFilePair.ContainsKey("file")) + foreach (var embedFilePair in this.Values) { - var file = this.valueAs(embedFilePair, "file"); - if (embed.Files == null) { - embed.Files = new List(); + var embed = this.valueAs(embedFilePair, "embed"); + if (embedFilePair.ContainsKey("file")) + { + var file = this.valueAs(embedFilePair, "file"); + if (embed.Files == null) + { + embed.Files = new List(); + } + embed.Files.Add(file); } - embed.Files.Add(file); + _embeds.Add(embed); } - _embeds.Add(embed); } } return _embeds; diff --git a/Podio.API/Utils/ItemFields/ItemField.cs b/Podio.API/Utils/ItemFields/ItemField.cs index 6960400..dbafad2 100644 --- a/Podio.API/Utils/ItemFields/ItemField.cs +++ b/Podio.API/Utils/ItemFields/ItemField.cs @@ -47,10 +47,13 @@ protected List valuesAs(List list) if (list == null) { list = new List(); - foreach (var itemAttributes in this.Values) + if (this.Values != null) { - var obj = this.valueAs(itemAttributes, "value"); - list.Add(obj); + foreach (var itemAttributes in this.Values) + { + var obj = this.valueAs(itemAttributes, "value"); + list.Add(obj); + } } } return list; From 908b56ce0762bab588832680e09fad9ba07dd609 Mon Sep 17 00:00:00 2001 From: Brent Johnson Date: Fri, 19 Apr 2013 16:06:27 -0700 Subject: [PATCH 8/8] Commented out unimplemented functions. --- Podio.API/Services/ItemService.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Podio.API/Services/ItemService.cs b/Podio.API/Services/ItemService.cs index 03cc52d..437c192 100644 --- a/Podio.API/Services/ItemService.cs +++ b/Podio.API/Services/ItemService.cs @@ -47,6 +47,7 @@ public int AddNewItem(int appId, Item item) return (int)item.ItemId; } + /* /// /// https://developers.podio.com/doc/items/calculate-67633 /// @@ -54,6 +55,7 @@ public void Calculate(int appId) { throw new NotImplementedException("Method not implemented yet."); } + */ /// /// https://developers.podio.com/doc/items/delete-item-s-22364 @@ -258,6 +260,7 @@ public PodioCollection GetItems(int appId, int limit, int offset, Dictiona return PodioRestHelper.Request>(String.Format("{0}/item/app/{1}/", Constants.PODIOAPI_BASEURL, appId), _client.AuthInfo.AccessToken, args).Data; } + /* /// /// https://developers.podio.com/doc/items/get-items-as-xlsx-63233 /// @@ -265,6 +268,7 @@ public void GetItemsAsXLSX(int appId, FilterItemRequest req) { throw new NotImplementedException("Method not implemented yet."); } + */ /// /// https://developers.podio.com/doc/items/get-meeting-url-14763260 @@ -334,6 +338,8 @@ public void UpdateItem(int itemId, CreateUpdateRequest requestData) { PodioRestHelper.JSONRequest(String.Format("{0}/item/{1}", Constants.PODIOAPI_BASEURL, itemId), _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.PUT); } + + /* /// /// https://developers.podio.com/doc/items/update-item-field-values-22367 /// @@ -349,6 +355,7 @@ public void UpdateItemValues(int itemId) { throw new NotImplementedException("Method not implemented yet."); } + */ [DataContract] public struct CreateUpdateRequest