Swiftpack.co - mattrighetti/hackernews-swift-api as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mattrighetti.
mattrighetti/hackernews-swift-api 1.0.1
Swift Hacker News API client implemented using Firebase
⭐️ 1
🕓 2 years ago
iOS macOS
.package(url: "https://github.com/mattrighetti/hackernews-swift-api.git", from: "1.0.1")

HackerNews Swift API

This is a swift package that contains the most useful methods that can be used to download stories, comments, user from Hacker News

Installation

Swift Package Manage

HackerNew API is also available through Swift Package Manager. To install it, simply add the dependency to your Package.Swift file:

...
dependencies: [
    .package(url: "https://github.com/mattrighetti/hackernews-swift-api", from: "1.0.0"),
],
targets: [
    .target( name: "YourTarget", dependencies: ["HackerNews"]),
]
...

Dependencies

Library Usage description
Firebase API for iOS This package is used to fetch items from the Firebase Database
SwiftSoup SwiftSoup is used to scrape comments directly from the HN page which is considerably faster than recursively fetching comments from Firebase

Usage

Get top, best and new stories

HackerNewsClient.shared.getStoriesIds(.top) { topIds in
    assert(!topIds.isEmpty())
    print("fetched top items ids: \(topIds)")
}

Get an item

HackerNewsClient.shared.getItem(withId: 27676266) { item in
    print("fetched item: \(item)")
}

Get item comments

let c: [Comment]!
HackerNewsClient.shared.getComments(forItemId: 27676266) { success, comments, hasMore in
    guard success == true else { return }
    assert(!comments.isEmpty())
    c = comments
    if hasMore {
        print("there are more comments ready to fetch in next pages")
    }
}

HackerNewsClient.shared.getComments(forItemId: 27676266, page: 2) { success, comments, hasMore in
    guard success == true else { return }
    c.append(comments)
}

print("fetched comments: \(comments)")

Get a user

HackerNewsClient.shared.getUser(withUsername: "mattrighetti") { user in
    print("fetched user: \(user)")
}

GitHub

link
Stars: 1
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics