<commit_before>//
//  MVApi.swift
//  RXMVHero
//
//  Created by <NAME> on 4/7/16.
//  Copyright © 2016 iGROOMGRiM. All rights reserved.
//

import Foundation
import Moya

enum ApiService {
    case GetCharacters
    case GetCharactersByID(id: String)
}

private func JSONResponseDataFormatter(data: NSData) -> NSData {
    do {
        let dataAsJSON = try NSJSONSerialization.JSONObjectWithData(data, options: [])
        let prettyData =  try NSJSONSerialization.dataWithJSONObject(dataAsJSON, options: .PrettyPrinted)
        return prettyData
    } catch {
        return data //fallback to original data if it cant be serialized
    }
}

let MVProvider = RxMoyaProvider<ApiService>(plugins: [NetworkLoggerPlugin(verbose: true, responseDataFormatter: JSONResponseDataFormatter)])

extension ApiService: TargetType {
    
    var baseURL: NSURL {
        return NSURL(string: "http://gateway.marvel.com")!
    }
    
    var path: String {
        
        switch self {
        case .GetCharacters:
            return "/v1/public/characters"
        case .GetCharactersByID(let id):
            return "/v1/public/characters/\(id)"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .GetCharacters, .GetCharactersByID(_):
            return .GET
        }
    }
    
    var parameters: [String: AnyObject]? {
        
        let publicKey = ""
        let privateKey = ""
        let apiKey = ""
        let ts = NSDate().timeIntervalSince1970.description
        let hash = "\(ts)\(privateKey)\(publicKey)".md5
        
        switch self {
        case .GetCharacters:
            return ["apikey":apiKey, "ts":ts, "hash": hash]
        case .GetCharactersByID(let id):
            return ["apikey":apiKey, "ts":ts, "hash": hash, "id": id]
        }
    }
    
    var sampleData: NSData {
        switch self {
        case .GetCharacters:
            return "[]".dataUsingEncoding(NSUTF8StringEncoding)!
        case .GetCharactersByID(_):
            return "[]".dataUsingEncoding(NSUTF8StringEncoding)!
        }
    }
}<commit_msg>add get comics service<commit_after>//
//  MVApi.swift
//  RXMVHero
//
//  Created by <NAME> on 4/7/16.
//  Copyright © 2016 iGROOMGRiM. All rights reserved.
//

import Foundation
import Moya

enum ApiService {
    case GetCharacters
    case GetCharactersByID(id: String)
    case GetComics
}

private func JSONResponseDataFormatter(data: NSData) -> NSData {
    do {
        let dataAsJSON = try NSJSONSerialization.JSONObjectWithData(data, options: [])
        let prettyData =  try NSJSONSerialization.dataWithJSONObject(dataAsJSON, options: .PrettyPrinted)
        return prettyData
    } catch {
        return data //fallback to original data if it cant be serialized
    }
}

let MVProvider = RxMoyaProvider<ApiService>(plugins: [NetworkLoggerPlugin(verbose: true, responseDataFormatter: JSONResponseDataFormatter)])

extension ApiService: TargetType {
    
    var baseURL: NSURL {
        return NSURL(string: "http://gateway.marvel.com")!
    }
    
    var path: String {
        
        switch self {
        case .GetCharacters:
            return "/v1/public/characters"
        case .GetCharactersByID(let id):
            return "/v1/public/characters/\(id)"
        case .GetComics:
            return "/v1/public/comics"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .GetCharacters, .GetCharactersByID(_), .GetComics:
            return .GET
        }
    }
    
    var parameters: [String: AnyObject]? {
        
        let ts = NSDate().timeIntervalSince1970.description
        let hash = "\(ts)\(MVPrivateKey)\(MVPublicKey)".md5
        
        switch self {
        case .GetCharacters, .GetComics:
            return ["apikey":MVPublicKey, "ts":ts, "hash": hash]
        case .GetCharactersByID(let id):
            return ["apikey":MVPublicKey, "ts":ts, "hash": hash, "id": id]
        }
    }
    
    var sampleData: NSData {
        switch self {
        case .GetCharacters, .GetComics:
            return "[]".dataUsingEncoding(NSUTF8StringEncoding)!
        case .GetCharactersByID(_):
            return "[]".dataUsingEncoding(NSUTF8StringEncoding)!
        }
    }
}
{'fraction_non_alphanumeric': 0.10792899408284023, 'fraction_numerical': 0.008284023668639054, 'mean_word_length': 2.2161339421613393, 'pattern_counts': {'":': 14, '<': 7, '<?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': '645820', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1271, 'n_words': 296}