SwiftyOpenGraph - A swift library that retrieves structured open graph data from webpages.

Overview

SwiftyOpenGraph

GithubCI_Status LICENSE_BADGE Platform

Usage

Initialization

You use SwiftyOpenGraph by initializing OpenGraph, the root object of SwiftyOpenGraph. There are two initializers of OpenGraph:

HTML String

let graph = OpenGraph(html: htmlString)

URL

let graph = try await OpenGraph(url: "https://quintschaf.com/#/app/mykeyboard")

Both of these initializers are optional, only returning when the html contains at least the required OpenGraph properties.

Base Properties

Every valid open graph enabled webpage has four properties, which an OpenGraph object exposes as non-optional constants: title, type, image and url. It can also contain additionalImages, audios, videos, description, determiner, locale, alternateLocales and siteName. These are either optional constants of an OpenGraph object or they contain the default value as defined by the OpenGraph protocol.

Images, Audios, Videos and the Determiner are represented by OpenGraphImage, OpenGraphAudio, OpenGraphVideo and Determiner. All of them are structs that may contain additional data, e.g. the width of an image, represented by the "og:image:width" meta tag.

Example:

print(graph.title)  // "MyKeyboard"
print(graph.type)   // OpenGraphType.website
print(graph.image)  // OpenGraphImage(url: "...", width: ...)
print(graph.url)    // "https://quintschaf.com/#/app/mykeyboard"

print(graph.additionalImages)   // []
print(graph.audios)             // []
print(graph.videos)             // []
print(graph.description)        // Optional("The fully customizable Keyboard.")
print(graph.determiner)         // Determiner.blank
print(graph.locale)             // "en_US"
print(graph.alternateLocales)   // []
print(graph.siteName)           // nil

Types

The type ("og:type") is represented by the OpenGraphType enum, which has the following cases (as specified by the OpenGraph spec):

  • song(SongAttributes)
  • album(AlbumAttributes)
  • playlist(PlaylistAttributes)
  • radioStation(RadioStationAttributes)
  • video(VideoAttributes)
  • article(ArticleAttributes)
  • book(BookAttributes)
  • profile(ProfileAttributes)
  • website

All of these (with the exception of the default type website) have a struct as an associated value. These structs hold the values that are specific to the type. Due to their differences in properties, there are seperate cases for song, album, playlist and radioStation. Due to them having almost the same properties, there is only one video case for all video types. The VideoAttributes therefor contains a kind property that is an enumeration containing all the video types.

Example:

switch graph.type {
case .video(let attributes):
    print(attributes.king)          // VideoAttributes.SubKind.movie
    print(attributes.actors)        // []
    print(attributes.directors)     // []
    print(attributes.writers)       // []
    print(attributes.duration)      // Optional(200)
    print(attributes.releaseDate)   // Optional(Date(...))
    print(attributes.tags)          // ["some", "words", "as", "tags"]
    print(attributes.series)        // nil
default:
    break
}

Types

Installation

Swift Package Manager

SwiftyOpenGraph relies on Swift Package Manager and is installed by adding it as a dependency.

License

We have chosen to use the CC0 1.0 Universal license for SwiftyOpenGraph. The following short explanation has no legal implication whatsoever and does not override the license in any way: CC0 1.0 Universal license gives you the right to use or modify all of SwiftyOpenGraphs code in any (commercial or non-commercial) product without mentioning, licensing or other headaches of any kind.

You might also like...
Easy to use Spider (Radar) Chart library for iOS written in Swift.
Easy to use Spider (Radar) Chart library for iOS written in Swift.

DDSpiderChart Easy to use Spider (Radar) Chart library for iOS written in Swift. Requirements iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ Xcode

Line Chart library for iOS written in Swift
Line Chart library for iOS written in Swift

Swift LineChart Usage var lineChart = LineChart() lineChart.addLine([3, 4, 9, 11, 13, 15]) Features Super simple Highly customizable Auto scaling Touc

SwiftChart - A simple line and area charting library for iOS.
SwiftChart - A simple line and area charting library for iOS.

SwiftChart A simple line and area charting library for iOS. πŸ“ˆ Line and area charts 🌞 Multiple series πŸŒ’ Partially filled series 🏊 Works with signed

 SwiftCharts - Easy to use and highly customizable charts library for iOS
SwiftCharts - Easy to use and highly customizable charts library for iOS

SwiftCharts Easy to use and highly customizable charts library for iOS Features: Bars - plain, stacked, grouped, horizontal, vertical Scatter Lines (s

SwiftUICharts - A simple line and bar charting library that supports accessibility written using SwiftUI.
SwiftUICharts - A simple line and bar charting library that supports accessibility written using SwiftUI.

SwiftUICharts - A simple line and bar charting library that supports accessibility written using SwiftUI.

SwiftUI library to easily render diagrams given a tree of objects. Similar to ring chart, sunburst chart, multilevel pie chart.
SwiftUI library to easily render diagrams given a tree of objects. Similar to ring chart, sunburst chart, multilevel pie chart.

Swift Sunburst Diagram Sunburst diagram is a library written with SwiftUI to easily render diagrams given a tree of objects. Similar to ring chart, su

Elegant Line Graphs for iOS. (Charting library)

BEMSimpleLineGraph BEMSimpleLineGraph makes it easy to create and customize line graphs for iOS. BEMSimpleLineGraph is a charting library that makes i

iOS-based charting library for both line and bar graphs.
iOS-based charting library for both line and bar graphs.

JBChartView Introducing JBChartView - Jawbone's iOS-based charting library for both line and bar graphs. It is easy to set-up, and highly customizable

FSLineChart  A line chart library for iOS.
FSLineChart A line chart library for iOS.

FSLineChart A line chart library for iOS. Screenshots Installing FSLineChart Add the contents of the FSLineChart project to your directory or simply a

Releases(1.0.1)
Owner
Quintschaf
Five heads are better than one.
Quintschaf
A powerful πŸš€ Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚑ A powerful & easy to use chart library for Android ⚑ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Jan 5, 2023
Simple and intuitive iOS chart library. Contribution graph, clock chart, and bar chart.

TEAChart Simple and intuitive iOS chart library, for Pomotodo app. Contribution graph, clock chart, and bar chart. Supports Storyboard and is fully ac

柳东原 · Dongyuan Liu 1.2k Nov 29, 2022
An adaptive scrollable graph view for iOS to visualise simple discrete datasets. Written in Swift.

ScrollableGraphView Announcements 9-7-2017 - Version 4: Version 4 was released which adds multiple plots, dynamic reloading of values, more reference

Phillip 5.3k Jan 5, 2023
iOS/iPhone/iPad Chart, Graph. Event handling and animation supported.

#EChart A highly extendable, easy to use chart with event handling, animation supported. ##Test How To Use Download and run the EChartDemo project is

Scott Zhu 646 Dec 27, 2022
Simple iOS Application built using UIKit displaying the list of Cryptocurrencies and a detailed screen with a line graph.

CryptoViewer Simple iOS Application built using UIKit displaying the list of Cryptocurrencies and a detailed screen with a line graph. Home Screen: Di

null 0 Jun 14, 2022
Creates WordCloud type graph from a string or array of strings input.

CPTWordCloud Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation CPTWo

Chronic Stim 1 Jan 7, 2022
Meet cute and very flexibility library for iOS application for different data view in one circle diagram.

SMDiagramViewSwift Meet cute and very flexibility library for iOS application for different data view in one circle diagram. The opportunity of transf

VRG Soft 42 Sep 17, 2022
an iOS open source Radar Chart implementation

JYRadarChart an open source iOS Radar Chart implementation ##Screenshots Requirements Xcode 5 or higher iOS 5.0 or higher ARC CoreGraphics.framework D

Johnny Wu 416 Dec 31, 2022
Eat fit is a component for attractive data representation inspired by Google Fit

EatFit Check this article on our blog. Purpose Eat fit is a component for attractive data representation inspired by Google Fit. It is based on PageVi

Yalantis 657 Jan 5, 2023