<commit_before>//
//  CloudAPISpec.swift
//  FeedlyKit
//
//  Created by <NAME> on 1/17/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

import FeedlyKit
import Quick
import Nimble

class CloudAPISpec: QuickSpec {
    internal let client: CloudAPIClient = CloudAPIClient(target: SpecHelper.target)
    var profile: Profile?

    func fetchProfile(callback: () -> ()) {
        self.client.fetchProfile {
            guard let _ = $0.response?.statusCode,
                  let profile = $0.result.value else { return }
            self.profile = profile
            callback()
        }
    }

    func fetchLatestEntries(callback: ([Entry]) -> ()) {
        fetchProfile() {
            guard let p = self.profile else { return }
            let params = PaginationParams()
            params.count = SpecHelper.perPage
            self.client.fetchContents(p.allCategory.id, paginationParams: params) {
                callback($0.result.value!.items)
            }
        }<commit_msg>Improve SpecHelper. Cache profile data, if profile is already fetched. use it<commit_after>//
//  CloudAPISpec.swift
//  FeedlyKit
//
//  Created by <NAME> on 1/17/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

import FeedlyKit
import Quick
import Nimble

class CloudAPISpec: QuickSpec {
    internal let client: CloudAPIClient = CloudAPIClient(target: SpecHelper.target)
    var profile: Profile?

    func fetchProfile(callback: () -> ()) {
        if let _ = profile {
            callback()
            return
        }
        self.client.fetchProfile {
            guard let _ = $0.response?.statusCode,
                  let profile = $0.result.value else { return }
            self.profile = profile
            callback()
        }
    }

    func fetchLatestEntries(callback: ([Entry]) -> ()) {
        fetchProfile() {
            guard let p = self.profile else { return }
            let params = PaginationParams()
            params.count = SpecHelper.perPage
            self.client.fetchContents(p.allCategory.id, paginationParams: params) {
                callback($0.result.value!.items)
            }
        }
{'fraction_non_alphanumeric': 0.10719193770041227, 'fraction_numerical': 0.010994044892349977, 'mean_word_length': 2.0124137931034483, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3358306', 'n_tokens_mistral': 627, 'n_tokens_neox': 600, 'n_words': 152}