<commit_before>//
//  TwitterManager.swift
//  CriticalMaps
//
//  Created by <NAME> on 1/28/19.
//

import Foundation

class TwitterManager {
    private let url: URL
    private var cachedTweets: [Tweet] = [] {
        didSet {
            updateContentStateCallback?(.results(cachedTweets))
        }
    }

    private var contentState: ContentState<[Tweet]> = .loading(.cmLoadingController) {
        didSet {
            updateContentStateCallback?(contentState)
        }
    }

    private let networkLayer: NetworkLayer

    var updateContentStateCallback: ((ContentState<[Tweet]>) -> Void)?

    init(networkLayer: NetworkLayer, url: URL) {
        self.networkLayer = networkLayer
        self.url = url
    }

    public func loadTweets(_ completion: ResultCallback<[Tweet]>? = nil) {
        let getTweetsRequest = TwitterRequest()
        networkLayer.get(request: getTweetsRequest) { [weak self] result in
            guard let self = self else { return }
            onMain {
                switch result {
                case let .failure(error):
                    completion?(.failure(error))
                    ErrorHandler.default.handleError(error)
                case let .success(response):
                    self.cachedTweets = response.statuses
                    completion?(.success(response.statuses))
                }
            }
        }
    }

    public func getTweets() {
        contentState = .loading(.cmLoadingController)
        loadTweets()
    }
}<commit_msg>add loadingState to getTweets<commit_after>//
//  TwitterManager.swift
//  CriticalMaps
//
//  Created by <NAME> on 1/28/19.
//

import Foundation

class TwitterManager {
    private let url: URL
    private var cachedTweets: [Tweet] = [] {
        didSet {
            updateContentStateCallback?(.results(cachedTweets))
        }
    }

    private var contentState: ContentState<[Tweet]> = .loading(.cmLoadingController) {
        didSet {
            updateContentStateCallback?(contentState)
        }
    }

    private let networkLayer: NetworkLayer

    var updateContentStateCallback: ((ContentState<[Tweet]>) -> Void)?

    init(networkLayer: NetworkLayer, url: URL) {
        self.networkLayer = networkLayer
        self.url = url
    }

    public func loadTweets(_ completion: ResultCallback<[Tweet]>? = nil) {
        let getTweetsRequest = TwitterRequest()
        networkLayer.get(request: getTweetsRequest) { [weak self] result in
            guard let self = self else { return }
            onMain {
                switch result {
                case let .failure(error):
                    completion?(.failure(error))
                    ErrorHandler.default.handleError(error)
                case let .success(response):
                    self.cachedTweets = response.statuses
                    completion?(.success(response.statuses))
                }
            }
        }
    }

    public func getTweets() {
        contentState = .loading(.default)
        loadTweets()
    }
}
{'fraction_non_alphanumeric': 0.09841479524438573, 'fraction_numerical': 0.0033025099075297227, 'mean_word_length': 1.935077519379845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6064211', 'n_tokens_mistral': 842, 'n_tokens_neox': 796, 'n_words': 175}