Skip to content

Commit 65345e7

Browse files
committed
Added http client Alamofire
1 parent 2f33141 commit 65345e7

File tree

11 files changed

+203
-6
lines changed

11 files changed

+203
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pods

Podfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Uncomment the next line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
target 'SimpleJwt' do
5+
# Comment the next line if you don't want to use dynamic frameworks
6+
use_frameworks!
7+
8+
# Pods for SimpleJwt
9+
pod 'Alamofire'
10+
11+
end

Podfile.lock

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
PODS:
2+
- Alamofire (5.8.0)
3+
4+
DEPENDENCIES:
5+
- Alamofire
6+
7+
SPEC REPOS:
8+
trunk:
9+
- Alamofire
10+
11+
SPEC CHECKSUMS:
12+
Alamofire: 0e92e751b3e9e66d7982db43919d01f313b8eb91
13+
14+
PODFILE CHECKSUM: 5e87a8159e5be0a9d9c3f9a6e3a7bd965bbf2cff
15+
16+
COCOAPODS: 1.12.1

SimpleJwt.xcodeproj/project.pbxproj

+74
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,64 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
40B96796276056CC525C8BAB /* Pods_SimpleJwt.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E66E1850F157B804A9D13B4 /* Pods_SimpleJwt.framework */; };
1011
FD838FE02AD6A023007AFC5F /* SimpleJwtApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD838FDF2AD6A023007AFC5F /* SimpleJwtApp.swift */; };
1112
FD838FE22AD6A023007AFC5F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD838FE12AD6A023007AFC5F /* ContentView.swift */; };
1213
FD838FE42AD6A025007AFC5F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FD838FE32AD6A025007AFC5F /* Assets.xcassets */; };
1314
FD838FE72AD6A025007AFC5F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FD838FE62AD6A025007AFC5F /* Preview Assets.xcassets */; };
1415
FD838FEF2AD6A273007AFC5F /* JWTDecode.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD838FEE2AD6A273007AFC5F /* JWTDecode.swift */; };
16+
FDC7B7552AD6C16F0092F443 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC7B7542AD6C16F0092F443 /* NetworkManager.swift */; };
1517
/* End PBXBuildFile section */
1618

1719
/* Begin PBXFileReference section */
20+
0E66E1850F157B804A9D13B4 /* Pods_SimpleJwt.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SimpleJwt.framework; sourceTree = BUILT_PRODUCTS_DIR; };
21+
5905EE7295D5103C7FEF48E1 /* Pods-SimpleJwt.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleJwt.debug.xcconfig"; path = "Target Support Files/Pods-SimpleJwt/Pods-SimpleJwt.debug.xcconfig"; sourceTree = "<group>"; };
22+
946986DEF817FAA5BD036987 /* Pods-SimpleJwt.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleJwt.release.xcconfig"; path = "Target Support Files/Pods-SimpleJwt/Pods-SimpleJwt.release.xcconfig"; sourceTree = "<group>"; };
1823
FD838FDC2AD6A023007AFC5F /* SimpleJwt.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleJwt.app; sourceTree = BUILT_PRODUCTS_DIR; };
1924
FD838FDF2AD6A023007AFC5F /* SimpleJwtApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleJwtApp.swift; sourceTree = "<group>"; };
2025
FD838FE12AD6A023007AFC5F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
2126
FD838FE32AD6A025007AFC5F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2227
FD838FE62AD6A025007AFC5F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2328
FD838FEE2AD6A273007AFC5F /* JWTDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWTDecode.swift; sourceTree = "<group>"; };
29+
FDC7B7542AD6C16F0092F443 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
2430
/* End PBXFileReference section */
2531

2632
/* Begin PBXFrameworksBuildPhase section */
2733
FD838FD92AD6A023007AFC5F /* Frameworks */ = {
2834
isa = PBXFrameworksBuildPhase;
2935
buildActionMask = 2147483647;
3036
files = (
37+
40B96796276056CC525C8BAB /* Pods_SimpleJwt.framework in Frameworks */,
3138
);
3239
runOnlyForDeploymentPostprocessing = 0;
3340
};
3441
/* End PBXFrameworksBuildPhase section */
3542

3643
/* Begin PBXGroup section */
44+
4298FE78527C20D6497D047D /* Pods */ = {
45+
isa = PBXGroup;
46+
children = (
47+
5905EE7295D5103C7FEF48E1 /* Pods-SimpleJwt.debug.xcconfig */,
48+
946986DEF817FAA5BD036987 /* Pods-SimpleJwt.release.xcconfig */,
49+
);
50+
path = Pods;
51+
sourceTree = "<group>";
52+
};
53+
7B704313159E613B4AA813DC /* Frameworks */ = {
54+
isa = PBXGroup;
55+
children = (
56+
0E66E1850F157B804A9D13B4 /* Pods_SimpleJwt.framework */,
57+
);
58+
name = Frameworks;
59+
sourceTree = "<group>";
60+
};
3761
FD838FD32AD6A023007AFC5F = {
3862
isa = PBXGroup;
3963
children = (
4064
FD838FDE2AD6A023007AFC5F /* SimpleJwt */,
4165
FD838FDD2AD6A023007AFC5F /* Products */,
66+
4298FE78527C20D6497D047D /* Pods */,
67+
7B704313159E613B4AA813DC /* Frameworks */,
4268
);
4369
sourceTree = "<group>";
4470
};
@@ -74,6 +100,7 @@
74100
isa = PBXGroup;
75101
children = (
76102
FD838FEE2AD6A273007AFC5F /* JWTDecode.swift */,
103+
FDC7B7542AD6C16F0092F443 /* NetworkManager.swift */,
77104
);
78105
path = Utils;
79106
sourceTree = "<group>";
@@ -85,9 +112,11 @@
85112
isa = PBXNativeTarget;
86113
buildConfigurationList = FD838FEA2AD6A025007AFC5F /* Build configuration list for PBXNativeTarget "SimpleJwt" */;
87114
buildPhases = (
115+
3CB5F154D1FF25100DA3B3EE /* [CP] Check Pods Manifest.lock */,
88116
FD838FD82AD6A023007AFC5F /* Sources */,
89117
FD838FD92AD6A023007AFC5F /* Frameworks */,
90118
FD838FDA2AD6A023007AFC5F /* Resources */,
119+
E012CFB89A17A4380D4B11E6 /* [CP] Embed Pods Frameworks */,
91120
);
92121
buildRules = (
93122
);
@@ -143,11 +172,54 @@
143172
};
144173
/* End PBXResourcesBuildPhase section */
145174

175+
/* Begin PBXShellScriptBuildPhase section */
176+
3CB5F154D1FF25100DA3B3EE /* [CP] Check Pods Manifest.lock */ = {
177+
isa = PBXShellScriptBuildPhase;
178+
buildActionMask = 2147483647;
179+
files = (
180+
);
181+
inputFileListPaths = (
182+
);
183+
inputPaths = (
184+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
185+
"${PODS_ROOT}/Manifest.lock",
186+
);
187+
name = "[CP] Check Pods Manifest.lock";
188+
outputFileListPaths = (
189+
);
190+
outputPaths = (
191+
"$(DERIVED_FILE_DIR)/Pods-SimpleJwt-checkManifestLockResult.txt",
192+
);
193+
runOnlyForDeploymentPostprocessing = 0;
194+
shellPath = /bin/sh;
195+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
196+
showEnvVarsInLog = 0;
197+
};
198+
E012CFB89A17A4380D4B11E6 /* [CP] Embed Pods Frameworks */ = {
199+
isa = PBXShellScriptBuildPhase;
200+
buildActionMask = 2147483647;
201+
files = (
202+
);
203+
inputFileListPaths = (
204+
"${PODS_ROOT}/Target Support Files/Pods-SimpleJwt/Pods-SimpleJwt-frameworks-${CONFIGURATION}-input-files.xcfilelist",
205+
);
206+
name = "[CP] Embed Pods Frameworks";
207+
outputFileListPaths = (
208+
"${PODS_ROOT}/Target Support Files/Pods-SimpleJwt/Pods-SimpleJwt-frameworks-${CONFIGURATION}-output-files.xcfilelist",
209+
);
210+
runOnlyForDeploymentPostprocessing = 0;
211+
shellPath = /bin/sh;
212+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SimpleJwt/Pods-SimpleJwt-frameworks.sh\"\n";
213+
showEnvVarsInLog = 0;
214+
};
215+
/* End PBXShellScriptBuildPhase section */
216+
146217
/* Begin PBXSourcesBuildPhase section */
147218
FD838FD82AD6A023007AFC5F /* Sources */ = {
148219
isa = PBXSourcesBuildPhase;
149220
buildActionMask = 2147483647;
150221
files = (
222+
FDC7B7552AD6C16F0092F443 /* NetworkManager.swift in Sources */,
151223
FD838FE22AD6A023007AFC5F /* ContentView.swift in Sources */,
152224
FD838FEF2AD6A273007AFC5F /* JWTDecode.swift in Sources */,
153225
FD838FE02AD6A023007AFC5F /* SimpleJwtApp.swift in Sources */,
@@ -273,6 +345,7 @@
273345
};
274346
FD838FEB2AD6A025007AFC5F /* Debug */ = {
275347
isa = XCBuildConfiguration;
348+
baseConfigurationReference = 5905EE7295D5103C7FEF48E1 /* Pods-SimpleJwt.debug.xcconfig */;
276349
buildSettings = {
277350
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
278351
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
@@ -301,6 +374,7 @@
301374
};
302375
FD838FEC2AD6A025007AFC5F /* Release */ = {
303376
isa = XCBuildConfiguration;
377+
baseConfigurationReference = 946986DEF817FAA5BD036987 /* Pods-SimpleJwt.release.xcconfig */;
304378
buildSettings = {
305379
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
306380
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;

SimpleJwt.xcodeproj/xcuserdata/magomedcoder.xcuserdatad/xcschemes/xcschememanagement.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>SimpleJwt.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>0</integer>
10+
<integer>2</integer>
1111
</dict>
1212
</dict>
1313
</dict>

SimpleJwt.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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>

SimpleJwt/ContentView.swift

+33-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import SwiftUI
99

10-
func JWTTest(token: String){
10+
func JWTTest(token: String) -> Void {
1111
if let jwt = JWTDecode(token: token) {
1212
let header = jwt.header
1313
let payload = jwt.payload
@@ -25,13 +25,41 @@ func JWTTest(token: String){
2525
}
2626
}
2727

28+
struct LoginResponse: Codable {
29+
var access: String
30+
}
31+
32+
func onLogin() -> Void {
33+
let networkManager = NetworkManager.shared
34+
35+
let parameters: [String: Any] = [
36+
"username": "",
37+
"password": "",
38+
]
39+
40+
networkManager.post(path: "/api/login/", parameters: parameters) { result in
41+
switch result {
42+
case .success(let data):
43+
do {
44+
let res = try JSONDecoder().decode(LoginResponse.self, from: data)
45+
JWTTest(token: res.access)
46+
} catch {
47+
print(error)
48+
}
49+
case .failure(let error):
50+
print("Error: \(error)")
51+
}
52+
}
53+
}
54+
2855
struct ContentView: View {
29-
3056
var body: some View {
3157
VStack {
32-
let _: () = JWTTest(token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjk3MTM0MDg4LCJpYXQiOjE2OTcwMTQwODgsImp0aSI6ImExMzc1MThhYWNmNDQ2MzRiNWFmZWY2N2I0ZWNjMjAwIiwidXNlcl9pZCI6M30.Y7vFwlWjoCbUWTfQAwRKfVhhjekQ3SS7DEebkwujkGc")
33-
34-
Text("Test")
58+
Button(action: {
59+
onLogin()
60+
}) {
61+
Text("Test")
62+
}
3563
}
3664
}
3765
}

SimpleJwt/Utils/NetworkManager.swift

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// NetworkManager.swift
3+
// SimpleJwt
4+
//
5+
// Created by Magomedcoder on 11.10.2023.
6+
//
7+
8+
import Alamofire
9+
10+
class NetworkManager {
11+
static let shared = NetworkManager()
12+
13+
private let baseURL = ""
14+
private var session: Session
15+
16+
private init() {
17+
session = Session()
18+
}
19+
20+
private func fullURL(forPath path: String) -> URL {
21+
if let url = URL(string: baseURL + path) {
22+
return url
23+
}
24+
fatalError("Invalid URL")
25+
}
26+
27+
private func performRequest(url: URL, method: HTTPMethod, parameters: [String: Any]?, completion: @escaping (Result<Data, Error>) -> Void) {
28+
session.request(url, method: method, parameters: parameters)
29+
.validate()
30+
.responseData {[weak self] response in
31+
switch response.result {
32+
case .success(let data):
33+
completion(.success(data))
34+
case .failure(let error):
35+
print(error)
36+
}
37+
}
38+
}
39+
40+
func post(
41+
path: String,
42+
parameters: [String: Any]?,
43+
completion: @escaping (Result<Data, Error>) -> Void
44+
) {
45+
let url = fullURL(forPath: path)
46+
performRequest(url: url, method: .post, parameters: parameters, completion: completion)
47+
}
48+
49+
}

0 commit comments

Comments
 (0)