Skip to content

Commit

Permalink
Add filtering to posts
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Oct 18, 2024
1 parent 7dd6bd2 commit 48b56e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Ghosting/buildServer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "xcode build server",
"version": "0.2",
"bspVersion": "2.0",
"languages": [
"c",
"cpp",
"objective-c",
"objective-cpp",
"swift"
],
"argv": [
"/opt/homebrew/bin/xcode-build-server"
],
"workspace": "/Users/rudrankriyam/Downloads/Frameworks/GhostingKit/Ghosting/Ghosting.xcodeproj/project.xcworkspace",
"build_root": "/Users/rudrankriyam/Library/Developer/Xcode/DerivedData/Ghosting-dqoifpovskmbjqapxwojysnnoqwx",
"scheme": "Ghosting",
"kind": "xcode"
}
14 changes: 12 additions & 2 deletions Sources/GhostingKit/GhostingKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,28 @@ public actor GhostingKit {

return data
}

/// Fetches posts from the Ghost Content API.
///
/// This method retrieves posts from the Ghost Content API, allowing you to customize the query
/// with various parameters.
///
/// - Parameters:
/// - limit: The maximum number of posts to return (default is 15).
/// - page: The page of posts to return (default is 1).
/// - include: Related data to include in the response (e.g., "authors,tags").
/// - filter: A filter query to apply to the posts (e.g., "tag:getting-started").
///
/// - Returns: A `GhostPostsResponse` containing an array of `GhostPost` objects.
///
/// - Throws: An error if the network request fails, returns an invalid response, or fails to decode the JSON.
///
/// - Note: The `filter` parameter allows you to narrow down the posts based on specific criteria.
/// For example, you can use "tag:getting-started" to fetch only posts with the "getting-started" tag.
public func getPosts(
limit: Int = 15,
page: Int = 1,
include: String? = nil
include: String? = nil,
filter: String? = nil
) async throws -> GhostPostsResponse {
var parameters: [String: String] = [
"limit": String(limit),
Expand All @@ -99,6 +106,9 @@ public actor GhostingKit {
if let include = include {
parameters["include"] = include
}
if let filter = filter {
parameters["filter"] = filter
}
let data = try await get("posts", parameters: parameters)
let decoder = JSONDecoder()
// decoder.dateDecodingStrategy = .iso8601
Expand Down

0 comments on commit 48b56e2

Please sign in to comment.