<commit_before>//
//  GitHubAPI.swift
//  RxExample
//
//  Created by <NAME> on 4/25/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation
import RxSwift
import RxCocoa

enum SignupState: Equatable {
    case InitialState
    case SigningUp
    case SignedUp(signedUp: Bool)
}

func ==(lhs: SignupState, rhs: SignupState) -> Bool {
    switch (lhs, rhs) {
    case (.InitialState, .InitialState):
        return true
    case (.SigningUp, .SigningUp):
        return true
    case (.SignedUp(let lhsSignup), .SignedUp(let rhsSignup)):
        return lhsSignup == rhsSignup
    default:
        return false
    }
}

class GitHubAPI {
    let dataScheduler: ImmediateScheduler
    let URLSession: NSURLSession

    init(dataScheduler: ImmediateScheduler, URLSession: NSURLSession) {
        self.dataScheduler = dataScheduler
        self.URLSession = URLSession
    }
    
    func usernameAvailable(username: String) -> Observable<Bool> {
        // this is ofc just mock, but good enough
        
        let URL = NSURL(string: "https://github.com/\(URLEscape(username))")!
        let request = NSURLRequest(URL: URL)
        return self.URLSession.rx_response(request)
            >- map { (maybeData, maybeResponse) in
                if let response = maybeResponse as? NSHTTPURLResponse {
                    return response.statusCode == 404
                }
                else {
                    return false
                }
            }
            >- observeSingleOn(self.dataScheduler)
            >- catch { result in
                return returnElement(false)
            }
    }
    
    func signup(username: String, password: String) -> Observable<SignupState> {
        // this is also just a mock
        let signupResult = SignupState.SignedUp(signedUp: arc4random() % 5 == 0 ? false : true)
        return concat([returnElement(signupResult), never()])
            >- throttle(5000, MainScheduler.sharedInstance)
            >- startWith(SignupState.SigningUp)
    }
}<commit_msg>Decreses timeout for Github signup example.<commit_after>//
//  GitHubAPI.swift
//  RxExample
//
//  Created by <NAME> on 4/25/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation
import RxSwift
import RxCocoa

enum SignupState: Equatable {
    case InitialState
    case SigningUp
    case SignedUp(signedUp: Bool)
}

func ==(lhs: SignupState, rhs: SignupState) -> Bool {
    switch (lhs, rhs) {
    case (.InitialState, .InitialState):
        return true
    case (.SigningUp, .SigningUp):
        return true
    case (.SignedUp(let lhsSignup), .SignedUp(let rhsSignup)):
        return lhsSignup == rhsSignup
    default:
        return false
    }
}

class GitHubAPI {
    let dataScheduler: ImmediateScheduler
    let URLSession: NSURLSession

    init(dataScheduler: ImmediateScheduler, URLSession: NSURLSession) {
        self.dataScheduler = dataScheduler
        self.URLSession = URLSession
    }
    
    func usernameAvailable(username: String) -> Observable<Bool> {
        // this is ofc just mock, but good enough
        
        let URL = NSURL(string: "https://github.com/\(URLEscape(username))")!
        let request = NSURLRequest(URL: URL)
        return self.URLSession.rx_response(request)
            >- map { (maybeData, maybeResponse) in
                if let response = maybeResponse as? NSHTTPURLResponse {
                    return response.statusCode == 404
                }
                else {
                    return false
                }
            }
            >- observeSingleOn(self.dataScheduler)
            >- catch { result in
                return returnElement(false)
            }
    }
    
    func signup(username: String, password: String) -> Observable<SignupState> {
        // this is also just a mock
        let signupResult = SignupState.SignedUp(signedUp: arc4random() % 5 == 0 ? false : true)
        return concat([returnElement(signupResult), never()])
            >- throttle(5, MainScheduler.sharedInstance)
            >- startWith(SignupState.SigningUp)
    }
}
{'fraction_non_alphanumeric': 0.09782873871676019, 'fraction_numerical': 0.008538667967797023, 'mean_word_length': 2.1273836765827614, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '3403015', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1164, 'n_words': 299}