<commit_before>//
//  NetworkingManager.swift
//  MarvelComics
//
//  Created by <NAME> on 02/03/2016.
//  Copyright © 2016 Desfici. All rights reserved.
//

import Foundation
import BothamNetworking
import CryptoSwift

struct MarvelAPIClient {

    static private let baseURL = "http://gateway.marvel.com:80/v1/public/"
    static private let comicsEndPoint = "/comics"
    
    private struct MarvelAPIParams {
        static let timestamp = "ts"
        static let apiKey = "apikey"
        static let hash = "hash"
    }
    
    static func comics(completion:([Comic]) -> ()) {
        
        let apiClient = BothamAPIClient(baseEndpoint: baseURL)
        apiClient.GET(comicsEndPoint, parameters: basicParams()) { result -> () in
            result.mapJSON({ json in
                dispatch_async(dispatch_get_main_queue(), {
                    completion(MarvelAPIParser.parseComics(json))
                })
            })
        }
    }
    
    static func basicParams() -> [String: String]{
    
        let apiKey = MarvelAPIConfig.apiKey
        let timestamp = NSDate.timeIntervalSinceReferenceDate()
        let hash = "\(timestamp)\(MarvelAPIConfig.privateKey)\(apiKey)".md5()
        
        return [MarvelAPIParams.timestamp: "\(timestamp)", MarvelAPIParams.apiKey: apiKey, MarvelAPIParams.hash: hash]
    }
}<commit_msg>Added order and index parameters to the comics api method<commit_after>//
//  NetworkingManager.swift
//  MarvelComics
//
//  Created by <NAME> on 02/03/2016.
//  Copyright © 2016 Desfici. All rights reserved.
//

import Foundation
import BothamNetworking
import CryptoSwift

enum OrderBy: String {
    case onsaleAscending = "-onsaleDate", onsaleDescending = "onsaleDate"
}

struct MarvelAPIClient {

    static private let baseURL = "http://gateway.marvel.com:80/v1/public/"
    static private let comicsEndPoint = "/comics"
    
    private struct MarvelAPIParams {
        static let timestamp = "ts"
        static let apiKey = "apikey"
        static let hash = "hash"
        static let offset = "offset"
        static let orderBy = "orderBy"
    }
    
    static func comics(index:Int = 0, orderBy: OrderBy = OrderBy.onsaleAscending, completion:([Comic]) -> ()) {
        
        let apiClient = BothamAPIClient(baseEndpoint: baseURL)
        var params = basicParams()
        
        params.appendDictionary([MarvelAPIParams.offset: "\(index)",
            MarvelAPIParams.orderBy: "-onsaleDate"])
        
        apiClient.GET(comicsEndPoint, parameters: params) { result -> () in
            result.mapJSON({ json in
                dispatch_async(dispatch_get_main_queue(), {
                    completion(MarvelAPIParser.parseComics(json))
                })
            })
        }
    }
    
    static func basicParams() -> [String: String]{
    
        let apiKey = MarvelAPIConfig.apiKey
        let timestamp = NSDate.timeIntervalSinceReferenceDate()
        let hash = "\(timestamp)\(MarvelAPIConfig.privateKey)\(apiKey)".md5()
        
        return [MarvelAPIParams.timestamp: "\(timestamp)",
            MarvelAPIParams.apiKey: apiKey,
            MarvelAPIParams.hash: hash]
    }
}
{'fraction_non_alphanumeric': 0.10724454286618158, 'fraction_numerical': 0.010439734261309713, 'mean_word_length': 2.381818181818182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6273296', 'n_tokens_mistral': 935, 'n_tokens_neox': 921, 'n_words': 209}