Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
platforms: [.macOS(.v10_13), .iOS(.v12), .watchOS(.v11)],
products: [
.library(
name: "ScryfallKit",
Expand Down
2 changes: 2 additions & 0 deletions Sources/ScryfallKit/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import OSLog

@available(macOS 11.0, *)
@available(iOS 14.0, *)
@available(watchOS 11.0, *)

extension Logger {
static let subsystem = "dev.hearst.scryfallkit"
static let main = Logger(subsystem: subsystem, category: "ScryfallKit")
Expand Down
20 changes: 20 additions & 0 deletions Sources/ScryfallKit/Models/Card/Card+Face.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ extension Card {
/// This card's watermark, if any
public var watermark: String?

enum CodingKeys: String, CodingKey {
case artist
case colorIndicator = "color_indicator"
case colors
case flavorText = "flavor_text"
case illustrationId = "illustration_id"
case imageUris = "image_uris"
case loyalty
case manaCost = "mana_cost"
case name
case oracleText = "oracle_text"
case power
case printedName = "printed_name"
case printedText = "printed_text"
case printedTypeLine = "printed_type_line"
case toughness
case typeLine = "type_line"
case watermark
}

public init(
artist: String? = nil,
colorIndicator: [Card.Color]? = nil,
Expand Down
92 changes: 84 additions & 8 deletions Sources/ScryfallKit/Models/Card/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
/// The language that this specific printing was printed in
public var lang: String
/// A link to where you can begin paginating all re/prints for this card on Scryfall’s API.
public var printsSearchUri: String
public var printsSearchUri: String?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scryfall's API docs don't list this as an optional field, have you seen cards where this property is nil?

/// A link to this card’s rulings list on Scryfall’s API.
public var rulingsUri: String
public var rulingsUri: String?
/// A link to this card’s permapage on Scryfall’s website.
public var scryfallUri: String
public var scryfallUri: String?
/// A link to this card object on Scryfall’s API.
public var uri: String

Expand All @@ -52,7 +52,7 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
/// An array of colors representing this card's color identity.
///
/// Color identity is used to determine what cards are legal in a Commander deck. See the [comprehensive rules](https://magic.wizards.com/en/rules) for more information
public var colorIdentity: [Color]
public var colorIdentity: [Color]?
/// An array of the colors in this card’s color indicator or nil if it doesn't have one
///
/// Color indicators are used to specify the color of a card that has no mana symbols
Expand Down Expand Up @@ -100,6 +100,8 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
// MARK: Print fields
/// The name of the artist who illustrated this card
public var artist: String?
/// An array of IDs that map to the artists who illustrated the card
public var artistIds: [String]?
/// True if this card was printed in booster packs
public var booster: Bool
/// The color of this card's border
Expand Down Expand Up @@ -127,6 +129,8 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
public var frame: Frame
/// True if this card's art is larger than normal
public var fullArt: Bool
/// A description of what security stamp the card has - for Unfinity cards, will be "acorn", for normal rares, "oval"
public var securityStamp: String?
/// An array of the games this card has been released in
public var games: [Game]
/// True if Scryfall has a high-res image of this card
Expand Down Expand Up @@ -169,6 +173,8 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
public var setType: MTGSet.`Type`
/// A link to this card's set object on the Scryfall API
public var setUri: String
/// A unique ID that identifies what set the card came from.
public var setId: String?
/// This card's set code
public var set: String
/// True if this was a story spotlight card
Expand All @@ -184,6 +190,72 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
/// An object with information on when this card was previewed and by whom
public var preview: Preview?

enum CodingKeys: String, CodingKey {
case id
case oracleId = "oracle_id"
case multiverseIds = "multiverse_ids"
case mtgoId = "mtgo_id"
case arenaId = "arena_id"
case tcgplayerId = "tcgplayer_id"
case cardMarketId = "cardmarket_id"
case name
case lang
case releasedAt = "released_at"
case uri
case scryfallUri = "scryfall_uri"
case layout
case highresImage = "highres_image"
case imageStatus = "image_status"
case imageUris = "image_uris"
case manaCost = "mana_cost"
case cardFaces = "card_faces"
case cmc
case typeLine = "type_line"
case oracleText = "oracle_text"
case power
case toughness
case colors
case colorIdentity = "color_identity"
case keywords
case legalities
case games
case reserved
case finishes
case oversized
case promo
case promoTypes = "promo_types"
case reprint
case variation
case setId = "set_id"
case set
case setName = "set_name"
case setType = "set_type"
case setUri = "set_uri"
case setSearchUri = "set_search_uri"
case scryfallSetUri = "scryfall_set_uri"
case rulingsUri = "rulings_uri"
case printsSearchUri = "prints_search_uri"
case collectorNumber = "collector_number"
case digital
case rarity
case cardBackId = "card_back_id"
case artist
case artistIds = "artist_ids"
case illustrationId = "illustration_id"
case borderColor = "border_color"
case frame
case frameEffects = "frame_effects"
case securityStamp = "security_stamp"
case fullArt = "full_art"
case textless
case booster
case storySpotlight = "story_spotlight"
case edhrecRank = "edhrec_rank"
case prices
case relatedUris = "related_uris"
case purchaseUris = "purchase_uris"
}

// swiftlint:disable function_body_length
public init(
arenaId: Int? = nil,
Expand All @@ -196,14 +268,14 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
id: UUID,
oracleId: String,
lang: String,
printsSearchUri: String,
rulingsUri: String,
scryfallUri: String,
printsSearchUri: String? = nil,
rulingsUri: String? = nil,
scryfallUri: String? = nil,
uri: String,
allParts: [RelatedCard]? = nil,
cardFaces: [Face]? = nil,
cmc: Double,
colorIdentity: [Color],
colorIdentity: [Color]? = nil,
colorIndicator: [Color]? = nil,
colors: [Color]? = nil,
edhrecRank: Int? = nil,
Expand All @@ -223,6 +295,7 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
toughness: String? = nil,
typeLine: String? = nil,
artist: String? = nil,
artistIds: [String]? = nil,
booster: Bool,
borderColor: BorderColor,
cardBackId: UUID? = nil,
Expand All @@ -235,6 +308,7 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
frameEffects: [FrameEffect]? = nil,
frame: Frame,
fullArt: Bool,
securityStamp: String? = nil,
games: [Game],
highresImage: Bool,
illustrationId: UUID? = nil,
Expand Down Expand Up @@ -301,6 +375,7 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
self.toughness = toughness
self.typeLine = typeLine
self.artist = artist
self.artistIds = artistIds
self.booster = booster
self.borderColor = borderColor
self.cardBackId = cardBackId
Expand All @@ -313,6 +388,7 @@ public struct Card: Codable, Identifiable, Hashable, Sendable {
self.frameEffects = frameEffects
self.frame = frame
self.fullArt = fullArt
self.securityStamp = securityStamp
self.games = games
self.highresImage = highresImage
self.illustrationId = illustrationId
Expand Down
4 changes: 2 additions & 2 deletions Sources/ScryfallKit/Networking/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol NetworkServiceProtocol: Sendable {
as type: T.Type,
completion: @Sendable @escaping (Result<T, Error>) -> Void
)
@available(macOS 10.15.0, *, iOS 13.0.0, *)
@available(macOS 10.15.0, *, iOS 13.0.0, *, watchOS 11.0, *)
func request<T: Decodable>(_ request: EndpointRequest, as type: T.Type) async throws -> T
}

Expand Down Expand Up @@ -104,7 +104,7 @@ struct NetworkService: NetworkServiceProtocol, Sendable {
}
}

@available(macOS 10.15.0, *, iOS 13.0.0, *)
@available(macOS 10.15.0, *, iOS 13.0.0, *, watchOS 11.0, *)
func request<T: Decodable>(_ request: EndpointRequest, as type: T.Type) async throws -> T
where T: Sendable {
try await withCheckedThrowingContinuation { continuation in
Expand Down
2 changes: 1 addition & 1 deletion Sources/ScryfallKit/ScryfallClient+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

@available(macOS 10.15.0, *, iOS 13.0.0, *)
@available(macOS 10.15.0, *, iOS 13.0.0, *, watchOS 11.0, *)
extension ScryfallClient {
/// Equivalent to ``searchCards(filters:unique:order:sortDirection:includeExtras:includeMultilingual:includeVariations:page:completion:)`` but with async/await syntax
public func searchCards(
Expand Down
Loading