<commit_before>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import ObjectMapper

// TODO: make sure the refreshed token is persistent (i.e. inout authStrategy)
// TODO: add support for keypath... (use AnyObject.valueForKeyPath() method)

/**
 A `WatsonGateway` is used to perform HTTP networking requests to Watson Developer
 Cloud services. The gateway automatically handles token authentication, refreshes
 expired tokens, and parses error responses.
 */
internal class WatsonGateway {
    
    // The shared WatsonGateway singleton.
    internal static let sharedInstance = WatsonGateway()
    
    // The type of cached requests.
    private typealias CachedRequest = Void -> Void
    
    // The collection of cached requests.
    private var cachedRequests = [CachedRequest]()
    
    // The maximum number of authentication retries before returning failure.
    private let maxRetries = 1
    
    // The shared NSURLSession singleton session.<commit_msg>Remove keypath comment from WatsonManager<commit_after>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import ObjectMapper

// TODO: make sure the refreshed token is persistent (i.e. inout authStrategy)

/**
 A `WatsonGateway` is used to perform HTTP networking requests to Watson Developer
 Cloud services. The gateway automatically handles token authentication, refreshes
 expired tokens, and parses error responses.
 */
internal class WatsonGateway {
    
    // The shared WatsonGateway singleton.
    internal static let sharedInstance = WatsonGateway()
    
    // The type of cached requests.
    private typealias CachedRequest = Void -> Void
    
    // The collection of cached requests.
    private var cachedRequests = [CachedRequest]()
    
    // The maximum number of authentication retries before returning failure.
    private let maxRetries = 1
    
    // The shared NSURLSession singleton session.
{'fraction_non_alphanumeric': 0.06459092414706856, 'fraction_numerical': 0.0059622391520370984, 'mean_word_length': 3.5619335347432024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5701205', 'n_tokens_mistral': 732, 'n_tokens_neox': 713, 'n_words': 359}