An open API service indexing awesome lists of open source software.

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.

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