Swiftpack.co - Package - JalilK/Yami

Yami

Swift package wrapper library for the http://yugiohprices.com api built with Kitura.

Summary

Yami provides an easy to use interface for accessing data from the http://yugiohprices.com api.

Usage

Each of Yami functions correspond to an endpoint in the http://yugiohprices.com api:

Check Price for Card Name

import Yami

//Create instance
let yami = Yami()

yami.getPricesForCard(withName: "Mirror Force", { yamiPrices, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let yamiPrices = yamiPrices else {
                //Handle case where yamiPrices instance is nil
            }
            
            //Array of YamiPrices
            for yamiPrice in yamiPrices {
                let name = yamiPrice.getName() //Set name
                let printTag = yamiPrice.getPrintTag() //Card print tag
                let rarity = yamiPrice.getRarity() //Card rarity within set
                
                //Price data
                let high = yamiPrice.getHigh() //High end of card price in this set
                let low = yamiPrice.getLow() //Low end of card price in this set
                let average = yamiPrice.getAverage() //Average of card price in this set
                let shift = yamiPrice.getShift() //Average price shift of card in this set
                let shift3 = yamiPrice.getShift3() //3 day price shift
                let shift7 = yamiPrice.getShift7() //7 day price shift
                let shift21 = yamiPrice.getShift21() //21 day price shift
                let shift30 = yamiPrice.getShift30() //30 day price shift
                let shift90 = yamiPrice.getShift90() //90 day price shift
                let shift180 = yamiPrice.getShift180() //180 day price shift
                let shift365 = yamiPrice.getShift365() //365 day price shift
                let updatedAt = yamiPrice.getUpdatedAt() //Date card was updated
            }
        }
    })

Check Price for Card's Print Tag

import Yami

//Create instance
let yami = Yami()
yami.getCard(withPrintTag: "YGLD-ENA37", { yamiCard, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let yamiCard = yamiCard else {
                //Handle case where yamiCard instance is nil
                return
            }
            
            let name = yamiCard.getName() //Name of card with print tag
            let cardType = yamiCard.getCardType() //Card Type of card with print tag
            let property = yamiCard.getProperty() //Property of card with print tag
            
            //Family and type can be nil as some cards don't have a family or type in which case yami.getFamily() and yami.getType() will return empty string
            //*NOTE: type is not to be confused with card_type. They are two different properties
            let family = yamiCard.getFamily() //Monster card family
            let type = yamiCard.getType() //Monster card type
            
            //Price data
            let high = yamiCard.getHigh() //High end of card price
            let low = yamiCard.getLow() //Low end of card price
            let average = yamiCard.getAverage() //Average of card price
            let shift = yamiCard.getShift() //Average price shift
            let shift3 = yamiCard.getShift3() //3 day price shift
            let shift7 = yamiCard.getShift7() //7 day price shift
            let shift21 = yamiCard.getShift21() //21 day price shift
            let shift30 = yamiCard.getShift30() //30 day price shift
            let shift90 = yamiCard.getShift90() //90 day price shift
            let shift180 = yamiCard.getShift180() //180 day price shift
            let shift365 = yamiCard.getShift365() //365 day price shift
            let updatedAt = yamiCard.getUpdatedAt() //Date card was updated
        }
    })

Check Price History for a Specific Print tag and (Optional) Rarity without rarity

//Create Yami instance
let yami = Yami()

yami.getPriceHistoryForCard(withPrintTag: "YGLD-ENA37", { (priceHistory, err) in
        if err != nil {
            //Error Handling
        }
        else {
            guard let priceHistory = priceHistory else {
                //Handle case where priceHistory array is nil
                return
            }
            
            //YamiPriceHistory array
            for currentHistory in priceHistory {
                let priceLow = currentHistory.getPriceLow() //Low end price of card with print tag
                let priceHigh = currentHistory.getPriceHigh() //High end price of card with print tag
                let priceAverage = currentHistory.getPriceAverage() //Average price of card with print tag
                let priceShift = currentHistory.getPriceShift() //Price shift of card at createdAt date
                let createdAt = currentHistory.getCreatedAt() //Date of creation for history
            }
        }
    })

Check Price History for a Specific Print tag and (Optional) Rarity with Rarity

let yami = Yami()
yami.getPriceHistoryForCard(withPrintTag: "YGLD-ENA37", rarity: "common", { priceHistory, err in
        if err != nil {
            //Error Handling
        }
        else {
            guard let priceHistory = priceHistory else {
                //Handle case where priceHistory array is nil
                return
            }
            
            //YamiPriceHistory array
            for currentHistory in priceHistory {
                let priceLow = currentHistory.getPriceLow() //Low end price of card with print tag
                let priceHigh = currentHistory.getPriceHigh() //High end price of card with print tag
                let priceAverage = currentHistory.getPriceAverage() //Average price of card with print tag
                let priceShift = currentHistory.getPriceShift() //Price shift of card at createdAt date
                let createdAt = currentHistory.getCreatedAt() //Date of creation for history
            }
        }
    })

Retrieve prices for all cards in a specific set

let yami = Yami()
yami.getPricesForCards(inSet: "metal raiders", { yamiSet, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let yamiSet = yamiSet else {
                //Handle case where yamiSet is nil
                return
            }
            
            let common = yamiSet.getCommon() // Number of common cards in this set
            let ultrRare = yamiSet.getUltraRare() // Number of Ultra Rare cards in this set
            let shortPrint = yamiSet.getShortPrint() // Number of Short Print cards in this set
            let rare = yamiSet.getRare() // Number of Rare cards in this set
            let superRare = yamiSet.getSuperRare() // Number of Super Rare cards in this set
            let superShortPrint = yamiSet.getSuperShortPrint() // Number of Super Short Print cards in this set
            let secretRare = yamiSet.getSecretRare() // Number of Secret Rare cards in set
            
            //Price data
            let average = yamiSet.getAverage() // Average price of all cards in set
            let loweest = yamiSet.getLowest() // Low end price of all cards in set
            let highest = yamiSet.getHighest() // High end price of all cards in set
            
            //TCGBooster values
            let boosterValueHigh = yamiSet.getBoosterValueHigh()
            let boosterValueLow = yamiSet.getBoosterValueLow()
            let boosterValueAverage = yamiSet.getBoosterValueAverage()
            
            //Cards in set
            let cards = yamiSet.getCards()
            
            //Array of YamiSetCard
            for card in cards {
                let name = card.getName() // Card name
                let cardType = card.getCardType() // Card type
                let property = card.getProperty() // Card property
                let family = card.getFamily() // Monster card family
                let type = card.getType() // Monster card type
                
                //Numbers
                //getNumbers() returns optional. Don't forget nil check
                if let numbers = card.getNumbers() {
                    //Array of YamiSetNumber
                    for number in numbers {
                        let setName = number.getName() // Name of set for this card is in
                        let cardPrintTag = number.getPrintTag() // Print tag of card
                        let rarity = number.getRarity() // Rarity of this card
                        
                        //Price data
                        let high = number.getHigh() //High end of card price
                        let low = number.getLow() //Low end of card price
                        let average = number.getAverage() //Average of card price
                        let shift = number.getShift() //Average price shift
                        let shift3 = number.getShift3() //3 day price shift
                        let shift7 = number.getShift7() //7 day price shift
                        let shift21 = number.getShift21() //21 day price shift
                        let shift30 = number.getShift30() //30 day price shift
                        let shift90 = number.getShift90() //90 day price shift
                        let shift180 = number.getShift180() //180 day price shift
                        let shift365 = number.getShift365() //365 day price shift
                        let updatedAt = number.getUpdatedAt() //Date card was updated
                    }
                }
                
            }
        }
    })

Retrieve rising and falling cards list

    let yami = Yami()
    yami.getRisingAndFalling({ yamiRisingAndFalling, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let yamiRisingAndFalling = yamiRisingAndFalling else {
                //Handle case where yamiRisingAndFalling is nil
                return
            }
            
            //getRising() returns an optional. Don't forget nil check
            if let risingList = yamiRisingAndFalling.getRising() {
                //YamiRisingAndFallingCard Array
                for card in risingList {
                    let name = card.getName() // Card name
                    let price = card.getPrice() // Card price
                    let priceShift = card.getPriceShift() // Price shift of card
                    let cardNumber = card.getCardNumber() // Card number
                    let cardSet = card.getCardSet() // Card set
                    let rarity = card.getRarity() // Card rarity
                }
            }
            
            //getFalling() returns an optional. Don't forget nil check
            if let fallingList = yamiRisingAndFalling.getFalling() {
                //YamiRisingAndFallingCard Array
                for card in fallingList {
                    let name = card.getName() // Card name
                    let price = card.getPrice() // Card price
                    let priceShift = card.getPriceShift() // Price shift of card
                    let cardNumber = card.getCardNumber() // Card number
                    let cardSet = card.getCardSet() // Card set
                    let rarity = card.getRarity() // Card rarity
                }
            }
        }
    })

Getting Card Data

    let yami = Yami()
    yami.getDetailsForCard(withName: "Mirror Force", { yamiCardDetail, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let yamiCardDetail = yamiCardDetail else {
                //Handle case where yamiCardDetail is nil
                return
            }
            
            let name = yamiCardDetail.getName() // Card name
            let text = yamiCardDetail.getText() // Card text
            let cardType = yamiCardDetail.getCardType() // Card type
            let type = yamiCardDetail.getType() // Monster card type
            let family = yamiCardDetail.getFamily() // Monster card family
            let atk = yamiCardDetail.getAtk() // Monster card atk
            let def = yamiCardDetail.getDef() // Monster card def
            let level = yamiCardDetail.getLevel() // Monster card level
            let property = yamiCardDetail.getProperty() // Card property
        }
    })

Retrieve a list of all known versions of a card using its name

    let yami = Yami()
    yami.getVersionsOfCard(withName: "Mirror Force", { yamiCardVersions, err in
        if err != nil {
            //Error Handling
        }
        else {
            guard let yamiCardVersions = yamiCardVersions else {
                //Handle case where yamiCardVersions is nil
                return
            }
            
            //Array of YamiCardVersion
            for yamiCardVersion in yamiCardVersions {
                let name = yamiCardVersion.getName() // Set name for this version of card
                let printTag = yamiCardVersion.getPrintTag() // Print tag for this version of card
                let rarity = yamiCardVersion.getRarity() // Rarity of this version of card
            }
        }
    })

Retrieve the image for a specific card using its name

    let yami = Yami()
    yami.getImageForCard(withName: "Mirror Force", { imageData, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let imageData = imageData else {
                //Handle case where imageData is nil
                return
            }
            
            //imageData is a base64 encoded string. Pass it to your json object as is to send to your client
            
            //Kitura-SwiftyJSON object
            var json = JSON([:])
            json["imageData"].stringValue = imageData
        }
    })

Retrieve the image for a specific card set using its name

    let yami = Yami()
    yami.getImageForSet(withName: "Metal Raiders", { imageData, err in
        if err != nil {
            //Error handling
        }
        else {
            guard let imageData = imageData else {
                //Handle case where imageData is nil
                return
            }
            
            //imageData is a base64 encoded string. Pass it to your json object as is to send to your client
            
            //Kitura-SwiftyJSON object
            var json = JSON([:])
            json["imageData"].stringValue = imageData
        }
    })

Heres an example of how you would parse the image data if your client is an iOS app

//Get imageData from your json object
let imageString = json["imageData"] as! String

//Convert the base64 string imageData to Data instance
let imageData = Data(base64Encoded: imageString, options: Data.Base64DecodingOptions.init(rawValue: 0))

//Use Data instance in UIImage constructor
let image = UIImage(data: imageData!)!

//Profit
self.imageView.image = image

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.1.0 - Mar 24, 2017

1.0.9 - Mar 24, 2017

1.0.8 - Mar 24, 2017

1.0.7 - Mar 22, 2017

1.0.6 - Mar 21, 2017