├── .gitignore ├── .travis.yml ├── Cartfile.private ├── Cartfile.resolved ├── OpenGraph.podspec ├── OpenGraph.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── OpenGraph.xcscheme ├── Package.resolved ├── Package.swift ├── README.md ├── Sources └── OpenGraph │ ├── Extension │ ├── Data.swift │ ├── String.swift │ └── URLSession.swift │ ├── Info.plist │ ├── OpenGraph.h │ ├── OpenGraph.swift │ ├── OpenGraphMetadata.swift │ ├── OpenGraphParseError.swift │ ├── OpenGraphParser.swift │ └── OpenGraphResponseError.swift └── Tests ├── Info.plist ├── OpenGraphTests.swift └── Resources ├── empty_ogp.html ├── example3.com.html └── ogp.html /.gitignore: -------------------------------------------------------------------------------- 1 | ## OS X Finder 2 | .DS_Store 3 | 4 | ## Build generated 5 | build/ 6 | DerivedData 7 | 8 | ## Various settings 9 | *.pbxuser 10 | !default.pbxuser 11 | *.mode1v3 12 | !default.mode1v3 13 | *.mode2v3 14 | !default.mode2v3 15 | *.perspectivev3 16 | !default.perspectivev3 17 | xcuserdata 18 | 19 | ## Other 20 | *.xccheckout 21 | *.moved-aside 22 | *.xcuserstate 23 | *.xcscmblueprint 24 | *.xcworkspace 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # Swift Package Manager 31 | .build/ 32 | 33 | # Carthage 34 | Carthage 35 | 36 | # CocoaPods 37 | Pods/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode11 3 | 4 | xcode_project: OpenGraph.xcodeproj 5 | xcode_scheme: OpenGraph 6 | 7 | before_install: 8 | - carthage bootstrap 9 | 10 | script: 11 | - xcodebuild build-for-testing test-without-building -project OpenGraph.xcodeproj -scheme OpenGraph -configuration Release ENABLE_TESTABILITY=YES 12 | -------------------------------------------------------------------------------- /Cartfile.private: -------------------------------------------------------------------------------- 1 | github "AliSoftware/OHHTTPStubs" "8.0.0" -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "AliSoftware/OHHTTPStubs" "8.0.0" 2 | -------------------------------------------------------------------------------- /OpenGraph.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "OpenGraph" 3 | s.version = "1.6.0" 4 | s.summary = "A Swift wrapper for the Open Graph protocol." 5 | s.homepage = "https://github.com/satoshi-takano/OpenGraph" 6 | s.license = { 7 | :type => "MIT", 8 | :text => <<-LICENSE 9 | The MIT License (MIT) 10 | Copyright (c) Satoshi Takano 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | LICENSE 15 | } 16 | s.author = "satoshi-takano" 17 | s.description = <<-DESC 18 | OpenGraph is a Swift wrapper for the Open Graph protocol. You can fetch OpenGraph,then you can access the attributes with subscript and the key provided by enum type. 19 | DESC 20 | 21 | s.swift_versions = ['5.0'] 22 | s.ios.deployment_target = "8.0" 23 | s.source = { :git => "https://github.com/satoshi-takano/OpenGraph.git", :tag => s.version.to_s } 24 | s.source_files = "Sources/**/*.{swift,h,m}" 25 | s.osx.deployment_target = "10.15" 26 | s.ios.deployment_target = "8.0" 27 | s.tvos.deployment_target = "9.0" 28 | s.watchos.deployment_target = "2.0" 29 | end 30 | -------------------------------------------------------------------------------- /OpenGraph.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0A78BBD027972EB30049F53B /* URLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A78BBCF27972EB30049F53B /* URLSession.swift */; }; 11 | 4204E998275B260700AB31CC /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4204E997275B260700AB31CC /* Data.swift */; }; 12 | 4204EA19275B76AE00AB31CC /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4204EA18275B76AE00AB31CC /* String.swift */; }; 13 | 7B24FB191D3B2583005275B0 /* OpenGraph.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B24FB181D3B2583005275B0 /* OpenGraph.h */; settings = {ATTRIBUTES = (Public, ); }; }; 14 | 7B24FB201D3B2583005275B0 /* OpenGraph.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B24FB151D3B2583005275B0 /* OpenGraph.framework */; }; 15 | 7B24FB3E1D3B26C4005275B0 /* OpenGraphTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB3D1D3B26C4005275B0 /* OpenGraphTests.swift */; }; 16 | 7B24FB461D3B27E5005275B0 /* OpenGraph.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB411D3B27E5005275B0 /* OpenGraph.swift */; }; 17 | 7B24FB471D3B27E5005275B0 /* OpenGraphMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB421D3B27E5005275B0 /* OpenGraphMetadata.swift */; }; 18 | 7B24FB481D3B27E5005275B0 /* OpenGraphParseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB431D3B27E5005275B0 /* OpenGraphParseError.swift */; }; 19 | 7B24FB491D3B27E5005275B0 /* OpenGraphParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB441D3B27E5005275B0 /* OpenGraphParser.swift */; }; 20 | 7B24FB4A1D3B27E5005275B0 /* OpenGraphResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B24FB451D3B27E5005275B0 /* OpenGraphResponseError.swift */; }; 21 | F75574302C2B0E0E002416DD /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = F755742F2C2B0E0E002416DD /* OHHTTPStubs */; }; 22 | F75574322C2B0E0E002416DD /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F75574312C2B0E0E002416DD /* OHHTTPStubsSwift */; }; 23 | F75574372C2B0E8C002416DD /* empty_ogp.html in Resources */ = {isa = PBXBuildFile; fileRef = F75574332C2B0E8C002416DD /* empty_ogp.html */; }; 24 | F75574382C2B0E8C002416DD /* example3.com.html in Resources */ = {isa = PBXBuildFile; fileRef = F75574342C2B0E8C002416DD /* example3.com.html */; }; 25 | F75574392C2B0E8C002416DD /* ogp.html in Resources */ = {isa = PBXBuildFile; fileRef = F75574352C2B0E8C002416DD /* ogp.html */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | 7B24FB211D3B2583005275B0 /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 7B24FB0C1D3B2583005275B0 /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 7B24FB141D3B2583005275B0; 34 | remoteInfo = OpenGraph; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 0A78BBCF27972EB30049F53B /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = ""; }; 40 | 4204E997275B260700AB31CC /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 41 | 4204EA18275B76AE00AB31CC /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; 42 | 7B24FB151D3B2583005275B0 /* OpenGraph.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OpenGraph.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 7B24FB181D3B2583005275B0 /* OpenGraph.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpenGraph.h; sourceTree = ""; }; 44 | 7B24FB1A1D3B2583005275B0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 7B24FB1F1D3B2583005275B0 /* OpenGraphTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OpenGraphTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 7B24FB261D3B2583005275B0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 7B24FB3D1D3B26C4005275B0 /* OpenGraphTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraphTests.swift; sourceTree = ""; }; 48 | 7B24FB411D3B27E5005275B0 /* OpenGraph.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraph.swift; sourceTree = ""; }; 49 | 7B24FB421D3B27E5005275B0 /* OpenGraphMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraphMetadata.swift; sourceTree = ""; }; 50 | 7B24FB431D3B27E5005275B0 /* OpenGraphParseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraphParseError.swift; sourceTree = ""; }; 51 | 7B24FB441D3B27E5005275B0 /* OpenGraphParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraphParser.swift; sourceTree = ""; }; 52 | 7B24FB451D3B27E5005275B0 /* OpenGraphResponseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGraphResponseError.swift; sourceTree = ""; }; 53 | F75574332C2B0E8C002416DD /* empty_ogp.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = empty_ogp.html; sourceTree = ""; }; 54 | F75574342C2B0E8C002416DD /* example3.com.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = example3.com.html; sourceTree = ""; }; 55 | F75574352C2B0E8C002416DD /* ogp.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ogp.html; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 7B24FB111D3B2583005275B0 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | 7B24FB1C1D3B2583005275B0 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | 7B24FB201D3B2583005275B0 /* OpenGraph.framework in Frameworks */, 71 | F75574322C2B0E0E002416DD /* OHHTTPStubsSwift in Frameworks */, 72 | F75574302C2B0E0E002416DD /* OHHTTPStubs in Frameworks */, 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | /* End PBXFrameworksBuildPhase section */ 77 | 78 | /* Begin PBXGroup section */ 79 | 4204E996275B25F300AB31CC /* Extension */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 4204E997275B260700AB31CC /* Data.swift */, 83 | 4204EA18275B76AE00AB31CC /* String.swift */, 84 | 0A78BBCF27972EB30049F53B /* URLSession.swift */, 85 | ); 86 | path = Extension; 87 | sourceTree = ""; 88 | }; 89 | 7B24FB0B1D3B2583005275B0 = { 90 | isa = PBXGroup; 91 | children = ( 92 | F72F549525AC0738006EE8CF /* Sources */, 93 | 7B24FB231D3B2583005275B0 /* Tests */, 94 | 7B24FB161D3B2583005275B0 /* Products */, 95 | ); 96 | sourceTree = ""; 97 | }; 98 | 7B24FB161D3B2583005275B0 /* Products */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 7B24FB151D3B2583005275B0 /* OpenGraph.framework */, 102 | 7B24FB1F1D3B2583005275B0 /* OpenGraphTests.xctest */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | 7B24FB171D3B2583005275B0 /* OpenGraph */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 7B24FB181D3B2583005275B0 /* OpenGraph.h */, 111 | 7B24FB411D3B27E5005275B0 /* OpenGraph.swift */, 112 | 7B24FB421D3B27E5005275B0 /* OpenGraphMetadata.swift */, 113 | 7B24FB431D3B27E5005275B0 /* OpenGraphParseError.swift */, 114 | 7B24FB441D3B27E5005275B0 /* OpenGraphParser.swift */, 115 | 7B24FB451D3B27E5005275B0 /* OpenGraphResponseError.swift */, 116 | 4204E996275B25F300AB31CC /* Extension */, 117 | 7B24FB1A1D3B2583005275B0 /* Info.plist */, 118 | ); 119 | path = OpenGraph; 120 | sourceTree = ""; 121 | }; 122 | 7B24FB231D3B2583005275B0 /* Tests */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | F75574362C2B0E8C002416DD /* Resources */, 126 | 7B24FB261D3B2583005275B0 /* Info.plist */, 127 | 7B24FB3D1D3B26C4005275B0 /* OpenGraphTests.swift */, 128 | ); 129 | path = Tests; 130 | sourceTree = ""; 131 | }; 132 | F72F549525AC0738006EE8CF /* Sources */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 7B24FB171D3B2583005275B0 /* OpenGraph */, 136 | ); 137 | path = Sources; 138 | sourceTree = ""; 139 | }; 140 | F75574362C2B0E8C002416DD /* Resources */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | F75574332C2B0E8C002416DD /* empty_ogp.html */, 144 | F75574342C2B0E8C002416DD /* example3.com.html */, 145 | F75574352C2B0E8C002416DD /* ogp.html */, 146 | ); 147 | path = Resources; 148 | sourceTree = ""; 149 | }; 150 | /* End PBXGroup section */ 151 | 152 | /* Begin PBXHeadersBuildPhase section */ 153 | 7B24FB121D3B2583005275B0 /* Headers */ = { 154 | isa = PBXHeadersBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 7B24FB191D3B2583005275B0 /* OpenGraph.h in Headers */, 158 | ); 159 | runOnlyForDeploymentPostprocessing = 0; 160 | }; 161 | /* End PBXHeadersBuildPhase section */ 162 | 163 | /* Begin PBXNativeTarget section */ 164 | 7B24FB141D3B2583005275B0 /* OpenGraph */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = 7B24FB291D3B2583005275B0 /* Build configuration list for PBXNativeTarget "OpenGraph" */; 167 | buildPhases = ( 168 | 7B24FB101D3B2583005275B0 /* Sources */, 169 | 7B24FB111D3B2583005275B0 /* Frameworks */, 170 | 7B24FB121D3B2583005275B0 /* Headers */, 171 | 7B24FB131D3B2583005275B0 /* Resources */, 172 | ); 173 | buildRules = ( 174 | ); 175 | dependencies = ( 176 | ); 177 | name = OpenGraph; 178 | productName = OpenGraph; 179 | productReference = 7B24FB151D3B2583005275B0 /* OpenGraph.framework */; 180 | productType = "com.apple.product-type.framework"; 181 | }; 182 | 7B24FB1E1D3B2583005275B0 /* OpenGraphTests */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = 7B24FB2C1D3B2583005275B0 /* Build configuration list for PBXNativeTarget "OpenGraphTests" */; 185 | buildPhases = ( 186 | 7B24FB1B1D3B2583005275B0 /* Sources */, 187 | 7B24FB1C1D3B2583005275B0 /* Frameworks */, 188 | 7B24FB1D1D3B2583005275B0 /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | 7B24FB221D3B2583005275B0 /* PBXTargetDependency */, 194 | ); 195 | name = OpenGraphTests; 196 | packageProductDependencies = ( 197 | F755742F2C2B0E0E002416DD /* OHHTTPStubs */, 198 | F75574312C2B0E0E002416DD /* OHHTTPStubsSwift */, 199 | ); 200 | productName = OpenGraphTests; 201 | productReference = 7B24FB1F1D3B2583005275B0 /* OpenGraphTests.xctest */; 202 | productType = "com.apple.product-type.bundle.unit-test"; 203 | }; 204 | /* End PBXNativeTarget section */ 205 | 206 | /* Begin PBXProject section */ 207 | 7B24FB0C1D3B2583005275B0 /* Project object */ = { 208 | isa = PBXProject; 209 | attributes = { 210 | LastSwiftUpdateCheck = 0730; 211 | LastUpgradeCheck = 0900; 212 | ORGANIZATIONNAME = "Satoshi Takano"; 213 | TargetAttributes = { 214 | 7B24FB141D3B2583005275B0 = { 215 | CreatedOnToolsVersion = 7.3; 216 | LastSwiftMigration = 0800; 217 | ProvisioningStyle = Automatic; 218 | }; 219 | 7B24FB1E1D3B2583005275B0 = { 220 | CreatedOnToolsVersion = 7.3; 221 | LastSwiftMigration = 0800; 222 | }; 223 | }; 224 | }; 225 | buildConfigurationList = 7B24FB0F1D3B2583005275B0 /* Build configuration list for PBXProject "OpenGraph" */; 226 | compatibilityVersion = "Xcode 3.2"; 227 | developmentRegion = English; 228 | hasScannedForEncodings = 0; 229 | knownRegions = ( 230 | English, 231 | en, 232 | ); 233 | mainGroup = 7B24FB0B1D3B2583005275B0; 234 | packageReferences = ( 235 | F755742E2C2B0E0E002416DD /* XCRemoteSwiftPackageReference "OHHTTPStubs" */, 236 | ); 237 | productRefGroup = 7B24FB161D3B2583005275B0 /* Products */; 238 | projectDirPath = ""; 239 | projectRoot = ""; 240 | targets = ( 241 | 7B24FB141D3B2583005275B0 /* OpenGraph */, 242 | 7B24FB1E1D3B2583005275B0 /* OpenGraphTests */, 243 | ); 244 | }; 245 | /* End PBXProject section */ 246 | 247 | /* Begin PBXResourcesBuildPhase section */ 248 | 7B24FB131D3B2583005275B0 /* Resources */ = { 249 | isa = PBXResourcesBuildPhase; 250 | buildActionMask = 2147483647; 251 | files = ( 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | 7B24FB1D1D3B2583005275B0 /* Resources */ = { 256 | isa = PBXResourcesBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | F75574382C2B0E8C002416DD /* example3.com.html in Resources */, 260 | F75574372C2B0E8C002416DD /* empty_ogp.html in Resources */, 261 | F75574392C2B0E8C002416DD /* ogp.html in Resources */, 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | }; 265 | /* End PBXResourcesBuildPhase section */ 266 | 267 | /* Begin PBXSourcesBuildPhase section */ 268 | 7B24FB101D3B2583005275B0 /* Sources */ = { 269 | isa = PBXSourcesBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | 7B24FB461D3B27E5005275B0 /* OpenGraph.swift in Sources */, 273 | 4204E998275B260700AB31CC /* Data.swift in Sources */, 274 | 0A78BBD027972EB30049F53B /* URLSession.swift in Sources */, 275 | 7B24FB4A1D3B27E5005275B0 /* OpenGraphResponseError.swift in Sources */, 276 | 7B24FB491D3B27E5005275B0 /* OpenGraphParser.swift in Sources */, 277 | 4204EA19275B76AE00AB31CC /* String.swift in Sources */, 278 | 7B24FB481D3B27E5005275B0 /* OpenGraphParseError.swift in Sources */, 279 | 7B24FB471D3B27E5005275B0 /* OpenGraphMetadata.swift in Sources */, 280 | ); 281 | runOnlyForDeploymentPostprocessing = 0; 282 | }; 283 | 7B24FB1B1D3B2583005275B0 /* Sources */ = { 284 | isa = PBXSourcesBuildPhase; 285 | buildActionMask = 2147483647; 286 | files = ( 287 | 7B24FB3E1D3B26C4005275B0 /* OpenGraphTests.swift in Sources */, 288 | ); 289 | runOnlyForDeploymentPostprocessing = 0; 290 | }; 291 | /* End PBXSourcesBuildPhase section */ 292 | 293 | /* Begin PBXTargetDependency section */ 294 | 7B24FB221D3B2583005275B0 /* PBXTargetDependency */ = { 295 | isa = PBXTargetDependency; 296 | target = 7B24FB141D3B2583005275B0 /* OpenGraph */; 297 | targetProxy = 7B24FB211D3B2583005275B0 /* PBXContainerItemProxy */; 298 | }; 299 | /* End PBXTargetDependency section */ 300 | 301 | /* Begin XCBuildConfiguration section */ 302 | 7B24FB271D3B2583005275B0 /* Debug */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ALWAYS_SEARCH_USER_PATHS = NO; 306 | CLANG_ANALYZER_NONNULL = YES; 307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 308 | CLANG_CXX_LIBRARY = "libc++"; 309 | CLANG_ENABLE_MODULES = YES; 310 | CLANG_ENABLE_OBJC_ARC = YES; 311 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 312 | CLANG_WARN_BOOL_CONVERSION = YES; 313 | CLANG_WARN_COMMA = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 316 | CLANG_WARN_EMPTY_BODY = YES; 317 | CLANG_WARN_ENUM_CONVERSION = YES; 318 | CLANG_WARN_INFINITE_RECURSION = YES; 319 | CLANG_WARN_INT_CONVERSION = YES; 320 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 321 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 322 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 323 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 324 | CLANG_WARN_STRICT_PROTOTYPES = YES; 325 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 326 | CLANG_WARN_UNREACHABLE_CODE = YES; 327 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 328 | CODE_SIGN_IDENTITY = "-"; 329 | COPY_PHASE_STRIP = NO; 330 | CURRENT_PROJECT_VERSION = 1; 331 | DEBUG_INFORMATION_FORMAT = dwarf; 332 | ENABLE_STRICT_OBJC_MSGSEND = YES; 333 | ENABLE_TESTABILITY = YES; 334 | GCC_C_LANGUAGE_STANDARD = gnu99; 335 | GCC_DYNAMIC_NO_PIC = NO; 336 | GCC_NO_COMMON_BLOCKS = YES; 337 | GCC_OPTIMIZATION_LEVEL = 0; 338 | GCC_PREPROCESSOR_DEFINITIONS = ( 339 | "DEBUG=1", 340 | "$(inherited)", 341 | ); 342 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 343 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 344 | GCC_WARN_UNDECLARED_SELECTOR = YES; 345 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 346 | GCC_WARN_UNUSED_FUNCTION = YES; 347 | GCC_WARN_UNUSED_VARIABLE = YES; 348 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 349 | MACOSX_DEPLOYMENT_TARGET = 10.15; 350 | MTL_ENABLE_DEBUG_INFO = YES; 351 | ONLY_ACTIVE_ARCH = YES; 352 | SDKROOT = macosx; 353 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 354 | SWIFT_VERSION = 5.0; 355 | TVOS_DEPLOYMENT_TARGET = 9.0; 356 | VERSIONING_SYSTEM = "apple-generic"; 357 | VERSION_INFO_PREFIX = ""; 358 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 359 | }; 360 | name = Debug; 361 | }; 362 | 7B24FB281D3B2583005275B0 /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_ANALYZER_NONNULL = YES; 367 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 368 | CLANG_CXX_LIBRARY = "libc++"; 369 | CLANG_ENABLE_MODULES = YES; 370 | CLANG_ENABLE_OBJC_ARC = YES; 371 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 372 | CLANG_WARN_BOOL_CONVERSION = YES; 373 | CLANG_WARN_COMMA = YES; 374 | CLANG_WARN_CONSTANT_CONVERSION = YES; 375 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 376 | CLANG_WARN_EMPTY_BODY = YES; 377 | CLANG_WARN_ENUM_CONVERSION = YES; 378 | CLANG_WARN_INFINITE_RECURSION = YES; 379 | CLANG_WARN_INT_CONVERSION = YES; 380 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 381 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 382 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 383 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 384 | CLANG_WARN_STRICT_PROTOTYPES = YES; 385 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 386 | CLANG_WARN_UNREACHABLE_CODE = YES; 387 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 388 | CODE_SIGN_IDENTITY = "-"; 389 | COPY_PHASE_STRIP = NO; 390 | CURRENT_PROJECT_VERSION = 1; 391 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 392 | ENABLE_NS_ASSERTIONS = NO; 393 | ENABLE_STRICT_OBJC_MSGSEND = YES; 394 | GCC_C_LANGUAGE_STANDARD = gnu99; 395 | GCC_NO_COMMON_BLOCKS = YES; 396 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 397 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 398 | GCC_WARN_UNDECLARED_SELECTOR = YES; 399 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 400 | GCC_WARN_UNUSED_FUNCTION = YES; 401 | GCC_WARN_UNUSED_VARIABLE = YES; 402 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 403 | MACOSX_DEPLOYMENT_TARGET = 10.15; 404 | MTL_ENABLE_DEBUG_INFO = NO; 405 | SDKROOT = macosx; 406 | SWIFT_COMPILATION_MODE = wholemodule; 407 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 408 | SWIFT_VERSION = 5.0; 409 | TVOS_DEPLOYMENT_TARGET = 9.0; 410 | VERSIONING_SYSTEM = "apple-generic"; 411 | VERSION_INFO_PREFIX = ""; 412 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 413 | }; 414 | name = Release; 415 | }; 416 | 7B24FB2A1D3B2583005275B0 /* Debug */ = { 417 | isa = XCBuildConfiguration; 418 | buildSettings = { 419 | CLANG_ENABLE_MODULES = YES; 420 | CODE_SIGN_IDENTITY = ""; 421 | COMBINE_HIDPI_IMAGES = YES; 422 | DEFINES_MODULE = YES; 423 | DYLIB_COMPATIBILITY_VERSION = 1; 424 | DYLIB_CURRENT_VERSION = 1; 425 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 426 | FRAMEWORK_SEARCH_PATHS = ( 427 | "$(inherited)", 428 | "$(PROJECT_DIR)/Carthage/Build/iOS", 429 | ); 430 | FRAMEWORK_VERSION = A; 431 | INFOPLIST_FILE = Sources/OpenGraph/Info.plist; 432 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 433 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 434 | LD_RUNPATH_SEARCH_PATHS = ( 435 | "$(inherited)", 436 | "@executable_path/../Frameworks", 437 | "@loader_path/Frameworks", 438 | ); 439 | MACOSX_DEPLOYMENT_TARGET = 10.15; 440 | PRODUCT_BUNDLE_IDENTIFIER = "net.cloud-dj.OpenGraph"; 441 | PRODUCT_NAME = "$(TARGET_NAME)"; 442 | SKIP_INSTALL = YES; 443 | SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; 444 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 445 | SWIFT_VERSION = 5.0; 446 | TVOS_DEPLOYMENT_TARGET = 9.0; 447 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 448 | }; 449 | name = Debug; 450 | }; 451 | 7B24FB2B1D3B2583005275B0 /* Release */ = { 452 | isa = XCBuildConfiguration; 453 | buildSettings = { 454 | CLANG_ENABLE_MODULES = YES; 455 | CODE_SIGN_IDENTITY = ""; 456 | COMBINE_HIDPI_IMAGES = YES; 457 | DEFINES_MODULE = YES; 458 | DYLIB_COMPATIBILITY_VERSION = 1; 459 | DYLIB_CURRENT_VERSION = 1; 460 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 461 | FRAMEWORK_SEARCH_PATHS = ( 462 | "$(inherited)", 463 | "$(PROJECT_DIR)/Carthage/Build/iOS", 464 | ); 465 | FRAMEWORK_VERSION = A; 466 | INFOPLIST_FILE = Sources/OpenGraph/Info.plist; 467 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 468 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 469 | LD_RUNPATH_SEARCH_PATHS = ( 470 | "$(inherited)", 471 | "@executable_path/../Frameworks", 472 | "@loader_path/Frameworks", 473 | ); 474 | MACOSX_DEPLOYMENT_TARGET = 10.15; 475 | PRODUCT_BUNDLE_IDENTIFIER = "net.cloud-dj.OpenGraph"; 476 | PRODUCT_NAME = "$(TARGET_NAME)"; 477 | SKIP_INSTALL = YES; 478 | SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; 479 | SWIFT_VERSION = 5.0; 480 | TVOS_DEPLOYMENT_TARGET = 9.0; 481 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 482 | }; 483 | name = Release; 484 | }; 485 | 7B24FB2D1D3B2583005275B0 /* Debug */ = { 486 | isa = XCBuildConfiguration; 487 | buildSettings = { 488 | CLANG_ENABLE_MODULES = YES; 489 | COMBINE_HIDPI_IMAGES = YES; 490 | FRAMEWORK_SEARCH_PATHS = ( 491 | "$(inherited)", 492 | "$(PROJECT_DIR)/Carthage/Build/Mac", 493 | "$(PROJECT_DIR)/Carthage/Build/iOS", 494 | ); 495 | INFOPLIST_FILE = Tests/Info.plist; 496 | LD_RUNPATH_SEARCH_PATHS = ( 497 | "$(inherited)", 498 | "@executable_path/../Frameworks", 499 | "@loader_path/../Frameworks", 500 | ); 501 | PRODUCT_BUNDLE_IDENTIFIER = "net.cloud-dj.OpenGraphTests"; 502 | PRODUCT_NAME = "$(TARGET_NAME)"; 503 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 504 | SWIFT_VERSION = 5.0; 505 | }; 506 | name = Debug; 507 | }; 508 | 7B24FB2E1D3B2583005275B0 /* Release */ = { 509 | isa = XCBuildConfiguration; 510 | buildSettings = { 511 | CLANG_ENABLE_MODULES = YES; 512 | COMBINE_HIDPI_IMAGES = YES; 513 | FRAMEWORK_SEARCH_PATHS = ( 514 | "$(inherited)", 515 | "$(PROJECT_DIR)/Carthage/Build/Mac", 516 | "$(PROJECT_DIR)/Carthage/Build/iOS", 517 | ); 518 | INFOPLIST_FILE = Tests/Info.plist; 519 | LD_RUNPATH_SEARCH_PATHS = ( 520 | "$(inherited)", 521 | "@executable_path/../Frameworks", 522 | "@loader_path/../Frameworks", 523 | ); 524 | PRODUCT_BUNDLE_IDENTIFIER = "net.cloud-dj.OpenGraphTests"; 525 | PRODUCT_NAME = "$(TARGET_NAME)"; 526 | SWIFT_VERSION = 5.0; 527 | }; 528 | name = Release; 529 | }; 530 | /* End XCBuildConfiguration section */ 531 | 532 | /* Begin XCConfigurationList section */ 533 | 7B24FB0F1D3B2583005275B0 /* Build configuration list for PBXProject "OpenGraph" */ = { 534 | isa = XCConfigurationList; 535 | buildConfigurations = ( 536 | 7B24FB271D3B2583005275B0 /* Debug */, 537 | 7B24FB281D3B2583005275B0 /* Release */, 538 | ); 539 | defaultConfigurationIsVisible = 0; 540 | defaultConfigurationName = Release; 541 | }; 542 | 7B24FB291D3B2583005275B0 /* Build configuration list for PBXNativeTarget "OpenGraph" */ = { 543 | isa = XCConfigurationList; 544 | buildConfigurations = ( 545 | 7B24FB2A1D3B2583005275B0 /* Debug */, 546 | 7B24FB2B1D3B2583005275B0 /* Release */, 547 | ); 548 | defaultConfigurationIsVisible = 0; 549 | defaultConfigurationName = Release; 550 | }; 551 | 7B24FB2C1D3B2583005275B0 /* Build configuration list for PBXNativeTarget "OpenGraphTests" */ = { 552 | isa = XCConfigurationList; 553 | buildConfigurations = ( 554 | 7B24FB2D1D3B2583005275B0 /* Debug */, 555 | 7B24FB2E1D3B2583005275B0 /* Release */, 556 | ); 557 | defaultConfigurationIsVisible = 0; 558 | defaultConfigurationName = Release; 559 | }; 560 | /* End XCConfigurationList section */ 561 | 562 | /* Begin XCRemoteSwiftPackageReference section */ 563 | F755742E2C2B0E0E002416DD /* XCRemoteSwiftPackageReference "OHHTTPStubs" */ = { 564 | isa = XCRemoteSwiftPackageReference; 565 | repositoryURL = "https://github.com/AliSoftware/OHHTTPStubs.git"; 566 | requirement = { 567 | kind = upToNextMajorVersion; 568 | minimumVersion = 9.0.0; 569 | }; 570 | }; 571 | /* End XCRemoteSwiftPackageReference section */ 572 | 573 | /* Begin XCSwiftPackageProductDependency section */ 574 | F755742F2C2B0E0E002416DD /* OHHTTPStubs */ = { 575 | isa = XCSwiftPackageProductDependency; 576 | package = F755742E2C2B0E0E002416DD /* XCRemoteSwiftPackageReference "OHHTTPStubs" */; 577 | productName = OHHTTPStubs; 578 | }; 579 | F75574312C2B0E0E002416DD /* OHHTTPStubsSwift */ = { 580 | isa = XCSwiftPackageProductDependency; 581 | package = F755742E2C2B0E0E002416DD /* XCRemoteSwiftPackageReference "OHHTTPStubs" */; 582 | productName = OHHTTPStubsSwift; 583 | }; 584 | /* End XCSwiftPackageProductDependency section */ 585 | }; 586 | rootObject = 7B24FB0C1D3B2583005275B0 /* Project object */; 587 | } 588 | -------------------------------------------------------------------------------- /OpenGraph.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OpenGraph.xcodeproj/xcshareddata/xcschemes/OpenGraph.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "OHHTTPStubs", 6 | "repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs", 7 | "state": { 8 | "branch": null, 9 | "revision": "12f19662426d0434d6c330c6974d53e2eb10ecd9", 10 | "version": "9.1.0" 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "OpenGraph", 7 | platforms: [ 8 | .macOS(.v10_15), .iOS(.v13), .tvOS(.v9), .watchOS(.v2) 9 | ], 10 | products: [ 11 | .library(name: "OpenGraph", targets: ["OpenGraph"]), 12 | ], 13 | dependencies: [ 14 | .package(url: "https://github.com/AliSoftware/OHHTTPStubs", .upToNextMajor(from: "9.0.0")), 15 | ], 16 | targets: [ 17 | .target( 18 | name: "OpenGraph", 19 | path: "Sources/OpenGraph", 20 | exclude: ["Info.plist"] 21 | ), 22 | .testTarget( 23 | name: "OpenGraphTests", 24 | dependencies: [ 25 | "OpenGraph", 26 | .product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs") 27 | ], 28 | path: "Tests", 29 | resources: [.process("Resources")] 30 | ), 31 | ], 32 | swiftLanguageVersions: [.v5] 33 | ) 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Swift wrapper for Open Graph protocol (OGP) 2 | [![Build Status](https://travis-ci.org/satoshi-takano/OpenGraph.svg?branch=feature%2Fci)](https://travis-ci.org/satoshi-takano/OpenGraph) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://cocoapod-badges.herokuapp.com/p/OpenGraph/badge.png)](http://cocoadocs.org/docsets/OpenGraph) 3 | OpenGraph is a Swift wrapper for OGP ([Open Graph protocol](http://ogp.me/)). 4 | You can fetch OpenGraph and get access to the attributes using subscript and enum cases as follows. 5 | ```swift 6 | OpenGraph.fetch(url: url) { result in 7 | switch result { 8 | case .success(let og): 9 | print(og[.title]) // => og:title of the web site 10 | print(og[.type]) // => og:type of the web site 11 | print(og[.image]) // => og:image of the web site 12 | print(og[.url]) // => og:url of the web site 13 | case .failure(let error): 14 | print(error) 15 | } 16 | } 17 | ``` 18 | 19 | For macOS 10.15, iOS 13, watchOS 6, tvOS 13, and above, you can use the async/await syntax: 20 | 21 | ```swift 22 | do { 23 | let og = try await OpenGraph.fetch(url: url) 24 | print(og[.title]) // => og:title of the web site 25 | print(og[.type]) // => og:type of the web site 26 | print(og[.image]) // => og:image of the web site 27 | print(og[.url]) // => og:url of the web site 28 | } catch { 29 | print(error) 30 | } 31 | ``` 32 | 33 | All metadata are defined [here](https://github.com/satoshi-takano/OpenGraph/blob/main/Sources/OpenGraph/OpenGraphMetadata.swift). 34 | This library doesn't provide any platform specific views to display OGP data for high portability. 35 | 36 | Furthermore, please copy the extension below to your own project if you want to use this library with the Rx interface. 37 | 38 | ```swift 39 | extension Reactive where Base: OpenGraph { 40 | static func fetch(url: URL?) -> Observable { 41 | return Observable.create { observer in 42 | guard let url = url else { 43 | observer.onCompleted() 44 | return Disposables.create() 45 | } 46 | 47 | OpenGraph.fetch(url: url) { result in 48 | switch result { 49 | case .success(let og): 50 | observer.onNext(og) 51 | case .failure(let error): 52 | observer.onError(error) 53 | } 54 | observer.onCompleted() 55 | } 56 | 57 | return Disposables.create() 58 | } 59 | } 60 | } 61 | ``` 62 | 63 | ## Requirements 64 | - Xcode 11.x / Swift 5.x (If you use Xcode 10.x, you can use [1.1.0](https://github.com/satoshi-takano/OpenGraph/releases/tag/1.1.0).) 65 | - iOS 10.0 or later 66 | - macOS 10.9 or later 67 | - tvOS 9.0 or later 68 | - watchOS 2.0 or later 69 | 70 | If you use Swift 2.2 or 2.3, use [older version of OpenGraph](https://github.com/satoshi-takano/OpenGraph/releases). 71 | 72 | ## Installation 73 | ### CocoaPods 74 | Insert `pod 'OpenGraph'` to your Podfile and run `pod install`. 75 | 76 | ### Carthage 77 | Insert `github "satoshi-takano/OpenGraph"` to your Cartfile and run `carthage update`. 78 | 79 | ## How to handle redirections 80 | In most cases, the OpenGraph can handle server-side redirections automatically. But some web pages provoke redirections on their front-end JavaScript. 81 | You might be able to handle these kind of redirections by changing the User-Agent as follows. 82 | https://github.com/satoshi-takano/OpenGraph/issues/43 83 | 84 | ## License 85 | This library is under the MIT License. 86 | -------------------------------------------------------------------------------- /Sources/OpenGraph/Extension/Data.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Data.swift 3 | // OpenGraph 4 | // 5 | // Created by p-x9 on 2021/12/04. 6 | // Copyright © 2021 Satoshi Takano. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 12 | extension Data { 13 | var stringEncoding: String.Encoding? { 14 | #if os(Linux) 15 | return nil 16 | #else 17 | var nsString: NSString? 18 | guard case let rawValue = NSString.stringEncoding(for: self, encodingOptions: nil, convertedString: &nsString, usedLossyConversion: nil), rawValue != 0 else { return nil } 19 | return String.Encoding(rawValue: rawValue) 20 | #endif 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/OpenGraph/Extension/String.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String.swift 3 | // OpenGraph 4 | // 5 | // Created by p-x9 on 2021/12/04. 6 | // Copyright © 2021 Satoshi Takano. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension String { 12 | init?(data: Data, textEncodingName: String? = nil, `default`: String.Encoding = .utf8) { 13 | let encoding: String.Encoding = { 14 | if let textEncodingName = textEncodingName { 15 | let cfe = CFStringConvertIANACharSetNameToEncoding(textEncodingName as CFString) 16 | if cfe != kCFStringEncodingInvalidId { 17 | let se = CFStringConvertEncodingToNSStringEncoding(cfe) 18 | return String.Encoding(rawValue: se) 19 | } 20 | } 21 | return data.stringEncoding ?? `default` 22 | }() 23 | 24 | self.init(data: data, encoding: encoding) 25 | } 26 | 27 | //Retreived from: https://stackoverflow.com/a/30141700 28 | /// Returns a new string made by replacing in the `String` 29 | /// all HTML character entity references with the corresponding 30 | /// character. 31 | var stringByDecodingHTMLEntities : String { 32 | // Mapping from XML/HTML character entity reference to character 33 | // From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 34 | let characterEntities : [ Substring : Character ] = [ 35 | // XML predefined entities: 36 | """ : "\"", 37 | "&" : "&", 38 | "'" : "'", 39 | "<" : "<", 40 | ">" : ">", 41 | 42 | // HTML character entity references: 43 | " " : "\u{00a0}", 44 | // ... 45 | "♦" : "♦", 46 | ] 47 | 48 | // ===== Utility functions ===== 49 | 50 | // Convert the number in the string to the corresponding 51 | // Unicode character, e.g. 52 | // decodeNumeric("64", 10) --> "@" 53 | // decodeNumeric("20ac", 16) --> "€" 54 | func decodeNumeric(_ string : Substring, base : Int) -> Character? { 55 | guard let code = UInt32(string, radix: base), 56 | let uniScalar = UnicodeScalar(code) else { return nil } 57 | return Character(uniScalar) 58 | } 59 | 60 | // Decode the HTML character entity to the corresponding 61 | // Unicode character, return `nil` for invalid input. 62 | // decode("@") --> "@" 63 | // decode("€") --> "€" 64 | // decode("<") --> "<" 65 | // decode("&foo;") --> nil 66 | func decode(_ entity : Substring) -> Character? { 67 | 68 | if entity.hasPrefix("&#x") || entity.hasPrefix("&#X") { 69 | return decodeNumeric(entity.dropFirst(3).dropLast(), base: 16) 70 | } else if entity.hasPrefix("&#") { 71 | return decodeNumeric(entity.dropFirst(2).dropLast(), base: 10) 72 | } else { 73 | return characterEntities[entity] 74 | } 75 | } 76 | 77 | // ===== Method starts here ===== 78 | 79 | var result = "" 80 | var position = startIndex 81 | 82 | // Find the next '&' and copy the characters preceding it to `result`: 83 | while let ampRange = self[position...].range(of: "&") { 84 | result.append(contentsOf: self[position ..< ampRange.lowerBound]) 85 | position = ampRange.lowerBound 86 | 87 | // Find the next ';' and copy everything from '&' to ';' into `entity` 88 | guard let semiRange = self[position...].range(of: ";") else { 89 | // No matching ';'. 90 | break 91 | } 92 | let entity = self[position ..< semiRange.upperBound] 93 | position = semiRange.upperBound 94 | 95 | if let decoded = decode(entity) { 96 | // Replace by decoded character: 97 | result.append(decoded) 98 | } else { 99 | // Invalid entity, copy verbatim: 100 | result.append(contentsOf: entity) 101 | } 102 | } 103 | // Copy remaining characters to `result`: 104 | result.append(contentsOf: self[position...]) 105 | return result 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Sources/OpenGraph/Extension/URLSession.swift: -------------------------------------------------------------------------------- 1 | // 2 | // URLSession.swift 3 | // OpenGraph 4 | // 5 | // Created by Rudrank Riyam on 18/01/22. 6 | // Copyright © 2022 Satoshi Takano. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | #if canImport(FoundationNetworking) 11 | import FoundationNetworking 12 | #endif 13 | 14 | // Taken from John Sundell's [AsyncCompatibilityKit](https://github.com/JohnSundell/AsyncCompatibilityKit/blob/main/Sources/URLSession%2BAsync.swift) 15 | 16 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 17 | public extension URLSession { 18 | /// Start a data task with a URL using async/await. 19 | /// - parameter url: The URL to send a request to. 20 | /// - returns: A tuple containing the binary `Data` that was downloaded, 21 | /// as well as a `URLResponse` representing the server's response. 22 | /// - throws: Any error encountered while performing the data task. 23 | func data(from url: URL) async throws -> (Data, URLResponse) { 24 | try await data(for: URLRequest(url: url)) 25 | } 26 | 27 | /// Start a data task with a `URLRequest` using async/await. 28 | /// - parameter request: The `URLRequest` that the data task should perform. 29 | /// - returns: A tuple containing the binary `Data` that was downloaded, 30 | /// as well as a `URLResponse` representing the server's response. 31 | /// - throws: Any error encountered while performing the data task. 32 | func data(for request: URLRequest) async throws -> (Data, URLResponse) { 33 | try await withCheckedThrowingContinuation { continuation in 34 | self.dataTask(with: request) { data, response, error in 35 | if let error = error { 36 | return continuation.resume(throwing: error) 37 | } 38 | guard let data = data, let response = response else { 39 | return continuation.resume(throwing: URLError(.badServerResponse)) 40 | } 41 | continuation.resume(returning: (data, response)) 42 | }.resume() 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/OpenGraph/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.6.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2016年 Satoshi Takano. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraph.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | //! Project version number for OpenGraph. 4 | FOUNDATION_EXPORT double OpenGraphVersionNumber; 5 | 6 | //! Project version string for OpenGraph. 7 | FOUNDATION_EXPORT const unsigned char OpenGraphVersionString[]; 8 | 9 | // In this header, you should import all the public headers of your framework using statements like #import 10 | 11 | 12 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraph.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | #if canImport(FoundationNetworking) 3 | import FoundationNetworking 4 | #endif 5 | 6 | public struct OpenGraph { 7 | 8 | public let source: [OpenGraphMetadata: String] 9 | 10 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 11 | @discardableResult 12 | public static func fetch(url: URL, headers: [String: String]? = nil, configuration: URLSessionConfiguration = .default, completion: @escaping (Result) -> Void) -> URLSessionDataTask { 13 | var mutableURLRequest = URLRequest(url: url) 14 | headers?.compactMapValues { $0 }.forEach { 15 | mutableURLRequest.setValue($1, forHTTPHeaderField: $0) 16 | } 17 | let session = URLSession(configuration: configuration) 18 | let task = session.dataTask(with: mutableURLRequest, completionHandler: { data, response, error in 19 | if let error = error { 20 | completion(.failure(error)) 21 | } else { 22 | handleFetchResult(data: data, response: response, completion: completion) 23 | } 24 | }) 25 | task.resume() 26 | return task 27 | } 28 | 29 | #if compiler(>=5.5.2) && canImport(_Concurrency) 30 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 31 | public static func fetch(url: URL, headers: [String: String]? = nil, configuration: URLSessionConfiguration = .default) async throws-> OpenGraph { 32 | var mutableURLRequest = URLRequest(url: url) 33 | headers?.compactMapValues { $0 }.forEach { 34 | mutableURLRequest.setValue($1, forHTTPHeaderField: $0) 35 | } 36 | let session = URLSession(configuration: configuration) 37 | let (data, response) = try await session.data(for: mutableURLRequest) 38 | return try handleFetchResult(data: data, response: response) 39 | } 40 | #elseif compiler(>=5.5) && canImport(_Concurrency) 41 | @available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) 42 | public static func fetch(url: URL, headers: [String: String]? = nil, configuration: URLSessionConfiguration = .default) async throws-> OpenGraph { 43 | var mutableURLRequest = URLRequest(url: url) 44 | headers?.compactMapValues { $0 }.forEach { 45 | mutableURLRequest.setValue($1, forHTTPHeaderField: $0) 46 | } 47 | let session = URLSession(configuration: configuration) 48 | let (data, response) = try await session.data(for: mutableURLRequest) 49 | return try handleFetchResult(data: data, response: response) 50 | } 51 | #endif 52 | 53 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 54 | private static func handleFetchResult(data: Data?, response: URLResponse?, completion: @escaping (Result) -> Void) { 55 | guard let data = data, let response = response as? HTTPURLResponse else { 56 | return 57 | } 58 | if !(200..<300).contains(response.statusCode) { 59 | completion(.failure(OpenGraphResponseError.unexpectedStatusCode(response.statusCode))) 60 | } else { 61 | guard let htmlString = String(data: data, textEncodingName: response.textEncodingName) else { 62 | completion(.failure(OpenGraphParseError.encodingError)) 63 | return 64 | } 65 | let og = OpenGraph(htmlString: htmlString) 66 | completion(.success(og)) 67 | } 68 | } 69 | 70 | @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) 71 | private static func handleFetchResult(data: Data, response: URLResponse) throws -> OpenGraph { 72 | if let response = response as? HTTPURLResponse, 73 | !(200..<300).contains(response.statusCode) { 74 | throw OpenGraphResponseError.unexpectedStatusCode(response.statusCode) 75 | } else { 76 | guard let htmlString = String(data: data, textEncodingName: response.textEncodingName) else { 77 | throw OpenGraphParseError.encodingError 78 | } 79 | return OpenGraph(htmlString: htmlString) 80 | } 81 | } 82 | 83 | public init(htmlString: String) { 84 | self = OpenGraph(htmlString: htmlString, parser: DefaultOpenGraphParser()) 85 | } 86 | 87 | init(htmlString: String, parser: OpenGraphParser) { 88 | source = parser.parse(htmlString: htmlString) 89 | } 90 | 91 | public subscript (attributeName: OpenGraphMetadata) -> String? { 92 | return source[attributeName] 93 | } 94 | } 95 | 96 | private struct DefaultOpenGraphParser: OpenGraphParser { 97 | } 98 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraphMetadata.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum OpenGraphMetadata: String, CaseIterable { 4 | // Basic Metadata 5 | case title 6 | case type 7 | case image 8 | case url 9 | 10 | // Optional Metadata 11 | case audio 12 | case description 13 | case determiner 14 | case locale 15 | case localeAlternate = "locale:alternate" 16 | case siteName = "site_name" 17 | case video 18 | 19 | // Structured Properties 20 | case imageUrl = "image:url" 21 | case imageSecure_url = "image:secure_url" 22 | case imageType = "image:type" 23 | case imageWidth = "image:width" 24 | case imageHeight = "image:height" 25 | 26 | // Music 27 | case musicDuration = "music:duration" 28 | case musicAlbum = "music:album" 29 | case musicAlbumDisc = "music:album:disc" 30 | case musicAlbumMusic = "music:album:track" 31 | case musicMusician = "music:musician" 32 | case musicSong = "music:song" 33 | case musicSongDisc = "music:song:disc" 34 | case musicSongTrack = "music:song:track" 35 | case musicReleaseDate = "music:release_date" 36 | case musicCreator = "music:creator" 37 | 38 | // Video 39 | case videoActor = "video:actor" 40 | case videoActorRole = "video:actor:role" 41 | case videoDirector = "video:director" 42 | case videoWriter = "video:writer" 43 | case videoDuration = "video:duration" 44 | case videoReleaseDate = "video:releaseDate" 45 | case videoTag = "video:tag" 46 | case videoSeries = "video:series" 47 | 48 | // No Vertical 49 | case articlePublishedTime = "article:published_time" 50 | case articleModifiedTime = "article:modified_time" 51 | case articleExpirationTime = "article:expiration_time" 52 | case articleAuthor = "article:author" 53 | case articleSection = "article:section" 54 | case articleTag = "article:tag" 55 | 56 | case bookAuthor = "book:author" 57 | case bookIsbn = "book:isbn" 58 | case bookReleaseDate = "book:release_date" 59 | case bookTag = "book:tag" 60 | 61 | case profileFirstName = "profile:first_name" 62 | case profileLastName = "profile:last_name" 63 | case profileUsername = "profile:username" 64 | case profileGender = "profile:gender" 65 | } 66 | 67 | #if !swift(>=4.2) 68 | public protocol CaseIterable { 69 | associatedtype AllCases: Collection where AllCases.Element == Self 70 | static var allCases: AllCases { get } 71 | } 72 | extension CaseIterable where Self: Hashable { 73 | public static var allCases: [Self] { 74 | return [Self](AnySequence { () -> AnyIterator in 75 | var raw = 0 76 | var first: Self? 77 | return AnyIterator { 78 | let current = withUnsafeBytes(of: &raw) { $0.load(as: Self.self) } 79 | if raw == 0 { 80 | first = current 81 | } else if current == first { 82 | return nil 83 | } 84 | raw += 1 85 | return current 86 | } 87 | }) 88 | } 89 | } 90 | #endif 91 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraphParseError.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum OpenGraphParseError: Error { 4 | case encodingError 5 | } 6 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraphParser.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public protocol OpenGraphParser { 4 | func parse(htmlString: String) -> [OpenGraphMetadata: String] 5 | } 6 | 7 | extension OpenGraphParser { 8 | func parse(htmlString: String) -> [OpenGraphMetadata: String] { 9 | // extract meta tag 10 | let metatagRegex = try! NSRegularExpression( 11 | pattern: "", 12 | options: [.dotMatchesLineSeparators] 13 | ) 14 | let metaTagMatches = metatagRegex.matches(in: htmlString, 15 | options: [], 16 | range: NSMakeRange(0, htmlString.count)) 17 | if metaTagMatches.isEmpty { 18 | return [:] 19 | } 20 | 21 | // prepare regular expressions to extract og property and content. 22 | let propertyRegexp = try! NSRegularExpression( 23 | pattern: "\\s(?:property|name)=(?:\"|\')*og:([a-zA_Z:]+)(?:\"|\')*", 24 | options: [] 25 | ) 26 | let contentRegexp = try! NSRegularExpression( 27 | pattern: "\\scontent=\\\\*?\"(.*?)\\\\*?\"", 28 | options: [] 29 | ) 30 | 31 | // create attribute dictionary 32 | let nsString = htmlString as NSString 33 | let attributes = metaTagMatches.reduce([OpenGraphMetadata: String]()) { (attributes, result) -> [OpenGraphMetadata: String] in 34 | var copiedAttributes = attributes 35 | 36 | let property = { () -> (name: String, content: String)? in 37 | let metaTag = nsString.substring(with: result.range(at: 0)) 38 | let propertyMatches = propertyRegexp.matches(in: metaTag, 39 | options: [], 40 | range: NSMakeRange(0, metaTag.count)) 41 | guard let propertyResult = propertyMatches.first else { return nil } 42 | 43 | var contentMatches = contentRegexp.matches(in: metaTag, options: [], range: NSMakeRange(0, metaTag.count)) 44 | if contentMatches.first == nil { 45 | let contentRegexp = try! NSRegularExpression( 46 | pattern: "\\scontent=\\\\*?'(.*?)\\\\*?'", 47 | options: [] 48 | ) 49 | contentMatches = contentRegexp.matches(in: metaTag, options: [], range: NSMakeRange(0, metaTag.count)) 50 | } 51 | guard let contentResult = contentMatches.first else { return nil } 52 | 53 | let nsMetaTag = metaTag as NSString 54 | let property = nsMetaTag.substring(with: propertyResult.range(at: 1)) 55 | let content = nsMetaTag.substring(with: contentResult.range(at: 1)).stringByDecodingHTMLEntities 56 | 57 | return (name: property, content: content) 58 | }() 59 | if let property = property, let metadata = OpenGraphMetadata(rawValue: property.name) { 60 | copiedAttributes[metadata] = property.content 61 | } 62 | return copiedAttributes 63 | } 64 | 65 | return attributes 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/OpenGraph/OpenGraphResponseError.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum OpenGraphResponseError: Error { 4 | case unexpectedStatusCode(Int) 5 | } 6 | -------------------------------------------------------------------------------- /Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/OpenGraphTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import OHHTTPStubs 3 | import OHHTTPStubsSwift 4 | @testable import OpenGraph 5 | 6 | class OpenGraphTests: XCTestCase { 7 | override func setUp() { 8 | super.setUp() 9 | // Put setup code here. This method is called before the invocation of each test method in the class. 10 | } 11 | 12 | override func tearDown() { 13 | // Put teardown code here. This method is called after the invocation of each test method in the class. 14 | super.tearDown() 15 | 16 | HTTPStubs.removeAllStubs() 17 | } 18 | 19 | func setupStub(htmlFileName: String) { 20 | HTTPStubs.stubRequests { request in 21 | true 22 | } withStubResponse: { request in 23 | #if SWIFT_PACKAGE 24 | let path = Bundle.module.path(forResource: htmlFileName, ofType: "html") 25 | #else 26 | let path = Bundle(for: type(of: self)).path(forResource: htmlFileName, ofType: "html") 27 | #endif 28 | return .init(fileAtPath: path!, statusCode: 200, headers: nil) 29 | } 30 | } 31 | 32 | func testCustomHeader() { 33 | let responseArrived = expectation(description: "response of async request has arrived") 34 | 35 | setupStub(htmlFileName: "ogp") 36 | 37 | let url = URL(string: "https://www.example.com")! 38 | var og: OpenGraph! 39 | var error: Error? 40 | let headers = ["User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"] 41 | OpenGraph.fetch(url: url, headers: headers) { result in 42 | switch result { 43 | case .success(let _og): og = _og 44 | case .failure(let _error): error = _error 45 | } 46 | responseArrived.fulfill() 47 | } 48 | 49 | waitForExpectations(timeout: 10) { _ in 50 | XCTAssert(og[.title] == " < It's example.com title > ") 51 | XCTAssert(og[.type] == "website") 52 | XCTAssert(og[.url] == "https://www.example.com") 53 | XCTAssert(og[.image] == "https://www.example.com/images/example.png") 54 | 55 | XCTAssert(error == nil) 56 | } 57 | } 58 | 59 | func testFetching() { 60 | let responseArrived = expectation(description: "response of async request has arrived") 61 | 62 | setupStub(htmlFileName: "ogp") 63 | 64 | let url = URL(string: "https://www.example.com")! 65 | var og: OpenGraph! 66 | var error: Error? 67 | OpenGraph.fetch(url: url) { result in 68 | switch result { 69 | case .success(let _og): og = _og 70 | case .failure(let _error): error = _error 71 | } 72 | responseArrived.fulfill() 73 | } 74 | 75 | waitForExpectations(timeout: 10) { _ in 76 | XCTAssert(og[.title] == " < It's example.com title > ") 77 | XCTAssert(og[.type] == "website") 78 | XCTAssert(og[.url] == "https://www.example.com") 79 | XCTAssert(og[.image] == "https://www.example.com/images/example.png") 80 | XCTAssert(og[.description] == "example.com description") 81 | XCTAssert(og[.imageType] == "image/png") 82 | XCTAssert(error == nil) 83 | } 84 | } 85 | 86 | func testEmptyOGP() { 87 | let responseArrived = expectation(description: "response of async request has arrived") 88 | 89 | setupStub(htmlFileName: "empty_ogp") 90 | 91 | let url = URL(string: "https://www.example.com")! 92 | var og: OpenGraph! 93 | var error: Error? 94 | OpenGraph.fetch(url: url) { result in 95 | switch result { 96 | case .success(let _og): og = _og 97 | case .failure(let _error): error = _error 98 | } 99 | responseArrived.fulfill() 100 | } 101 | 102 | waitForExpectations(timeout: 10) { _ in 103 | XCTAssert(og[.title] == nil) 104 | XCTAssert(og[.type] == nil) 105 | XCTAssert(og[.url] == nil) 106 | XCTAssert(og[.image] == nil) 107 | 108 | XCTAssert(error == nil) 109 | } 110 | } 111 | 112 | func testHTTPResponseError() { 113 | let responseArrived = expectation(description: "response of async request has arrived") 114 | 115 | HTTPStubs.stubRequests { request in 116 | true 117 | } withStubResponse: { request in 118 | return .init(jsonObject: [:], statusCode: 404, headers: nil) 119 | } 120 | 121 | let url = URL(string: "https://www.example.com")! 122 | var og: OpenGraph? 123 | var error: Error? 124 | OpenGraph.fetch(url: url) { result in 125 | switch result { 126 | case .success(let _og): og = _og 127 | case .failure(let _error): error = _error 128 | } 129 | responseArrived.fulfill() 130 | } 131 | 132 | waitForExpectations(timeout: 10) { _ in 133 | XCTAssert(og == nil) 134 | 135 | XCTAssert(error! is OpenGraphResponseError) 136 | 137 | var statusCode: Int = 0 138 | switch error as! OpenGraphResponseError { 139 | case .unexpectedStatusCode(let code): 140 | statusCode = code 141 | break 142 | } 143 | 144 | XCTAssert(statusCode == 404) 145 | } 146 | } 147 | 148 | func testParseError() async { 149 | OHHTTPStubsSwift.stub { request in 150 | return true 151 | } response: { request in 152 | HTTPStubsResponse() 153 | } 154 | 155 | HTTPStubs.stubRequests { request in 156 | true 157 | } withStubResponse: { request in 158 | .init(data: "あ".data(using: String.Encoding.shiftJIS)!, statusCode: 200, headers: nil) 159 | } 160 | 161 | let url = URL(string: "https://www.example.com")! 162 | 163 | do { 164 | _ = try await OpenGraph.fetch(url: url) 165 | } 166 | catch let error { 167 | XCTAssert(error is OpenGraphParseError) 168 | } 169 | } 170 | 171 | func testParsing() { 172 | var html = "" 173 | XCTAssert(OpenGraph(htmlString: html)[.description] == "It's a description") 174 | html = "" 175 | XCTAssert(OpenGraph(htmlString: html)[.title] == "It's a title contains single quote") 176 | html = "" 177 | XCTAssert(OpenGraph(htmlString: html)[.title] == "It's a title contains single quote") 178 | 179 | html = "" 180 | XCTAssert(OpenGraph(htmlString: html)[.description] == "It's a description") 181 | html = "" 182 | XCTAssert(OpenGraph(htmlString: html)[.title] == "It is a title contains double quote \"") 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /Tests/Resources/empty_ogp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Hello, world.

6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/Resources/example3.com.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |

Hello, world.

11 | 12 | 13 | -------------------------------------------------------------------------------- /Tests/Resources/ogp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

Hello, world.

15 | 16 | 17 | --------------------------------------------------------------------------------