<commit_before>//
//  GrailedNetworkModel.swift
//  RxGrailed
//
//  Created by <NAME> on 2/25/17.
//  Copyright © 2017 Killectro. All rights reserved.
//

import Foundation
import AlgoliaSearch
import RxSwift

/// Protocol that represents the entirety of `RxGrailed`'s networking capabilities.
/// In a production app this would be split into network models for each controller, but
/// here that is unnecessary
protocol GrailedNetworkModelable {

    /// Returns an observable of `Listing`s retrieved from the backend
    ///
    /// - Parameters:
    ///   - paginate: Observable that triggers when the network model should trigger another request
    ///   - loadedSoFar: The list of `Listing`s loaded thus far. Should start as an empty array
    /// - Returns: An `Observable<[Listing]>` that has all of the `Listing` objects received from the backend
    func getListings(paginate: Observable<Void>, loadedSoFar: [Listing]) -> Observable<[Listing]>
}

struct GrailedNetworkModel: GrailedNetworkModelable {
    fileprivate let client: Client
    fileprivate let searchIndex: Index

    init() {
        client = Client(appID: "MNRWEFSS2Q", apiKey: "ce26ba82dbc20d4f25c28a2077ce159d")
        searchIndex = client.index(withName: "Listing_production")
    }

    func getListings(paginate: Observable<Void>, loadedSoFar: [Listing]) -> Observable<[Listing]> {
        return getMoreListings().flatMap { newPage -> Observable<[Listing]> in

            let newListings = loadedSoFar + newPage

            print(newListings.count)

            let obs = [
                // Return our current list of Listings
                Observable.just(newListings),

                // Wait until we are told to paginate
                Observable.never().takeUntil(paginate),<commit_msg>Remove debug print statement<commit_after>//
//  GrailedNetworkModel.swift
//  RxGrailed
//
//  Created by <NAME> on 2/25/17.
//  Copyright © 2017 Killectro. All rights reserved.
//

import Foundation
import AlgoliaSearch
import RxSwift

/// Protocol that represents the entirety of `RxGrailed`'s networking capabilities.
/// In a production app this would be split into network models for each controller, but
/// here that is unnecessary
protocol GrailedNetworkModelable {

    /// Returns an observable of `Listing`s retrieved from the backend
    ///
    /// - Parameters:
    ///   - paginate: Observable that triggers when the network model should trigger another request
    ///   - loadedSoFar: The list of `Listing`s loaded thus far. Should start as an empty array
    /// - Returns: An `Observable<[Listing]>` that has all of the `Listing` objects received from the backend
    func getListings(paginate: Observable<Void>, loadedSoFar: [Listing]) -> Observable<[Listing]>
}

struct GrailedNetworkModel: GrailedNetworkModelable {
    fileprivate let client: Client
    fileprivate let searchIndex: Index

    init() {
        client = Client(appID: "MNRWEFSS2Q", apiKey: "ce26ba82dbc20d4f25c28a2077ce159d")
        searchIndex = client.index(withName: "Listing_production")
    }

    func getListings(paginate: Observable<Void>, loadedSoFar: [Listing]) -> Observable<[Listing]> {
        return getMoreListings().flatMap { newPage -> Observable<[Listing]> in

            let newListings = loadedSoFar + newPage

            let obs = [
                // Return our current list of Listings
                Observable.just(newListings),

                // Wait until we are told to paginate
                Observable.never().takeUntil(paginate),
{'fraction_non_alphanumeric': 0.09465950833568805, 'fraction_numerical': 0.015823679005368747, 'mean_word_length': 2.9641657334826426, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '7057213', 'n_tokens_mistral': 1033, 'n_tokens_neox': 951, 'n_words': 321}