a simple swift client to easily work with the universalis.app api
- Xcode -> File -> Add Package Dependency
- paste this repository url:
https://github.com/Eisenhuth/universalis-swift.git
- Add Package
add this dependency to your Package.swift
file
.package(url: "https://github.com/Eisenhuth/universalis-swift", branch: "master")
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)
print("average price: \(single?.averagePrice.rounded() ?? 0) gil")
let multi = await universalis.getCurrentData(worldDcRegion: worldDcRegion, itemIds: itemIds)
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
)
let multiWithQueries = await universalis.getCurrentData(
worldDcRegion: worldDcRegion,
itemIds: itemIds,
queryItems: queryItems
)
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 ?? "")")
})