<commit_before>//
//  MalKit.swift
//  MalKit
//
//  Created by nktn on 2017/07/08.
//  Copyright © 2017年 nktn. All rights reserved.
//

import Foundation

//MalKit API Class
final class MalKit {
    
    static let sharedInstance = MalKit()
    
    var user_id: String = ""
    var passwd: String = ""
    let baseURLString: String = "https://myanimelist.net/api/"
    var session: URLSession
    
    enum MethodType: String{
        case validatingLogin = "/account/verify_credentials"
        case searchAnime = "anime/search"
        case searchManga = "manga/search"
        case addAnime = "animelist/add/"
        case addManga = "mangalist/add/"
        case updateAnime = "animelist/update/"
        case updateManga = "mangalist/update/"
        case deleteAnime = "animelist/delete/"
        case deleteManga = "mangalist/delete/"
    }
    
    enum LocalError: Int {
        case TooManyLogin = 0
        func createError(userInfo: [String : AnyObject]? = nil) -> NSError {
            return NSError(domain: "malkit", code: self.rawValue, userInfo: userInfo)
        }
    }
    
    private init() {
        self.session = URLSession.shared
    }
    
    public func setUserData(user_id: String, passwd: String){
        _ = MalKeychainService.set(user_id, forKey: "user_id")
        _ = MalKeychainService.set(passwd, forKey: "passwd")
    }
    
    public func verifyCredentials(completionHandler: @escaping (Data?, HTTPURLResponse?, NSError?) -> Void) -> URLSessionDataTask {
        return performGetRequest(MethodType.validatingLogin.rawValue, last_half: ".xml", params: nil, completionHandler: completionHandler)<commit_msg>modify class<commit_after>//
//  MalKit.swift
//  MalKit
//
//  Created by nktn on 2017/07/08.
//  Copyright © 2017年 nktn. All rights reserved.
//

import Foundation

//MalKit API Class
public class MalKit {
    
    public static let sharedInstance = MalKit()
    
    var user_id: String = ""
    var passwd: String = ""
    let baseURLString: String = "https://myanimelist.net/api/"
    var session: URLSession
    
    enum MethodType: String{
        case validatingLogin = "/account/verify_credentials"
        case searchAnime = "anime/search"
        case searchManga = "manga/search"
        case addAnime = "animelist/add/"
        case addManga = "mangalist/add/"
        case updateAnime = "animelist/update/"
        case updateManga = "mangalist/update/"
        case deleteAnime = "animelist/delete/"
        case deleteManga = "mangalist/delete/"
    }
    
    enum LocalError: Int {
        case TooManyLogin = 0
        func createError(userInfo: [String : AnyObject]? = nil) -> NSError {
            return NSError(domain: "malkit", code: self.rawValue, userInfo: userInfo)
        }
    }
    
    private init() {
        self.session = URLSession.shared
    }
    
    public func setUserData(user_id: String, passwd: String){
        _ = MalKeychainService.removeValue(forKey: "user_id")
        _ = MalKeychainService.removeValue(forKey: "passwd")
        _ = MalKeychainService.set(user_id, forKey: "user_id")
        _ = MalKeychainService.set(passwd, forKey: "passwd")
    }
    
    public func verifyCredentials(completionHandler: @escaping (Data?, HTTPURLResponse?, NSError?) -> Void) -> URLSessionDataTask {
        return performGetRequest(MethodType.validatingLogin.rawValue, last_half: ".xml", params: nil, completionHandler: completionHandler)
{'fraction_non_alphanumeric': 0.10910151691948658, 'fraction_numerical': 0.007584597432905484, 'mean_word_length': 2.6595517609391677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '613698', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1049, 'n_words': 249}