Skip to content

Add support for Retrieve page property item #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var complexFiler = new CompoundFilter(
- [x] Retrieve a page
- [x] Create a page
- [x] Update page
- [x] Retrieve page property item
- [x] Blocks
- [x] Retrieve a block
- [x] Update a block
Expand Down
8 changes: 8 additions & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public static class PagesApiUrls
public static string Retrieve(string pageId) => $"/v1/pages/{pageId}";
public static string Update(string pageId) => $"/v1/pages/{pageId}";
public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}";

/// <summary>
/// Get the <see cref="uri string"/> for retrieve page property item
/// </summary>
/// <param name="pageId">Identifier for a Notion Page</param>
/// <param name="propertyId">Identifier for a Notion Property</param>
/// <returns></returns>
public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}";
}

public static class SearchApiUrls
Expand Down
7 changes: 7 additions & 0 deletions Src/Notion.Client/Api/Pages/IPagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ IDictionary<string, PropertyValue> updatedProperties
/// <param name="pagesUpdateParameters"></param>
/// <returns>Updated page.</returns>
Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters);

/// <summary>
/// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values.
/// </summary>
/// <param name="retrievePropertyItemParameters">sdf sd</param>
/// <returns><see cref="IPropertyItemObject"/></returns>
Task<IPropertyItemObject> RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters);
}
}
16 changes: 16 additions & 0 deletions Src/Notion.Client/Api/Pages/PagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public async Task<Page> RetrieveAsync(string pageId)
return await _client.GetAsync<Page>(url);
}

public async Task<IPropertyItemObject> RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters)
{
var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters;
var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters;

var url = PagesApiUrls.RetrievePropertyItem(pathParameters.PageId, pathParameters.PropertyId);

var queryParams = new Dictionary<string, string>()
{
{ "start_cursor", queryParameters?.StartCursor },
{ "page_size", queryParameters?.PageSize?.ToString() }
};

return await _client.GetAsync<IPropertyItemObject>(url, queryParams);
}

public async Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters)
{
var url = PagesApiUrls.Update(pageId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IRetrievePropertyItemPathParameters
{
[JsonProperty("page_id")]
string PageId { get; set; }

[JsonProperty("property_id")]
string PropertyId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Notion.Client
{
public interface IRetrievePropertyQueryParameters : IPaginationParameters
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Notion.Client
{
public class RetrievePropertyItemParameters : IRetrievePropertyItemPathParameters, IRetrievePropertyQueryParameters
{
public string PageId { get; set; }

public string PropertyId { get; set; }

public string StartCursor { get; set; }

public int? PageSize { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/CheckboxPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class CheckboxPropertyItem : SimplePropertyItem
{
public override string Type => "checkbox";

[JsonProperty("checkbox")]
public bool Checkbox { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/CreatedByPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class CreatedByPropertyItem : SimplePropertyItem
{
public override string Type => "created_by";

[JsonProperty("created_by")]
public User CreatedBy { get; set; }
}
}
13 changes: 13 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/CreatedTimePropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Newtonsoft.Json;

namespace Notion.Client
{
public class CreatedTimePropertyItem : SimplePropertyItem
{
public override string Type => "created_time";

[JsonProperty("created_time")]
public DateTime CreatedTime { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/DatePropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class DatePropertyItem : SimplePropertyItem
{
public override string Type => "date";

[JsonProperty("date")]
public Date Date { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/EmailPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class EmailPropertyItem : SimplePropertyItem
{
public override string Type => "email";

[JsonProperty("email")]
public string Email { get; set; }
}
}
13 changes: 13 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/FilesPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class FilesPropertyItem : SimplePropertyItem
{
public override string Type => "files";

[JsonProperty("files")]
public IEnumerable<FileObjectWithName> Files { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/FormulaPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class FormulaPropertyItem : SimplePropertyItem
{
public override string Type => "formula";

[JsonProperty("formula")]
public FormulaValue Formula { get; set; }
}
}
17 changes: 17 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JsonSubTypes;
using Newtonsoft.Json;

namespace Notion.Client
{
[JsonConverter(typeof(JsonSubtypes), "object")]
[JsonSubtypes.KnownSubType(typeof(SimplePropertyItem), "property_item")]
[JsonSubtypes.KnownSubType(typeof(ListPropertyItem), "list")]
public interface IPropertyItemObject
{
[JsonProperty("object")]
string Object { get; }

[JsonProperty("type")]
string Type { get; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/LastEditedByPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class LastEditedByPropertyItem : SimplePropertyItem
{
public override string Type => "last_edited_by";

[JsonProperty("last_edited_by")]
public User LastEditedBy { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Newtonsoft.Json;

namespace Notion.Client
{
public class LastEditedTimePropertyItem : SimplePropertyItem
{
public override string Type => "last_edited_time";

[JsonProperty("last_edited_time")]
public DateTime LastEditedTime { get; set; }
}
}
24 changes: 24 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using JsonSubTypes;
using Newtonsoft.Json;

namespace Notion.Client
{
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")]
[JsonSubtypes.FallBackSubType(typeof(ListPropertyItem))]
public class ListPropertyItem : IPropertyItemObject
{
public string Object => "list";
public virtual string Type { get; set; }

[JsonProperty("results")]
public IEnumerable<SimplePropertyItem> Results { get; set; }

[JsonProperty("has_more")]
public bool HasMore { get; set; }

[JsonProperty("next_cursor")]
public string NextCursor { get; set; }
}
}
13 changes: 13 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/MultiSelectPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class MultiSelectPropertyItem : SimplePropertyItem
{
public override string Type => "multi_select";

[JsonProperty("multi_select")]
public IEnumerable<SelectOption> MultiSelect { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class NumberPropertyItem : SimplePropertyItem
{
public override string Type => "number";

[JsonProperty("number")]
public Number Number { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/PeoplePropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class PeoplePropertyItem : SimplePropertyItem
{
public override string Type => "people";

[JsonProperty("people")]
public User People { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/PhoneNumberPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class PhoneNumberPropertyItem : SimplePropertyItem
{
public override string Type => "phone_number";

[JsonProperty("phone_number")]
public string PhoneNumber { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/RelationPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class RelationPropertyItem : SimplePropertyItem
{
public override string Type => "relation";

[JsonProperty("relation")]
public ObjectId Relation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Notion.Client
{
public class RichTextPropertyItem : SimplePropertyItem
{
public override string Type => "rich_text";

public RichTextBase RichText { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class RollupPropertyItem : ListPropertyItem
{
public override string Type => "rollup";

[JsonProperty("rollup")]
public RollupValue Rollup { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/SelectPropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class SelectPropertyItem : SimplePropertyItem
{
public override string Type => "select";

[JsonProperty("select")]
public SelectOption Select { get; set; }
}
}
31 changes: 31 additions & 0 deletions Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JsonSubTypes;
using Newtonsoft.Json;

namespace Notion.Client
{
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(NumberPropertyItem), "number")]
[JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")]
[JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")]
[JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")]
[JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")]
[JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")]
[JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")]
[JsonSubtypes.KnownSubType(typeof(CheckboxPropertyItem), "checkbox")]
[JsonSubtypes.KnownSubType(typeof(FilesPropertyItem), "files")]
[JsonSubtypes.KnownSubType(typeof(CreatedByPropertyItem), "created_by")]
[JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyItem), "created_time")]
[JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyItem), "last_edited_by")]
[JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyItem), "last_edited_time")]
[JsonSubtypes.KnownSubType(typeof(FormulaPropertyItem), "formula")]
[JsonSubtypes.KnownSubType(typeof(TitlePropertyItem), "title")]
[JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")]
[JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")]
[JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")]
public abstract class SimplePropertyItem : IPropertyItemObject
{
public string Object => "property_item";

public abstract string Type { get; }
}
}
Loading