Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 1e26aef

Browse files
committed
Will use json instead of data in next version.
0 parents  commit 1e26aef

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version:5.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "fortnite-api",
8+
products: [
9+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
10+
.library(
11+
name: "fortnite-api",
12+
targets: ["fortnite-api"]),
13+
],
14+
dependencies: [
15+
// Dependencies declare other packages that this package depends on.
16+
// .package(url: /* package url */, from: "1.0.0"),
17+
],
18+
targets: [
19+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20+
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
21+
.target(
22+
name: "fortnite-api",
23+
dependencies: []),
24+
.testTarget(
25+
name: "fortnite-apiTests",
26+
dependencies: ["fortnite-api"]),
27+
]
28+
)

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div align="center">
2+
3+
# Swift wrapper for [Fortnite-API.com](https://fortnite-api.com)
4+
5+
</div>
6+
7+
This repository offers an request API around the endpoints of [fortnite-api.com](https://fortnite-api.com).
8+
9+
## Installation
10+
11+
For now you have to install the source code but it will be uploaded to CocoaPods soon.
12+
13+
## Example
14+
15+
```swift
16+
import fortnite_api
17+
18+
let cosmetic = fortnite_api.searchCosmetics(parameters: "name", value: "Renegade")
19+
print(cosmetic.id)
20+
```
21+
22+
## Documentation
23+
24+
To see the full documentation for this gem, please visit the [wiki](https://github.com/Fortnite-API/ruby-wrapper/wiki)
25+
26+
## License
27+
28+
Fortnite-API (MIT) [License](https://github.com/Fortnite-API/ruby-wrapper/blob/master/LICENSE "MIT License")
29+
30+
API developed by [Fortnite-API.com](https://fortnite-api.com/about)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import Foundation
2+
3+
public struct Cosmetic: Codable {
4+
let id: String
5+
let type: String
6+
let backendType: String
7+
let rarity: String
8+
let displayRarity: String
9+
let backendRarity: String
10+
let name: String
11+
let shortDescription: String
12+
let description: String
13+
let images: String
14+
let gameplayTags: String
15+
let displayAssetPath: String
16+
let definition: String
17+
let path: String
18+
let lastUpdate: String
19+
let added: String
20+
}
21+
22+
func fnapi_get(endpoint: String, xapikey: String) -> (Data, URLResponse?) {
23+
let url = URL(string: "https://fortnite-api.com/\(endpoint)")
24+
var request = URLRequest(url: url!)
25+
request.setValue(xapikey, forHTTPHeaderField: "x-api-key")
26+
27+
let semaphore = DispatchSemaphore(value: 0)
28+
29+
var result: Data?
30+
var _response: URLResponse?
31+
32+
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
33+
result = data!
34+
_response = response
35+
semaphore.signal()
36+
}
37+
38+
task.resume()
39+
semaphore.wait()
40+
return (result!, _response)
41+
}
42+
43+
public struct fortnite_api {
44+
45+
public static func getShop(language: String, xapikey: String) -> (Data){
46+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "shop/br?language\(language)", xapikey: "\(xapikey)")
47+
return query.data
48+
}
49+
50+
public static func getCreatorCode(slug: String, xapikey: String) -> (Data){
51+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "creatorcode/search?slug=\(slug)", xapikey: "\(xapikey)")
52+
return query.data
53+
}
54+
55+
public static func getAllCosmetics(xapikey: String) -> (Data){
56+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "cosmetics/br", xapikey: "\(xapikey)")
57+
return query.data
58+
}
59+
60+
public static func searchCosmetics(parameters: String, value: String, xapikey: String) -> (Data){
61+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "cosmetics/br/search?\(parameters)=\(value)", xapikey: "\(xapikey)")
62+
return query.data
63+
64+
}
65+
66+
public static func searchAllCosmetics(parameters: String, value: String, xapikey: String) -> (Data){
67+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "cosmetics/br/search/all?\(parameters)=\(value)", xapikey: "\(xapikey)")
68+
return query.data
69+
}
70+
71+
public static func searchCosmeticIds(id: String, xapikey: String) -> (Data){
72+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "cosmetics/br/search/ids?id=\(id)", xapikey: "\(xapikey)")
73+
return query.data
74+
}
75+
76+
public static func getAllNews(xapikey: String) -> (Data){
77+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "news/", xapikey: "\(xapikey)")
78+
return query.data
79+
}
80+
81+
public static func getNews(gamemode: String, xapikey: String) -> (Data){
82+
let query: (data: Data, address: URLResponse?) = fnapi_get(endpoint: "news/\(gamemode)", xapikey: "\(xapikey)")
83+
return query.data
84+
}
85+
86+
}

0 commit comments

Comments
 (0)