/universalis-swift

simple swift client to easily work with the universalis.app api

Primary LanguageSwiftMIT LicenseMIT

universalis-swift

a simple swift client to easily work with the universalis.app api

Installation

Swift Package Manager

  1. Xcode -> File -> Add Package Dependency
  2. paste this repository url: https://github.com/Eisenhuth/universalis-swift.git
  3. Add Package

Swift Package

add this dependency to your Package.swift file

.package(url: "https://github.com/Eisenhuth/universalis-swift", branch: "master")

Usage

import Foundation
import universalis_swift

//create the client
let universalis = UniversalisClient()

//that's it, just call any of the instance methods from the client
let dataCenters = await universalis.getDataCenters()
let worlds = await universalis.getWorlds()
let taxRates = await universalis.getTaxRates(world: "Phoenix")

let listings = 5
let monthInSeconds = 86400 * 30
let itemIds = [2, 3, 4, 5]
let worldDcRegion = "Europe"

let single = await universalis.getCurrentData(worldDcRegion: worldDcRegion, itemId: 5).result
print("average price: \(single?.averagePrice.rounded() ?? 0) gil")

let multi = await universalis.getCurrentData(worldDcRegion: worldDcRegion, itemIds: itemIds).result
multi?.items?.values.forEach({
    print("\($0.itemID) - listings: \($0.listingsCount)")
})

want to use your own queries? use URLQueryItems!

let queryItems = [
    URLQueryItem(name: "listings", value: "\(listings)"),
    URLQueryItem(name: "entriesWithin", value: "\(monthInSeconds)")
]
let singleWithQueries = await universalis.getCurrentData(
    worldDcRegion: worldDcRegion,
    itemId: 5,
    queryItems: queryItems
).result

let multiWithQueries = await universalis.getCurrentData(
    worldDcRegion: worldDcRegion,
    itemIds: itemIds,
    queryItems: queryItems
).result

singleWithQueries?.listings?.forEach({ listing in
    print("\(listing.pricePerUnit) - \(listing.quantity) - \(listing.retainerCityName) - \(listing.worldName ?? "")")
})

multiWithQueries?.items?.first?.value.listings?.forEach({ listing in
    print("\(listing.pricePerUnit) - \(listing.quantity) - \(listing.retainerCityName) - \(listing.worldName ?? "")")
})