Skip to content

nhdang103/OpenGraph

 
 

Repository files navigation

A Swift wrapper for the Open Graph protocol (OGP)

Build Status Carthage compatible Platform
OpenGraph is a Swift wrapper for the OGP (Open Graph protocol). You can fetch OpenGraph,then you can access the attributes with subscript and the key provided by enum type.

OpenGraph.fetch(url) { og, error in
    print(og?[.title]) // => og:title of the web site
    print(og?[.type])  // => og:type of the web site
    print(og?[.image]) // => og:image of the web site
    print(og?[.url])   // => og:url of the web site
}

If you want to use Rx interface, use an extension below.

extension OpenGraph {
    static func rx_fetch(url: URL?) -> Observable<OpenGraph?> {
        return Observable.create { observer in
            guard let url = url else {
                observer.onCompleted()
                return Disposables.create()
            }
            
            OpenGraph.fetch(url: url) { og, err in
                if let og = og {
                    observer.onNext(og)
                }
                if let err = err {
                    observer.onError(err)
                }
                
                observer.onCompleted()
            }
            
            return Disposables.create()
        }
    }
}

Requirements

  • Xcode 9 / Swift 4.0 or 3.2 (If you use Xcode 8.x, you can use 1.0.2.)
  • iOS 8.0 or later
  • macOS 10.9 or later
  • tvOS 9.0 or later
  • watchOS 2.0 or later

If you use Swift 2.2 or 2.3, use older version of OpenGraph.

Installation

CocoaPods

Insert pod 'OpenGraph' to your Podfile and run pod install.

Carthage

Insert github "satoshi-takano/OpenGraph" to your Cartfile and run carthage update.

License

This project and library has been created by Satoshi Takano and is under the MIT License.

About

A Swift wrapper for the Open Graph protocol (OGP).

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 81.2%
  • Ruby 10.4%
  • HTML 6.4%
  • Objective-C 2.0%