Skip to content

Commit ff8b97e

Browse files
committed
Merge branch 'master' of github.com:audienceproject/userreport-ios-sdk
2 parents a606291 + d2e7cef commit ff8b97e

File tree

12 files changed

+286
-243
lines changed

12 files changed

+286
-243
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// String+Request.swift
3+
// UserReportSDK
4+
//
5+
// Created by Dmitriy on 15.09.2021.
6+
// Copyright © 2021 UserReport. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension String {
12+
13+
@inlinable static func / (lhs: String, rhs: String) -> String {
14+
lhs + "/" + rhs
15+
}
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Foundation
2+
3+
struct Request {
4+
5+
let httpMethod: HTTPMethod
6+
let urlString: String
7+
let headers: [String: String]?
8+
let body: [String: Any?]?
9+
10+
init(_ httpMethod: HTTPMethod = .GET, _ urlString: String, _ headers: [String: String]? = nil, body: [String: Any?]? = nil) {
11+
self.httpMethod = httpMethod
12+
self.urlString = urlString
13+
self.headers = headers
14+
self.body = body
15+
}
16+
17+
func build() throws -> URLRequest
18+
{
19+
guard let url = URL(string: urlString) else {
20+
// Track error
21+
throw URError.invalidURL(url: urlString)
22+
}
23+
24+
// Create request object
25+
var request = URLRequest(url: url)
26+
request.httpMethod = httpMethod.rawValue
27+
28+
// Set headers if needed
29+
headers?.forEach { key, value in
30+
request.addValue(value, forHTTPHeaderField: key)
31+
}
32+
33+
// Set body if needed
34+
if let data = body {
35+
request.httpBody = try JSONSerialization.data(withJSONObject: data, options: .prettyPrinted)
36+
}
37+
38+
return request
39+
}
40+
}

UserReport/UserReport/Models/SerializableObject.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ protocol SerializableObject {
1010
init(dict: [String: Any?]) throws
1111
}
1212

13-
1413
/// Use this struct when you expect empty response
1514
struct Empty: SerializableObject {
1615

0 commit comments

Comments
 (0)