<commit_before>//
//  CompetitionWebservice.swift
//  Leichatletik
//
//  Created by <NAME> on 09.02.17.
//  Copyright © 2017 freiraum. All rights reserved.
//

import Foundation
import DBNetworkStack

extension Competition: JSONMappable {}
extension CompetitionDetails: JSONMappable {}
extension CompetitionResultDetails: JSONMappable {}

public struct CompetitionWebService {
    public init() {}
    public func searchCompetitions(filter: CompetitionFilter) -> Resource<Array<Competition>> {
        var parameters = filter.toDictionary()
        parameters["mostCurrent"] = true
        parameters["limit"] = 100
        
        let request = NetworkRequest(path: "ausList", baseURLKey: LADV.ladvURLKey,
                                     parameter: parameters)
        
        return JSONArrayResource(request: request).wrapped()
    }
    
    public func competitionDetails(for competitions: [CompetitionDescribing]) -> Resource<[CompetitionDetails]> {
        let ids = competitions.map( { "\($0.id)" } ).joined(separator: ",")
        let parameters: [String: Any] = ["id": ids, "all": true, "wettbewerbe": true]
        let request = NetworkRequest(path: "ausDetail", baseURLKey: LADV.ladvURLKey,
                                     parameter: parameters)
        
        return JSONArrayResource(request: request).wrapped()
    }
    
    public func competitionDetail(for competition: CompetitionDescribing) -> Resource<CompetitionDetails> {
        return competitionDetails(for: [competition]).map(transform: { $0.first! })
    }
    
}

<commit_msg>More Flexible API<commit_after>//
//  CompetitionWebservice.swift
//  Leichatletik
//
//  Created by <NAME> on 09.02.17.
//  Copyright © 2017 freiraum. All rights reserved.
//

import Foundation
import DBNetworkStack

extension Competition: JSONMappable {}
extension CompetitionDetails: JSONMappable {}
extension CompetitionResultDetails: JSONMappable {}

public struct CompetitionWebService {
    public init() {}
    public func searchCompetitions(filter: CompetitionFilter) -> Resource<Array<Competition>> {
        var parameters = filter.toDictionary()
        parameters["mostCurrent"] = true
        parameters["limit"] = 100
        
        let request = NetworkRequest(path: "ausList", baseURLKey: LADV.ladvURLKey,
                                     parameter: parameters)
        
        return JSONArrayResource(request: request).wrapped()
    }
    
    public func competitionDetails(for competitionIds: [Int]) -> Resource<[CompetitionDetails]> {
        let ids = competitionIds.map( { "\($0)" } ).joined(separator: ",")
        let parameters: [String: Any] = ["id": ids, "all": true, "wettbewerbe": true]
        let request = NetworkRequest(path: "ausDetail", baseURLKey: LADV.ladvURLKey,
                                     parameter: parameters)
        
        return JSONArrayResource(request: request).wrapped()
    }
    
    public func competitionDetail(for competitionId: Int) -> Resource<CompetitionDetails> {
        return competitionDetails(for: [competitionId]).map(transform: { $0.first! })
    }
    
    
}

extension CompetitionWebService {
    
    public func competitionDetails(for competitions: [CompetitionDescribing]) -> Resource<[CompetitionDetails]> {
        return competitionDetails(for: competitions.map({ $0.id }))
    }
    
    public func competitionDetail(for competition: CompetitionDescribing) -> Resource<CompetitionDetails> {
        return competitionDetails(for: [competition.id]).map(transform: { $0.first! })
    }
}

{'fraction_non_alphanumeric': 0.11145510835913312, 'fraction_numerical': 0.009006473402758232, 'mean_word_length': 3.0249150622876555, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232771', 'n_tokens_mistral': 994, 'n_tokens_neox': 930, 'n_words': 220}