<commit_before>//
//  Request.swift
//  SimpleRESTLayer
//
//  Created by <NAME> on 13/03/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation


public struct Request {
    // MARK: - Enums
    public enum HTTPMethod: String {
        case get = "GET"
        case post = "POST"
    }
    
    
    // MARK: - Methods
    public static func with(method: HTTPMethod, address: String, headers: [String: String]? = nil, parameters: [String: String]? = nil, body: [String: String]? = nil) -> URLRequest
    {
        guard var urlComponents = URLComponents(string: address) else { fatalError("Unable to build components") }
        if let parameters = parameters {
            urlComponents.queryItems = [URLQueryItem]()
            
            for (name, value) in parameters {
                let queryItem = URLQueryItem(name: name, value: value)
                urlComponents.queryItems?.append(queryItem)
            }
        }
        
        guard let URL = urlComponents.url else { fatalError("Unable to build URL") }
        
        let request = NSMutableURLRequest(url: URL)
        switch method {
        case .get:
            request.httpMethod = HTTPMethod.get.rawValue
        case .post:
            request.httpMethod = HTTPMethod.post.rawValue
        }
        
        if let headers = headers {
            for (field, value) in headers {
                request.addValue(value, forHTTPHeaderField: field)
            }
        }
        
        if let body = body {<commit_msg>Disable cyclomatic complexity swiftlint rule<commit_after>//
//  Request.swift
//  SimpleRESTLayer
//
//  Created by <NAME> on 13/03/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation


public struct Request {
    // MARK: - Enums
    public enum HTTPMethod: String {
        case get = "GET"
        case post = "POST"
    }
    
    
    // MARK: - Methods
    // swiftlint:disable cyclomatic_complexity
    static func with(method: HTTPMethod, address: String, headers: [String: String]? = nil, parameters: [String: String]? = nil, body: [String: String]? = nil) -> URLRequest
    // swiftlint:enable cyclomatic_complexity
    {
        guard var urlComponents = URLComponents(string: address) else { fatalError("Unable to build components") }
        if let parameters = parameters {
            urlComponents.queryItems = [URLQueryItem]()
            
            for (name, value) in parameters {
                let queryItem = URLQueryItem(name: name, value: value)
                urlComponents.queryItems?.append(queryItem)
            }
        }
        
        guard let URL = urlComponents.url else { fatalError("Unable to build URL") }
        
        let request = NSMutableURLRequest(url: URL)
        switch method {
        case .get:
            request.httpMethod = HTTPMethod.get.rawValue
        case .post:
            request.httpMethod = HTTPMethod.post.rawValue
        }
        
        if let headers = headers {
            for (field, value) in headers {
                request.addValue(value, forHTTPHeaderField: field)
            }
        }
        
        if let body = body {
{'fraction_non_alphanumeric': 0.09713024282560706, 'fraction_numerical': 0.007568590350047304, 'mean_word_length': 1.8836363636363636, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6692286', 'n_tokens_mistral': 879, 'n_tokens_neox': 833, 'n_words': 249}