<commit_before>//
//  AddCarTask.swift
//  CarsApp
//
//  Created by <NAME> on 01/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import RxSwift
import ObjectMapper

struct CarBodyParameters {
    let name: String
    let brand: String
    let model: String
    let year: String

    init(name: String,
         brand: String,
         model: String,
         year: String) {

        self.name = name
        self.brand = brand
        self.model = model
        self.year = year
    }
}

final class AddCarTask: BaseCarsTask<CarBodyParameters, CarCreateModelResponse> {
    typealias ContentResponse = Dictionary<String, Any>

    override func perform(_ input: CarBodyParameters) -> Observable<CarCreateModelResponse> {
        let dispatcher = self.dispatcher

        let recognizer: ((Any) throws -> ContentResponse) = { response in
            if let content = response as? ContentResponse {
                return content
            }

            throw RestCarsServiceError.invalidResponse
        }

        let mapper: ((ContentResponse) throws -> CarCreateModelResponse) = { content in
            let model = Mapper<CarCreateModelResponse>().map(JSONObject: content)

            switch model {
            case .some(let result): return result
            case .none: throw RestCarsServiceError.invalidResponse
            }
        }

        let parameters = createParameters(input)
        let completion: ((BaseCarsRequest) -> Void) = { request in
            request.parameters = parameters
        }

        return createRequest(endpoint: .cars, completion: completion)
            .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
            .flatMap { dispatcher.execute($0) }
            .map(recognizer)
            .map(mapper)
            .observeOn(MainScheduler.asyncInstance)
    }

    private func createParameters(_ model: CarBodyParameters) -> Parameters {
        return [
            "name" : model.name,
            "model" : model.model,
            "brand" : model.brand,
            "year" : model.year
        ]
    }

}<commit_msg>Added post method parameter for add task.<commit_after>//
//  AddCarTask.swift
//  CarsApp
//
//  Created by <NAME> on 01/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import RxSwift
import ObjectMapper

struct CarBodyParameters {
    let name: String
    let brand: String
    let model: String
    let year: String

    init(name: String,
         brand: String,
         model: String,
         year: String) {

        self.name = name
        self.brand = brand
        self.model = model
        self.year = year
    }
}

final class AddCarTask: BaseCarsTask<CarBodyParameters, CarCreateModelResponse> {
    typealias ContentResponse = Dictionary<String, Any>

    override func perform(_ input: CarBodyParameters) -> Observable<CarCreateModelResponse> {
        let dispatcher = self.dispatcher

        let recognizer: ((Any) throws -> ContentResponse) = { response in
            if let content = response as? ContentResponse {
                return content
            }

            throw RestCarsServiceError.invalidResponse
        }

        let mapper: ((ContentResponse) throws -> CarCreateModelResponse) = { content in
            let model = Mapper<CarCreateModelResponse>().map(JSONObject: content)

            switch model {
            case .some(let result): return result
            case .none: throw RestCarsServiceError.invalidResponse
            }
        }

        let parameters = createParameters(input)
        let completion: ((BaseCarsRequest) -> Void) = { request in
            request.method = .post
            request.parameters = parameters
        }

        return createRequest(endpoint: .cars, completion: completion)
            .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
            .flatMap { dispatcher.execute($0) }
            .map(recognizer)
            .map(mapper)
            .observeOn(MainScheduler.asyncInstance)
    }

    private func createParameters(_ model: CarBodyParameters) -> Parameters {
        return [
            "name" : model.name,
            "model" : model.model,
            "brand" : model.brand,
            "year" : model.year
        ]
    }

}
{'fraction_non_alphanumeric': 0.08924006507088078, 'fraction_numerical': 0.006042296072507553, 'mean_word_length': 2.0764832022873483, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2013426', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1097, 'n_words': 300}