<commit_before>//
//  DeliveryClient.swift
//  KenticoCloud
//
//  Created by <NAME> on 15/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import AlamofireObjectMapper
import Alamofire
import ObjectMapper

/// DeliveryClient is the main class repsonsible for getting items from Delivery API.
public class DeliveryClient {
    
    private var projectId: String
    private var previewApiKey: String?
    private var secureApiKey: String?
    private var headers: HTTPHeaders?
    private var isDebugLoggingEnabled: Bool
    private var isRetryEnabled: Bool
    private var maxRetryAttempts: Int
    
    /**
     Inits delivery client instance.
     Requests Preview API if previewApiKey is specified, otherwise requests Live API.
     
     - Parameter projectId: Identifier of the project.
     - Parameter previewApiKey: Preview API key for the project.
     - Parameter secureApiKey: Secure API key for the project.
     - Parameter enableDebugLogging: Flag for logging debug messages.
     - Returns: Instance of the DeliveryClient.
     */
    public init(projectId: String, previewApiKey: String? = nil, secureApiKey: String? = nil, enableDebugLogging: Bool = false,
                isRetryEnabled: Bool = true, maxRetryAttempts: Int = 5) {
        self.projectId = projectId
        self.previewApiKey = previewApiKey
        self.secureApiKey = secureApiKey
        self.isDebugLoggingEnabled = enableDebugLogging
        self.isRetryEnabled = isRetryEnabled
        self.maxRetryAttempts = maxRetryAttempts
        self.headers = getHeaders()
    }

    public func setRetryAttribute(isRetryEnabled enabled: Bool, maxRetryAttempts attempts: Int) {
        self.isRetryEnabled = enabled
        self.maxRetryAttempts = attempts
    }
    
    /**
     Gets multiple items from Delivery service.
     Suitable for strongly typed query.
     
     - Parameter modelType: Type of the requested items. Type must conform to Mappable protocol.<commit_msg>reject negative retry attempts<commit_after>//
//  DeliveryClient.swift
//  KenticoCloud
//
//  Created by <NAME> on 15/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import AlamofireObjectMapper
import Alamofire
import ObjectMapper

/// DeliveryClient is the main class repsonsible for getting items from Delivery API.
public class DeliveryClient {
    
    private var projectId: String
    private var previewApiKey: String?
    private var secureApiKey: String?
    private var headers: HTTPHeaders?
    private var isDebugLoggingEnabled: Bool
    private var isRetryEnabled: Bool
    private var maxRetryAttempts: Int
    
    /**
     Inits delivery client instance.
     Requests Preview API if previewApiKey is specified, otherwise requests Live API.
     
     - Parameter projectId: Identifier of the project.
     - Parameter previewApiKey: Preview API key for the project.
     - Parameter secureApiKey: Secure API key for the project.
     - Parameter enableDebugLogging: Flag for logging debug messages.
     - Returns: Instance of the DeliveryClient.
     */
    public init(projectId: String, previewApiKey: String? = nil, secureApiKey: String? = nil, enableDebugLogging: Bool = false,
                isRetryEnabled: Bool = true, maxRetryAttempts: Int = 5) {
        self.projectId = projectId
        self.previewApiKey = previewApiKey
        self.secureApiKey = secureApiKey
        self.isDebugLoggingEnabled = enableDebugLogging
        self.isRetryEnabled = isRetryEnabled
        self.maxRetryAttempts = maxRetryAttempts
        self.headers = getHeaders()
        if (maxRetryAttempts < 0) {
            self.maxRetryAttempts = 0
        }
    }

    public func setRetryAttribute(isRetryEnabled enabled: Bool, maxRetryAttempts attempts: Int) {
        self.isRetryEnabled = enabled
        self.maxRetryAttempts = attempts
        if (attempts < 0) {
            self.maxRetryAttempts = 0
        }
    }
    
    /**
     Gets multiple items from Delivery service.
     Suitable for strongly typed query.
     
     - Parameter modelType: Type of the requested items. Type must conform to Mappable protocol.
{'fraction_non_alphanumeric': 0.06354596167838952, 'fraction_numerical': 0.007276255154014068, 'mean_word_length': 2.839851024208566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7056376', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1097, 'n_words': 374}