Skip to content

Commit

Permalink
Merge pull request #686 from StepicOrg/release/1.118
Browse files Browse the repository at this point in the history
Release 1.118
  • Loading branch information
ivan-magda authored Apr 2, 2020
2 parents bed6b1c + d191721 commit 1142ad3
Show file tree
Hide file tree
Showing 88 changed files with 1,114 additions and 938 deletions.
121 changes: 45 additions & 76 deletions Alamofire-SwiftyJSON.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
//
// AlamofireSwiftyJSON.swift
// AlamofireSwiftyJSON
//
// Created by Hikaru on 2016/01/29.
// Copyright © 2016年 Hikaru. All rights reserved.
//
import Alamofire
import Foundation
import SwiftyJSON

/// A set of HTTP response status code that do not contain response data.
private let emptyDataStatusCodes: Set<Int> = [204, 205]

// MARK: - Request for SwiftyJSON
// MARK: SwiftyJSON Response Serializer -

public final class SwiftyJSONResponseSerializer: ResponseSerializer {
private let jsonResponseSerializer: JSONResponseSerializer

public init(
dataPreprocessor: DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
options: JSONSerialization.ReadingOptions = .allowFragments
) {
self.jsonResponseSerializer = JSONResponseSerializer(
dataPreprocessor: dataPreprocessor,
emptyResponseCodes: emptyResponseCodes,
emptyRequestMethods: emptyRequestMethods,
options: options
)
}

extension DataRequest {
/// Creates a response serializer that
/// returns a SwiftyJSON object result type constructed from the response data using
/// `JSONSerialization` with the specified reading options.
///
/// - parameter options: The JSON serialization reading options. Defaults to `.allowFragments`.
///
/// - returns: A JSON object response serializer.
public static func serializeResponseSwiftyJSON(
options: JSONSerialization.ReadingOptions = .allowFragments)
-> DataResponseSerializer<JSON> {
return DataResponseSerializer { _, response, data, error in
Request.serializeResponseSwiftyJSON(options: options,
response: response,
data: data,
error: error)
}
public func serialize(
request: URLRequest?,
response: HTTPURLResponse?,
data: Data?,
error: Error?
) throws -> JSON {
let json = try self.jsonResponseSerializer.serialize(
request: request,
response: response,
data: data,
error: error
)

return JSON(json)
}
}

// MARK: - Request for SwiftyJSON -

extension DataRequest {
/// Adds a handler to be called once the request has finished.
///
/// - parameter options:
Expand All @@ -41,54 +50,14 @@ extension DataRequest {
/// - returns: The request.
@discardableResult
public func responseSwiftyJSON(
queue: DispatchQueue? = nil,
queue: DispatchQueue = .main,
options: JSONSerialization.ReadingOptions = .allowFragments,
_ completionHandler: @escaping (DataResponse<JSON>) -> Void)
-> Self {
return response(
queue: queue,
responseSerializer: DataRequest.serializeResponseSwiftyJSON(options: options),
completionHandler: completionHandler
)
}
}

// MARK: - JSON

extension Request {
/// Returns a JSON object contained in a result type constructed
/// from the response data using `JSONSerialization`
/// with the specified reading options.
///
/// - parameter options: The JSON serialization reading options. Defaults to `.allowFragments`.
/// - parameter response: The response from the server.
/// - parameter data: The data returned from the server.
/// - parameter error: The error already encountered if it exists.
///
/// - returns: The result data type.
public static func serializeResponseSwiftyJSON(
options: JSONSerialization.ReadingOptions,
response: HTTPURLResponse?,
data: Data?,
error: Error?)
-> Alamofire.Result<JSON> {
guard error == nil else { return .failure(error!) }

if let response = response, emptyDataStatusCodes.contains(response.statusCode) {
return .success(JSON.null)
}

guard let validData = data, !validData.isEmpty else {
return .failure(AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength))
}

do {
let json = try JSONSerialization.jsonObject(with: validData, options: options)

return .success(JSON(json))
} catch {
return .failure(AFError.responseSerializationFailed(
reason: .jsonSerializationFailed(error: error)))
}
_ completionHandler: @escaping (AFDataResponse<JSON>) -> Void
) -> Self {
self.response(
queue: queue,
responseSerializer: SwiftyJSONResponseSerializer(options: options),
completionHandler: completionHandler
)
}
}
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"
ruby "2.6.5"

gem "fastlane", "2.143.0"
gem "fastlane", "2.144.0"
gem "cocoapods", "1.9.1"

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
Expand Down
28 changes: 17 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ GEM
json (>= 1.5.1)
atomos (0.1.3)
aws-eventstream (1.0.3)
aws-sdk (2.11.463)
aws-sdk-resources (= 2.11.463)
aws-sdk-core (2.11.463)
aws-sigv4 (~> 1.0)
aws-partitions (1.288.0)
aws-sdk-core (3.92.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-resources (2.11.463)
aws-sdk-core (= 2.11.463)
aws-sdk-kms (1.30.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.61.1)
aws-sdk-core (~> 3, >= 3.83.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.1)
aws-eventstream (~> 1.0, >= 1.0.2)
babosa (1.0.3)
Expand Down Expand Up @@ -77,7 +83,7 @@ GEM
escape (0.0.4)
ethon (0.12.0)
ffi (>= 1.3.0)
excon (0.72.0)
excon (0.73.0)
faraday (0.17.3)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
Expand All @@ -86,10 +92,10 @@ GEM
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.7)
fastlane (2.143.0)
fastlane (2.144.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
aws-sdk (~> 2.3)
aws-sdk-s3 (~> 1.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 3.0.0)
colored
Expand Down Expand Up @@ -190,7 +196,7 @@ GEM
ruby-macho (1.4.0)
rubyzip (1.3.0)
security (0.1.3)
signet (0.13.0)
signet (0.13.2)
addressable (~> 2.3)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.5, < 3.0)
Expand Down Expand Up @@ -233,7 +239,7 @@ PLATFORMS

DEPENDENCIES
cocoapods (= 1.9.1)
fastlane (= 2.143.0)
fastlane (= 2.144.0)
fastlane-plugin-firebase_app_distribution

RUBY VERSION
Expand Down
14 changes: 7 additions & 7 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inhibit_all_warnings!
use_frameworks!

def shared_pods
pod 'Alamofire', '4.9.1'
pod 'Alamofire', '5.0.5'
pod 'Atributika', '4.9.5'
pod 'SwiftyJSON', '5.0.0'
pod 'SDWebImage', '5.6.1'
Expand All @@ -29,10 +29,10 @@ def all_pods
pod 'SnapKit', '5.0.1'

# Firebase
pod 'Firebase/Core', '6.19.0'
pod 'Firebase/Messaging' , '6.19.0'
pod 'Firebase/Analytics' , '6.19.0'
pod 'Firebase/RemoteConfig', '6.19.0'
pod 'Firebase/Core', '6.21.0'
pod 'Firebase/Messaging' , '6.21.0'
pod 'Firebase/Analytics' , '6.21.0'
pod 'Firebase/RemoteConfig', '6.21.0'

pod 'YandexMobileMetrica/Dynamic', '3.9.4'
pod 'Amplitude-iOS', '4.9.3'
Expand All @@ -53,15 +53,15 @@ def all_pods

pod 'Presentr', '1.9'

pod 'Agrume', '5.6.5'
pod 'Agrume', '5.6.7'
pod 'Highlightr', '2.1.0'
pod 'TTTAttributedLabel', '2.0.0'
pod 'lottie-ios', '2.5.3'
pod 'Koloda', '5.0'
pod 'Charts', '3.4.0'
pod 'EasyTipView', '2.0.4'
pod 'ActionSheetPicker-3.0', '2.4.0'
pod 'Nuke', '8.3.1'
pod 'Nuke', '8.4.1'
pod 'STRegex', '2.1.1'
pod 'Tabman', '2.8.0'
pod 'SwiftDate', '6.1.0'
Expand Down
Loading

0 comments on commit 1142ad3

Please sign in to comment.