<commit_before>//
//  AuthRequests.swift
//  NetworkStack
//
//  Created by <NAME> on 2/11/16.
//  Copyright © 2016 OC Tanner. All rights reserved.
//

import Foundation
import JaSON


// TODO: This should just call network for something like login and construct the session and pass the URL in

public protocol AuthRequests {
    func logIn(username: String, password: String, completion: (responseObject: JSONObject?, error: ErrorType?) -> Void) throws
    func logOut()
}

public struct AuthAPIRequests: AuthRequests {

    // MARK: - Public initializer

    public init() { }

    
    // MARK: - Internal properties
    
    var network = Network()
    
    
    // MARK: - Public API
    
    public func logIn(username: String, password: String, completion: (responseObject: JSONObject?, error: ErrorType?) -> Void) throws {
        guard let appNetworkState = AppNetworkState.currentAppState else { throw Network.Error.MissingAppNetworkState }
        guard let url = appNetworkState.urlForEndpoint(appNetworkState.tokenEndpointURLString) else { throw Network.Error.InvalidEndpoint }
        let parameters = [
            "grant_type": "password",
            "username": username,
            "password": password
        ]<commit_msg>Revert "Construct correct URL for authentication"<commit_after>//
//  AuthRequests.swift
//  NetworkStack
//
//  Created by <NAME> on 2/11/16.
//  Copyright © 2016 OC Tanner. All rights reserved.
//

import Foundation
import JaSON


// TODO: This should just call network for something like login and construct the session and pass the URL in

public protocol AuthRequests {
    func logIn(username: String, password: String, completion: (responseObject: JSONObject?, error: ErrorType?) -> Void) throws
    func logOut()
}

public struct AuthAPIRequests: AuthRequests {

    // MARK: - Public initializer

    public init() { }

    
    // MARK: - Internal properties
    
    var network = Network()
    
    
    // MARK: - Public API
    
    public func logIn(username: String, password: String, completion: (responseObject: JSONObject?, error: ErrorType?) -> Void) throws {
        guard let appNetworkState = AppNetworkState.currentAppState else { throw Network.Error.MissingAppNetworkState }
        guard let url = NSURL(string: appNetworkState.tokenEndpointURLString) else { throw Network.Error.InvalidEndpoint }
        let parameters = [
            "grant_type": "password",
            "username": username,
            "password": password
        ]
{'fraction_non_alphanumeric': 0.09485850936628139, 'fraction_numerical': 0.007174172977281785, 'mean_word_length': 2.9341692789968654, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 9, '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': '1983251', 'n_tokens_mistral': 681, 'n_tokens_neox': 649, 'n_words': 224}