<commit_before>//
//  GitHubRouter.swift
//  Xgist
//
//  Created by <NAME> on 27/03/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

enum GitHubRouter {
    case auth([String : Any])
    case gist([String : Any], Bool)
    case gists
    
    private var basePath: String {
        return "https://api.github.com"
    }
    
    private var accessToken: String {
        guard let token = GitHubAPI().token else { fatalError("No Token") }
        return token
    }
    
    private var path: String {
        switch self {
        case .auth:
            return "authorizations/clients/\(GitHubCredential.clientID.value)/\(UUID.init())"
        case .gist( _ , let authenticated):
            if authenticated {
                return "gists?access_token=\(accessToken)"
            } else {
                return "gists"
            }
        case .gists:
            return "users/\("usernameToTest")/gists?access_token=\(accessToken)"
        }
    }
        
    private var method: String {
        switch self {
        case .auth:
            return "PUT"
        case .gist:
            return "POST"
        case .gists:
            return "GET"
        }
    }
    
    private var httpBody: Data? {
        switch self {
        case .auth(let params), .gist(let params, _):
            let jsonData = try? JSONSerialization.data(withJSONObject: params)
            return jsonData
        case .gists:
            return nil
        }
    }
    <commit_msg>Add user info router<commit_after>//
//  GitHubRouter.swift
//  Xgist
//
//  Created by <NAME> on 27/03/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

enum GitHubRouter {
    case auth([String : Any])
    case gist([String : Any], Bool)
    case gists
    case user
    
    private var basePath: String {
        return "https://api.github.com"
    }
    
    private var accessToken: String {
        guard let token = GitHubAPI().token else { fatalError("No Token") }
        return token
    }
    
    private var path: String {
        switch self {
        case .auth:
            return "authorizations/clients/\(GitHubCredential.clientID.value)/\(UUID.init())"
        case .gist( _ , let authenticated):
            if authenticated {
                return "gists?access_token=\(accessToken)"
            } else {
                return "gists"
            }
        case .gists:
            return "users/\("usernameToTest")/gists?access_token=\(accessToken)"
        case .user:
            return "user?access_token=\(accessToken)"
        }
    }
        
    private var method: String {
        switch self {
        case .auth:
            return "PUT"
        case .gist:
            return "POST"
        case .gists, .user:
            return "GET"
        }
    }
    
    private var httpBody: Data? {
        switch self {
        case .auth(let params), .gist(let params, _):
            let jsonData = try? JSONSerialization.data(withJSONObject: params)
            return jsonData
        case .gists, .user:
            return nil
        }
    }
    
{'fraction_non_alphanumeric': 0.10710839498230942, 'fraction_numerical': 0.0064329366355741395, 'mean_word_length': 1.5617792421746293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3189837', 'n_tokens_mistral': 918, 'n_tokens_neox': 885, 'n_words': 235}