https://github.com/phoqe/ogge
Convenient and efficient Swift wrapper for the Open Graph Protocol.
https://github.com/phoqe/ogge
async await codable dom html meta ogp open-graph-protocol parser regex swift wrapper
Last synced: 6 months ago
JSON representation
Convenient and efficient Swift wrapper for the Open Graph Protocol.
- Host: GitHub
- URL: https://github.com/phoqe/ogge
- Owner: phoqe
- License: mit
- Created: 2021-11-11T21:57:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-18T07:57:46.000Z (over 4 years ago)
- Last Synced: 2025-01-23T05:14:15.648Z (over 1 year ago)
- Topics: async, await, codable, dom, html, meta, ogp, open-graph-protocol, parser, regex, swift, wrapper
- Language: Swift
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Ogge
Ogge is a convenient and efficient Swift wrapper for the Open Graph Protocol.
It was created in parallel with a newsreader app to fetch an image from an article.
## Installation
Ogge is available as a Swift Package:
```swift
.package(url: "https://github.com/phoqe/Ogge.git", .branch("master"))
```
## Usage
You can use Ogge in multiple ways depending on the available data.
### URL
[`OGRepo`](Sources/Ogge/OGRepo.swift) can fetch HTML from a URL and parse it into an [`OGObject`](Sources/Ogge/Models/OGObject.swift):
#### [`async/await`](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html)
```swift
let url = URL(string: "https://example.com")!
let object = try await OGRepo.object(from: url)
```
#### [`Result`](https://developer.apple.com/documentation/swift/result)
```swift
let url = URL(string: "https://example.com")!
OGRepo.object(from: url, completion: { result in
switch (result) {
case .failure(let error):
break
case .success(let object):
break
}
})
```
### HTML
[`OGParser`](Sources/Ogge/OGParser.swift) can parse HTML and parse it into an [`OGObject`](Sources/Ogge/Models/OGObject.swift):
```swift
let html = """
"""
let object = try OGParser.parse(html: html)
```
## License
MIT