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.
Ogge is available as a Swift Package:
.package(url: "https://github.com/phoqe/Ogge.git", .branch("master"))
You can use Ogge in multiple ways depending on the available data.
OGRepo
can fetch HTML from a URL and parse it into an OGObject
:
let url = URL(string: "https://example.com")!
let object = try await OGRepo.object(from: url)
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
}
})
OGParser
can parse HTML and parse it into an OGObject
:
let html = """
<meta property="og:title" content="The Rock">
<meta property="og:type" content="video.movie">
<meta property="og:url" content="https://www.imdb.com/title/tt0117500">
<meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg">
"""
let object = try OGParser.parse(html: html)
MIT