forked from chojnac/NotionSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
272 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
# NotionSwift | ||
|
||
Unofficial Notion SDK for Swift. | ||
Unofficial Notion SDK for iOS & macOS | ||
|
||
|
||
## Supported Endpoints | ||
|
||
### Databases | ||
* Retrieve a database ✅ | ||
* Query a database ✅ | ||
* List databases ✅ | ||
|
||
### Pages | ||
* Retrieve a page ✅ | ||
* Create a page | ||
* Update page properties | ||
|
||
### Blocks | ||
* Retrieve block children | ||
* Append block children | ||
|
||
### Users | ||
* Retrieve a user ✅ | ||
* List all users ✅ | ||
|
||
### Search | ||
* Search |
This file was deleted.
Oops, something went wrong.
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
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,57 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Wojciech Chojnacki on 01/06/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
public class URLBuilder { | ||
let base: URL | ||
|
||
init() { | ||
self.base = Network.notionBaseURL | ||
} | ||
|
||
public func url<T>( | ||
path: String, | ||
identifier: EntityIdentifier<T, String>, | ||
params: [String: String] = [:] | ||
) -> URL { | ||
let newPath = path.replacingOccurrences(of: "{identifier}", with: identifier.rawValue) | ||
guard let url = URL(string: newPath, relativeTo: base) else { | ||
fatalError("Invalid path, unable to create a URL: \(path)") | ||
} | ||
|
||
return buildURL(url: url, params: params) | ||
} | ||
|
||
public func url( | ||
path: String, | ||
params: [String: String] = [:] | ||
) -> URL { | ||
guard let url = URL(string: path, relativeTo: base) else { | ||
fatalError("Invalid path, unable to create a URL: \(path)") | ||
} | ||
|
||
return buildURL(url: url, params: params) | ||
} | ||
|
||
private func buildURL(url: URL, params: [String: String]) -> URL { | ||
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { | ||
fatalError("Invalid url, unable to build components path") | ||
} | ||
|
||
if !params.isEmpty { | ||
components.queryItems = params.map { | ||
URLQueryItem(name: $0.key, value: $0.value) | ||
} | ||
} | ||
guard let result = components.url else { | ||
fatalError("Unable to create url from components (\(components)") | ||
} | ||
|
||
return result | ||
} | ||
} |
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
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
Oops, something went wrong.