diff --git a/Package.swift b/Package.swift index 7e4e947..f1384b4 100644 --- a/Package.swift +++ b/Package.swift @@ -4,12 +4,12 @@ import PackageDescription let package = Package( - name: "SWGOFloat", + name: "CSFloatKit", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( - name: "SWGOFloat", - targets: ["SWGOFloat"]), + name: "CSFloatKit", + targets: ["CSFloatKit"]), ], dependencies: [ // 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 can depend on other targets in this package, and on products in packages which this package depends on. .target( - name: "SWGOFloat", + name: "CSFloatKit", dependencies: []), .testTarget( - name: "SWGOFloatTests", - dependencies: ["SWGOFloat"]), + name: "CSFloatKitTests", + dependencies: ["CSFloatKit"]), ] ) diff --git a/Sources/SWGOFloat/ApiError.swift b/Sources/CSFloatKit/ApiError.swift similarity index 100% rename from Sources/SWGOFloat/ApiError.swift rename to Sources/CSFloatKit/ApiError.swift diff --git a/Sources/SWGOFloat/Helpers/Rarity.swift b/Sources/CSFloatKit/Helpers/Rarity.swift similarity index 100% rename from Sources/SWGOFloat/Helpers/Rarity.swift rename to Sources/CSFloatKit/Helpers/Rarity.swift diff --git a/Sources/CSFloatKit/Model/CSMScreenshot.swift b/Sources/CSFloatKit/Model/CSMScreenshot.swift new file mode 100644 index 0000000..a1b2256 --- /dev/null +++ b/Sources/CSFloatKit/Model/CSMScreenshot.swift @@ -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) + } +} diff --git a/Sources/CSFloatKit/Model/CSMSkin.swift b/Sources/CSFloatKit/Model/CSMSkin.swift new file mode 100644 index 0000000..5f5d411 --- /dev/null +++ b/Sources/CSFloatKit/Model/CSMSkin.swift @@ -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? +} diff --git a/Sources/SWGOFloat/Model/ItemInfo.swift b/Sources/CSFloatKit/Model/ItemInfo.swift similarity index 100% rename from Sources/SWGOFloat/Model/ItemInfo.swift rename to Sources/CSFloatKit/Model/ItemInfo.swift diff --git a/Sources/SWGOFloat/Model/Skin.swift b/Sources/CSFloatKit/Model/Skin.swift similarity index 99% rename from Sources/SWGOFloat/Model/Skin.swift rename to Sources/CSFloatKit/Model/Skin.swift index 794fdc3..64261b8 100644 --- a/Sources/SWGOFloat/Model/Skin.swift +++ b/Sources/CSFloatKit/Model/Skin.swift @@ -55,7 +55,7 @@ import Foundation } } -// MARK: - Extension +// MARK: - Properties public extension Skin { /// Boolean value indicating whether the skin is StatTrak diff --git a/Sources/SWGOFloat/Model/Sticker.swift b/Sources/CSFloatKit/Model/Sticker.swift similarity index 100% rename from Sources/SWGOFloat/Model/Sticker.swift rename to Sources/CSFloatKit/Model/Sticker.swift diff --git a/Sources/SWGOFloat/SWGOConfiguration.swift b/Sources/CSFloatKit/SWGOConfiguration.swift similarity index 96% rename from Sources/SWGOFloat/SWGOConfiguration.swift rename to Sources/CSFloatKit/SWGOConfiguration.swift index e7e0493..f764987 100644 --- a/Sources/SWGOFloat/SWGOConfiguration.swift +++ b/Sources/CSFloatKit/SWGOConfiguration.swift @@ -12,7 +12,7 @@ import Foundation var inspectLink: String? /// Inspect link "s" parameter, if the item is from an player's inventory var inventoryParameter: String? - /// Inspect link "a" parameter + /// Inspect link "a" parameter, which represents the link's assets var aParameter: String? /// Inspect link "d" paramete var dParameter: String? diff --git a/Sources/SWGOFloat/SWGORequester.swift b/Sources/CSFloatKit/SWGORequester.swift similarity index 96% rename from Sources/SWGOFloat/SWGORequester.swift rename to Sources/CSFloatKit/SWGORequester.swift index 78ff436..a4b3264 100644 --- a/Sources/SWGOFloat/SWGORequester.swift +++ b/Sources/CSFloatKit/SWGORequester.swift @@ -50,7 +50,7 @@ import Foundation /// Parses the fetched JSON /// - Parameter data: The data retrurned in the request - public func parseJson(data: Data) { + private func parseJson(data: Data) { do { let decodedObject = try self.parseData(data: data) if let errorCode = decodedObject.code { @@ -67,7 +67,7 @@ import Foundation /// Parses the data feched 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 { let decoder = JSONDecoder() let decodedWebsites = try decoder.decode(Skin.self, from: data) diff --git a/Tests/SWGOFloatTests/SWGOFloatTests.swift b/Tests/CSFloatKitTests/CSFloatKitTests.swift similarity index 95% rename from Tests/SWGOFloatTests/SWGOFloatTests.swift rename to Tests/CSFloatKitTests/CSFloatKitTests.swift index beb1aa2..6e5841b 100644 --- a/Tests/SWGOFloatTests/SWGOFloatTests.swift +++ b/Tests/CSFloatKitTests/CSFloatKitTests.swift @@ -1,7 +1,7 @@ import XCTest -@testable import SWGOFloat +@testable import CSFloatKit -final class SWGOFloatTests: XCTestCase { +final class CSFloatKitTests: XCTestCase { func testWithInspectLink() { let exp = expectation(description: "InspectLink") diff --git a/Tests/SWGOFloatTests/XCTestManifests.swift b/Tests/CSFloatKitTests/XCTestManifests.swift similarity index 100% rename from Tests/SWGOFloatTests/XCTestManifests.swift rename to Tests/CSFloatKitTests/XCTestManifests.swift