Skip to content

Commit

Permalink
Implement parsing of Appcast items from XML data
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefizso committed Oct 25, 2023
1 parent 7cac656 commit d9dc4f2
Show file tree
Hide file tree
Showing 7 changed files with 553 additions and 65 deletions.
5 changes: 5 additions & 0 deletions Sources/Appcast/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ public struct SURSSElement {
public static let PubDate = "pubDate"
public static let Title = "title"
}

public struct SURSSAttribute {
public static let URL = "url"
public static let Length = "length"
}
22 changes: 13 additions & 9 deletions Sources/Appcast/SUAppcast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public class SUAppcast {
}

if let name = self.sparkleNamespacedName(of: currentNode) {
var nodes = nodesDict[name]
if nodes == nil {
nodes = [XMLNode]()
nodesDict[name] = nodes
}

nodes?.append(currentNode)
nodesDict[name, default: [XMLNode]()].append(currentNode)
// var nodes = nodesDict[name]
// if nodes == nil {
// nodes = [XMLNode]()
// nodesDict[name] = nodes
// }
//
// nodes?.append(currentNode)
}

node = currentNode.nextSibling
Expand All @@ -61,6 +62,7 @@ public class SUAppcast {
let name = nodeInfo.key
let nodeSet = nodeInfo.value
guard let node = self.bestNode(in: nodeSet, name: name) else {
print("Missing node value for element \(name)")
continue
}

Expand Down Expand Up @@ -88,7 +90,7 @@ public class SUAppcast {
let attributes = self.attributes(of: node)
let descriptionFormat = attributes[SUAppcastAttribute.Format]

var descriptionDict = [String: String]()
var descriptionDict = AttributesDictionary()
descriptionDict["content"] = description
descriptionDict["format"] = descriptionFormat

Expand Down Expand Up @@ -123,7 +125,7 @@ public class SUAppcast {
dict[name] = tags
}
else if name == SUAppcastElement.InformationalUpdate {
var informationalUpdateVersions = Set<String>()
var informationalUpdateVersions = SUAppcastItem.InformationalUpdateType()

if let children = node.children {
for child in children {
Expand Down Expand Up @@ -210,6 +212,8 @@ public class SUAppcast {
return nodes[preferredLanguageIndex]
}

typealias AttributesDictionary = [String: String]

func attributes(of node: XMLNode) -> [String: String] {
var dictionary = [String: String]()

Expand Down
Loading

0 comments on commit d9dc4f2

Please sign in to comment.