<commit_before>//
//  Search.swift
//  mas-cli
//
//  Created by <NAME> on 4/14/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

struct ResultKeys {
    static let ResultCount = "resultCount"
    static let Results = "results"
    static let TrackName = "trackName"
    static let TrackId = "trackId"
    static let Version = "version"
}

struct SearchCommand: CommandProtocol {
    typealias Options = SearchOptions
    let verb = "search"
    let function = "Search for apps from the Mac App Store"
    
    func run(_ options: Options) -> Result<(), MASError> {
        
        guard let searchURLString = searchURLString(options.appName),
              let searchJson = URLSession.requestSynchronousJSONWithURLString(searchURLString) as? [String: Any] else {
            return .failure(.searchFailed)
        }
        
        guard let resultCount = searchJson[ResultKeys.ResultCount] as? Int, resultCount > 0,
              let results = searchJson[ResultKeys.Results] as? [[String: Any]] else {
            print("No results found")
            return .failure(.noSearchResultsFound)
        }
        
        for result in results {
            if let appName = result[ResultKeys.TrackName] as? String,
                   let appVersion = result[ResultKeys.Version] as? String,
                   let appId = result[ResultKeys.TrackId] as? Int {
                print("\(String(appId)) \(appName) \(appVersion)")
            }
        }
        
        return .success(())
    }
    
    func searchURLString(_ appName: String) -> String? {
        if let urlEncodedAppName = appName.URLEncodedString {
            return "https://itunes.apple.com/search?entity=macSoftware&term=\(urlEncodedAppName)&attribute=allTrackTerm"
        }
        return nil
    }
}<commit_msg>added parenthsis around version in search<commit_after>//
//  Search.swift
//  mas-cli
//
//  Created by <NAME> on 4/14/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

struct ResultKeys {
    static let ResultCount = "resultCount"
    static let Results = "results"
    static let TrackName = "trackName"
    static let TrackId = "trackId"
    static let Version = "version"
}

struct SearchCommand: CommandProtocol {
    typealias Options = SearchOptions
    let verb = "search"
    let function = "Search for apps from the Mac App Store"
    
    func run(_ options: Options) -> Result<(), MASError> {
        
        guard let searchURLString = searchURLString(options.appName),
              let searchJson = URLSession.requestSynchronousJSONWithURLString(searchURLString) as? [String: Any] else {
            return .failure(.searchFailed)
        }
        
        guard let resultCount = searchJson[ResultKeys.ResultCount] as? Int, resultCount > 0,
              let results = searchJson[ResultKeys.Results] as? [[String: Any]] else {
            print("No results found")
            return .failure(.noSearchResultsFound)
        }
        
        for result in results {
            if let appName = result[ResultKeys.TrackName] as? String,
                   let appVersion = result[ResultKeys.Version] as? String,
                   let appId = result[ResultKeys.TrackId] as? Int {
                print("\(String(appId)) \(appName) (\(appVersion))")
            }
        }
        
        return .success(())
    }
    
    func searchURLString(_ appName: String) -> String? {
        if let urlEncodedAppName = appName.URLEncodedString {
            return "https://itunes.apple.com/search?entity=macSoftware&term=\(urlEncodedAppName)&attribute=allTrackTerm"
        }
        return nil
    }
}
{'fraction_non_alphanumeric': 0.10281923714759536, 'fraction_numerical': 0.00552791597567717, 'mean_word_length': 2.248653500897666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '6933721', 'n_tokens_mistral': 1020, 'n_tokens_neox': 984, 'n_words': 271}