Skip to content

Commit

Permalink
Fixed some swiftlint warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
DAVID Amaury committed Aug 16, 2019
1 parent c9cafa2 commit 3eac873
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Examples/_shared/GitHubAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Moya
private func JSONResponseDataFormatter(_ data: Data) -> String {
do {
let dataAsJSON = try JSONSerialization.jsonObject(with: data)
let prettyData = try JSONSerialization.data(withJSONObject: dataAsJSON, options: .prettyPrinted)
return String(data:prettyData, encoding: .utf8) ?? String()
let prettyData = try JSONSerialization.data(withJSONObject: dataAsJSON, options: .prettyPrinted)
return String(data: prettyData, encoding: .utf8) ?? String()
} catch {
return String()
}
Expand Down
24 changes: 11 additions & 13 deletions Sources/Moya/Plugins/NetworkLoggerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class NetworkLoggerPlugin {
}
}

//MARK: - PluginType
// MARK: - PluginType
extension NetworkLoggerPlugin: PluginType {
public func willSend(_ request: RequestType, target: TargetType) {
configuration.output(target, logNetworkRequest(request, target: target))
Expand All @@ -27,15 +27,14 @@ extension NetworkLoggerPlugin: PluginType {
}
}

//MARK: - Logging
// MARK: - Logging
private extension NetworkLoggerPlugin {

func newEntry(identifier: String, message: String) -> String {
let date = configuration.dateFormatter.string(from: Date())
return "\(configuration.loggerId): [\(date)] \(identifier): \(message)"
}


func logNetworkRequest(_ request: RequestType, target: TargetType) -> [String] {

//cURL formatting
Expand Down Expand Up @@ -103,7 +102,6 @@ private extension NetworkLoggerPlugin {
return output
}


func logNetworkError(_ error: MoyaError, target: TargetType) -> [String] {
//Some errors will still have a response, like errors due to Alamofire's HTTP code validation.
if let moyaResponse = error.response {
Expand All @@ -115,7 +113,7 @@ private extension NetworkLoggerPlugin {
}
}

//MARK: - Configuration
// MARK: - Configuration
public extension NetworkLoggerPlugin {
struct Configuration {

Expand Down Expand Up @@ -174,24 +172,24 @@ public extension NetworkLoggerPlugin.Configuration {
public let rawValue: Int
public init(rawValue: Int) { self.rawValue = rawValue }

public static let method: RequestLogOptions = RequestLogOptions(rawValue: 1 << 0)
public static let body: RequestLogOptions = RequestLogOptions(rawValue: 1 << 1)
public static let headers: RequestLogOptions = RequestLogOptions(rawValue: 1 << 2)
public static let method: RequestLogOptions = RequestLogOptions(rawValue: 1 << 0)
public static let body: RequestLogOptions = RequestLogOptions(rawValue: 1 << 1)
public static let headers: RequestLogOptions = RequestLogOptions(rawValue: 1 << 2)
public static let formatAscURL: RequestLogOptions = RequestLogOptions(rawValue: 1 << 3)

//Aggregate options
public static let `default`: RequestLogOptions = [method, headers]
public static let verbose: RequestLogOptions = [method, headers, body]
public static let `default`: RequestLogOptions = [method, headers]
public static let verbose: RequestLogOptions = [method, headers, body]
}

struct ResponseLogOptions: OptionSet {
public let rawValue: Int
public init(rawValue: Int) { self.rawValue = rawValue }

public static let body: ResponseLogOptions = ResponseLogOptions(rawValue: 1 << 0)
public static let body: ResponseLogOptions = ResponseLogOptions(rawValue: 1 << 0)

//Aggregate options
public static let `default`: ResponseLogOptions = []
public static let verbose: ResponseLogOptions = [body]
public static let `default`: ResponseLogOptions = []
public static let verbose: ResponseLogOptions = [body]
}
}

0 comments on commit 3eac873

Please sign in to comment.