Renamed package to CSFloatKit, added new models for CSM service
This commit is contained in:
parent
50f47087db
commit
d289a50bbe
|
@ -4,12 +4,12 @@
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "SWGOFloat",
|
name: "CSFloatKit",
|
||||||
products: [
|
products: [
|
||||||
// Products define the executables and libraries produced by a package, and make them visible to other packages.
|
// Products define the executables and libraries produced by a package, and make them visible to other packages.
|
||||||
.library(
|
.library(
|
||||||
name: "SWGOFloat",
|
name: "CSFloatKit",
|
||||||
targets: ["SWGOFloat"]),
|
targets: ["CSFloatKit"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// Dependencies declare other packages that this package depends on.
|
// Dependencies declare other packages that this package depends on.
|
||||||
|
@ -19,10 +19,10 @@ let package = Package(
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||||
.target(
|
.target(
|
||||||
name: "SWGOFloat",
|
name: "CSFloatKit",
|
||||||
dependencies: []),
|
dependencies: []),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "SWGOFloatTests",
|
name: "CSFloatKitTests",
|
||||||
dependencies: ["SWGOFloat"]),
|
dependencies: ["CSFloatKit"]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Tomas Martins on 24/01/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@objc public class CSMScreenshot: NSObject, NSCoding, Codable {
|
||||||
|
let status: Bool?
|
||||||
|
let cached: Bool?
|
||||||
|
let imageURL: String?
|
||||||
|
let previewURL: String?
|
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case status = "ok"
|
||||||
|
case cached
|
||||||
|
case imageURL = "img"
|
||||||
|
case previewURL = "preview"
|
||||||
|
}
|
||||||
|
|
||||||
|
//MARK: - NSCoding methods
|
||||||
|
public func encode(with coder: NSCoder) {
|
||||||
|
coder.encode(status, forKey: CodingKeys.status.rawValue)
|
||||||
|
coder.encode(cached, forKey: CodingKeys.cached.rawValue)
|
||||||
|
coder.encode(imageURL, forKey: CodingKeys.imageURL.rawValue)
|
||||||
|
coder.encode(previewURL, forKey: CodingKeys.previewURL.rawValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal init(status: Bool?, cached: Bool?, imageURL: String?, previewURL: String?) {
|
||||||
|
self.status = status
|
||||||
|
self.cached = cached
|
||||||
|
self.imageURL = imageURL
|
||||||
|
self.previewURL = previewURL
|
||||||
|
}
|
||||||
|
|
||||||
|
public required convenience init?(coder: NSCoder) {
|
||||||
|
let status = coder.decodeObject(forKey: CodingKeys.status.rawValue) as? Bool
|
||||||
|
let cached = coder.decodeObject(forKey: CodingKeys.cached.rawValue) as? Bool
|
||||||
|
let imageURL = coder.decodeObject(forKey: CodingKeys.imageURL.rawValue) as? String
|
||||||
|
let previewURL = coder.decodeObject(forKey: CodingKeys.previewURL.rawValue) as? String
|
||||||
|
self.init(status: status, cached: cached, imageURL: imageURL, previewURL: previewURL)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
//
|
||||||
|
// CSMSkin.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Tomas Martins on 24/01/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
// MARK: - CSMItem
|
||||||
|
internal struct CSMSkin: Codable {
|
||||||
|
internal init(item: CSMItem?, isBot: Bool = false, botInventory: Bool = false, isInGame: Bool = false) {
|
||||||
|
self.item = item
|
||||||
|
self.isBot = isBot
|
||||||
|
self.botInventory = botInventory
|
||||||
|
self.isInGame = isInGame
|
||||||
|
}
|
||||||
|
|
||||||
|
let item: CSMItem?
|
||||||
|
var isBot: Bool = false
|
||||||
|
var botInventory: Bool = false
|
||||||
|
var isInGame: Bool = false
|
||||||
|
|
||||||
|
public init?(skin: Skin) {
|
||||||
|
guard let inventoryParameter = skin.itemInfo?.inventoryParameter, Int(inventoryParameter) != 0 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let item = CSMItem(id: Int(inventoryParameter))
|
||||||
|
self = CSMSkin(item: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Item
|
||||||
|
struct CSMItem: Codable {
|
||||||
|
let id: Int?
|
||||||
|
}
|
|
@ -55,7 +55,7 @@ import Foundation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Extension
|
// MARK: - Properties
|
||||||
|
|
||||||
public extension Skin {
|
public extension Skin {
|
||||||
/// Boolean value indicating whether the skin is StatTrak
|
/// Boolean value indicating whether the skin is StatTrak
|
|
@ -12,7 +12,7 @@ import Foundation
|
||||||
var inspectLink: String?
|
var inspectLink: String?
|
||||||
/// Inspect link "s" parameter, if the item is from an player's inventory
|
/// Inspect link "s" parameter, if the item is from an player's inventory
|
||||||
var inventoryParameter: String?
|
var inventoryParameter: String?
|
||||||
/// Inspect link "a" parameter
|
/// Inspect link "a" parameter, which represents the link's assets
|
||||||
var aParameter: String?
|
var aParameter: String?
|
||||||
/// Inspect link "d" paramete
|
/// Inspect link "d" paramete
|
||||||
var dParameter: String?
|
var dParameter: String?
|
|
@ -50,7 +50,7 @@ import Foundation
|
||||||
|
|
||||||
/// Parses the fetched JSON
|
/// Parses the fetched JSON
|
||||||
/// - Parameter data: The data retrurned in the request
|
/// - Parameter data: The data retrurned in the request
|
||||||
public func parseJson(data: Data) {
|
private func parseJson(data: Data) {
|
||||||
do {
|
do {
|
||||||
let decodedObject = try self.parseData(data: data)
|
let decodedObject = try self.parseData(data: data)
|
||||||
if let errorCode = decodedObject.code {
|
if let errorCode = decodedObject.code {
|
||||||
|
@ -67,7 +67,7 @@ import Foundation
|
||||||
|
|
||||||
/// Parses the data feched in the request
|
/// Parses the data feched in the request
|
||||||
/// - Parameter data: The data returned in the request
|
/// - Parameter data: The data returned in the request
|
||||||
public func parseData(data: Data) throws -> Skin{
|
private func parseData(data: Data) throws -> Skin {
|
||||||
do {
|
do {
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder()
|
||||||
let decodedWebsites = try decoder.decode(Skin.self, from: data)
|
let decodedWebsites = try decoder.decode(Skin.self, from: data)
|
|
@ -1,7 +1,7 @@
|
||||||
import XCTest
|
import XCTest
|
||||||
@testable import SWGOFloat
|
@testable import CSFloatKit
|
||||||
|
|
||||||
final class SWGOFloatTests: XCTestCase {
|
final class CSFloatKitTests: XCTestCase {
|
||||||
|
|
||||||
func testWithInspectLink() {
|
func testWithInspectLink() {
|
||||||
let exp = expectation(description: "InspectLink")
|
let exp = expectation(description: "InspectLink")
|
Loading…
Reference in New Issue