universalis-swift

1.2.0

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

What's New

v1.2.0

2023-12-12T06:14:24Z

What's Changed

Full Changelog: v1.1.0...v1.2.0

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)
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 ?? "")")
})

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Dec 01 2024 10:01:43 GMT-1000 (Hawaii-Aleutian Standard Time)