From 0b4a9f143e3f8cea1f83a1e0ef3f8248ba7c2e6c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 11 Dec 2017 13:36:16 -0800 Subject: [PATCH] Parse Feedbin articles. --- .../Account/Account.xcodeproj/project.pbxproj | 4 + .../Account/Feedbin/FeedbinArticle.swift | 96 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 Frameworks/Account/Feedbin/FeedbinArticle.swift diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index 445196710..af2182fd3 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 84B99C9F1FAE8D3200ECDEDB /* ContainerPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */; }; 84C3654A1F899F3B001EC85C /* CombinedRefreshProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */; }; 84C8B3F41F89DE430053CCA6 /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */; }; + 84CAD7161FDF2E22000F0755 /* FeedbinArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -126,6 +127,7 @@ 84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerPath.swift; sourceTree = ""; }; 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = ""; }; 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = ""; }; + 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinArticle.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -204,6 +206,7 @@ 84245C801FDDD42A0074AFBB /* Feedbin.swift */, 84245C821FDDD8160074AFBB /* FeedbinGetSubscriptionsDelegate.swift */, 84245C841FDDD8CB0074AFBB /* FeedbinSubscription.swift */, + 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */, ); path = Feedbin; sourceTree = ""; @@ -461,6 +464,7 @@ 84B99C9F1FAE8D3200ECDEDB /* ContainerPath.swift in Sources */, 846E77501F6EF9C400A165E2 /* LocalAccountRefresher.swift in Sources */, 84245C811FDDD42A0074AFBB /* Feedbin.swift in Sources */, + 84CAD7161FDF2E22000F0755 /* FeedbinArticle.swift in Sources */, 841974011F6DD1EC006346C4 /* Folder.swift in Sources */, 846E774F1F6EF9C000A165E2 /* LocalAccountDelegate.swift in Sources */, 84245C851FDDD8CB0074AFBB /* FeedbinSubscription.swift in Sources */, diff --git a/Frameworks/Account/Feedbin/FeedbinArticle.swift b/Frameworks/Account/Feedbin/FeedbinArticle.swift new file mode 100644 index 000000000..cbd2c64bf --- /dev/null +++ b/Frameworks/Account/Feedbin/FeedbinArticle.swift @@ -0,0 +1,96 @@ +// +// FeedbinArticle.swift +// Account +// +// Created by Brent Simmons on 12/11/17. +// Copyright © 2017 Ranchero Software, LLC. All rights reserved. +// + +import Foundation +import RSParser +import RSCore + +struct FeedbinArticle { + + // "id": 2077, + // "feed_id": 135, + // "title": "Objective-C Runtime Releases", + // "url": "http:\/\/mjtsai.com\/blog\/2013\/02\/02\/objective-c-runtime-releases\/", + // "author": "Michael Tsai", + // "content": "

Bavarious<\/a> created a GitHub repository<\/a> that shows the differences between versions of Apple\u2019s Objective-C runtime<\/a> that shipped with different versions of Mac OS X.<\/p>", + // "summary": "Bavarious created a GitHub repository that shows the differences between versions of Apple\u2019s Objective-C runtime that shipped with different versions of Mac OS X.", + // "published": "2013-02-03T01:00:19.000000Z", + // "created_at": "2013-02-04T01:00:19.127893Z" + + struct Key { + static let syncID = "id" + static let feedID = "feed_id" + static let title = "title" + static let url = "url" + static let authorName = "author" + static let contentHTML = "content" + static let summary = "summary" + static let datePublished = "published" + static let dateArrived = "created_at" + } + + let syncID: String + let feedID: String + let title: String? + let url: String? + let authorName: String? + let contentHTML: String? + let summary: String? + let datePublished: Date? + let dateArrived: Date? + + init?(jsonDictionary: JSONDictionary) { + + guard let syncIDInt = jsonDictionary[Key.syncID] as? Int else { + return nil + } + guard let feedIDInt = jsonDictionary[Key.feedID] as? Int else { + return nil + } + self.syncID = "\(syncIDInt)" + self.feedID = "\(feedIDInt)" + + self.title = jsonDictionary[Key.title] as? String + self.url = jsonDictionary[Key.url] as? String + self.authorName = jsonDictionary[Key.authorName] as? String + + if let contentHTML = jsonDictionary[Key.contentHTML] as? String, !contentHTML.isEmpty { + self.contentHTML = contentHTML + } + else { + self.contentHTML = nil + } + + if let summary = jsonDictionary[Key.summary] as? String, !summary.isEmpty { + self.summary = summary + } + else { + self.summary = nil + } + + if let datePublishedString = jsonDictionary[Key.datePublished] as? String { + self.datePublished = RSDateWithString(datePublishedString) + } + else { + self.datePublished = nil + } + + if let dateArrivedString = jsonDictionary[Key.dateArrived] as? String { + self.dateArrived = RSDateWithString(dateArrivedString) + } + else { + self.dateArrived = nil + } + } + + static func articles(with array: JSONArray) -> [FeedbinArticle]? { + + let articlesArray = array.flatMap { FeedbinArticle(jsonDictionary: $0) } + return articlesArray.isEmpty ? nil : articlesArray + } +}