Skip to content

Commit

Permalink
Fix JSON parsing error by making formattedPrice & price optional …
Browse files Browse the repository at this point in the history
…for `SearchResult`.

Use new `displayPrice` to get around optional `formattedPrice`. Doesn't handle i18n, but we can clean that up after we completely redo JSON handling.

Resolve #493

Signed-off-by: Ross Goldberg <[email protected]>
  • Loading branch information
rgoldberg committed Nov 20, 2024
1 parent ca921c0 commit 309cfec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/mas/Formatters/AppInfoFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum AppInfoFormatter {
let headline = [
"\(app.trackName)",
"\(app.version)",
"[\(app.formattedPrice)]",
"[\(app.displayPrice)]",
]
.joined(separator: " ")

Expand Down
2 changes: 1 addition & 1 deletion Sources/mas/Formatters/SearchResultFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum SearchResultFormatter {
let version = result.version

if includePrice {
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.formattedPrice)
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.displayPrice)
} else {
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/mas/Models/SearchResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ struct SearchResult: Decodable {
var bundleId: String
var currentVersionReleaseDate: String
var fileSizeBytes: String
var formattedPrice: String
var formattedPrice: String?
var minimumOsVersion: String
var price: Double
var price: Double?
var sellerName: String
var sellerUrl: String?
var trackId: AppID
var trackName: String
var trackViewUrl: String
var version: String

var displayPrice: String {
formattedPrice ?? "Unknown"
}

init(
bundleId: String = "",
currentVersionReleaseDate: String = "",
Expand Down

0 comments on commit 309cfec

Please sign in to comment.