-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from asevos/feature/pages_endpoints
Add Pages API's support ✨
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Notion.Client | ||
{ | ||
public interface IPagesClient | ||
{ | ||
Task<Page> CreateAsync(NewPage page); | ||
Task<Page> RetrieveAsync(string pageId); | ||
|
||
Task<Page> UpdatePropertiesAsync( | ||
string pageId, | ||
IDictionary<string, PropertyValue> updatedProperties | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using static Notion.Client.ApiEndpoints; | ||
|
||
namespace Notion.Client | ||
{ | ||
public class PagesClient : IPagesClient | ||
{ | ||
private readonly IRestClient _client; | ||
|
||
public PagesClient(IRestClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public async Task<Page> CreateAsync(NewPage page) | ||
{ | ||
return await _client.PostAsync<Page>(PagesApiUrls.Create(), page); | ||
} | ||
|
||
public async Task<Page> RetrieveAsync(string pageId) | ||
{ | ||
var url = PagesApiUrls.Retrieve(pageId); | ||
return await _client.GetAsync<Page>(url); | ||
} | ||
|
||
public async Task<Page> UpdatePropertiesAsync( | ||
string pageId, | ||
IDictionary<string, PropertyValue> updatedProperties) | ||
{ | ||
var url = PagesApiUrls.UpdateProperties(pageId); | ||
var body = new UpdatePropertiesParameters { Properties = updatedProperties }; | ||
|
||
return await _client.PatchAsync<Page>(url, body); | ||
} | ||
|
||
private class UpdatePropertiesParameters | ||
{ | ||
public IDictionary<string, PropertyValue> Properties { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Notion.Client | ||
{ | ||
public class NewPage | ||
{ | ||
/// <summary> | ||
/// Constructor without arguments: added for class initializations using class literals. | ||
/// </summary> | ||
public NewPage() | ||
{ | ||
Properties = new Dictionary<string, PropertyValue>(); | ||
Children = new List<Block>(); | ||
} | ||
|
||
/// <summary> | ||
/// Constructor that adds required <c>Parent</c> property. Used when you don't want to | ||
/// assign properties in separate operations. | ||
/// </summary> | ||
public NewPage(Parent parent) | ||
{ | ||
Parent = parent; | ||
Properties = new Dictionary<string, PropertyValue>(); | ||
Children = new List<Block>(); | ||
} | ||
|
||
public Parent Parent { get; set; } | ||
|
||
public Dictionary<string, PropertyValue> Properties { get; set; } | ||
|
||
public List<Block> Children { get; set; } | ||
|
||
public NewPage AddProperty(string nameOrId, PropertyValue value) | ||
{ | ||
Properties[nameOrId] = value; | ||
return this; | ||
} | ||
|
||
public NewPage AddPageContent(Block block) | ||
{ | ||
Children.Add(block); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters