Skip to content

Commit

Permalink
feat: add Delete Page example, rename pageUpdateProperties to pageUpd…
Browse files Browse the repository at this point in the history
…ate because this endpoint not just for update property (#52)
  • Loading branch information
AnthonyBY authored Sep 2, 2024
1 parent 13e74cd commit 05cdb05
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ notion.pageCreate(request: request) {
let pageId = Page.Identifier("{PAGE UUIDv4}")

// update title property
let request = PageProperiesUpdateRequest(
let request = PageUpdateRequest(
properties: [
.name("title"): .init(
type: .title([
Expand All @@ -237,7 +237,20 @@ let request = PageProperiesUpdateRequest(
]
)

notion.pageUpdateProperties(pageId: pageId, request: request) {
notion.pageUpdate(pageId: pageId, request: request) {
print($0)
}
```

### Delete page

```swift
let pageId = Page.Identifier("{PAGE UUIDv4}")

// Archive page (trash a page)
let request = PageUpdateRequest(archived: true)

notion.pageUpdate(pageId: pageId, request: request) {
print($0)
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

public struct PageProperiesUpdateRequest {
public struct PageUpdateRequest {
public enum Key: Hashable, Equatable {
case name(Page.PropertyName)
case id(PageProperty.Identifier)
Expand All @@ -29,7 +29,7 @@ public struct PageProperiesUpdateRequest {

}

extension PageProperiesUpdateRequest: Encodable {
extension PageUpdateRequest: Encodable {
enum CodingKeys: String, CodingKey {
case properties
case archived
Expand Down Expand Up @@ -61,7 +61,7 @@ extension PageProperiesUpdateRequest: Encodable {
}
}

extension PageProperiesUpdateRequest.Key: Encodable {
extension PageUpdateRequest.Key: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NotionSwift/NotionClient+Pages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import Foundation
)
}

public func pageUpdateProperties(
public func pageUpdate(
pageId: Page.Identifier,
request: PageProperiesUpdateRequest,
request: PageUpdateRequest,
completed: @escaping (Result<Page, NotionClientError>) -> Void
) {
networkClient.patch(
Expand Down
6 changes: 3 additions & 3 deletions Sources/NotionSwift/NotionClientType+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ extension NotionClientType {
}
}

public func pageUpdateProperties(
public func pageUpdate(
pageId: Page.Identifier,
request: PageProperiesUpdateRequest
request: PageUpdateRequest
) -> AnyPublisher<Page, NotionClientError> {
convertToPublisher { promise in
self.pageUpdateProperties(
self.pageUpdate(
pageId: pageId,
request: request,
completed: promise
Expand Down
4 changes: 2 additions & 2 deletions Sources/NotionSwift/NotionClientType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public protocol NotionClientType: AnyObject {
completed: @escaping (Result<Page, NotionClientError>) -> Void
)

func pageUpdateProperties(
func pageUpdate(
pageId: Page.Identifier,
request: PageProperiesUpdateRequest,
request: PageUpdateRequest,
completed: @escaping (Result<Page, NotionClientError>) -> Void
)

Expand Down

0 comments on commit 05cdb05

Please sign in to comment.