Compare commits

...
2 Commits
Author SHA1 Message Date
Majd Alfhaily 972f0b2cd0 Align version (1.0.5) 2021-06-11 23:23:45 +02:00
Majd Alfhaily 03993b2b93 Add support for specifying device family 2021-06-11 23:23:19 +02:00
7 changed files with 81 additions and 27 deletions

No files matched your search

+10 -4
View File
@@ -34,7 +34,7 @@ To search for apps on the App Store, use the `search` command.
```
OVERVIEW: Search for iOS apps available on the App Store.
USAGE: ipatool search <term> [--limit <limit>] [--country <country>] [--log-level <log-level>]
USAGE: ipatool search <term> [--limit <limit>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
ARGUMENTS:
<term> The term to search for.
@@ -44,7 +44,10 @@ OPTIONS:
(default: 5)
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
the iTunes Store. (default: US)
--log-level <log-level> (default: info)
-d, --device-family <device-family>
The device family to limit the search query to.
(default: iPhone)
--log-level <log-level> The log level. (default: info)
--version Show the version.
-h, --help Show help information.
```
@@ -54,7 +57,7 @@ To download a copy of the ipa file, use the `download` command.
```
OVERVIEW: Download (encrypted) iOS app packages from the App Store.
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--email <email>] [--password <password>] [--country <country>] [--log-level <log-level>]
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--email <email>] [--password <password>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
OPTIONS:
-b, --bundle-identifier <bundle-identifier>
@@ -64,7 +67,10 @@ OPTIONS:
The password for the Apple ID.
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
the iTunes Store. (default: US)
--log-level <log-level> (default: info)
-d, --device-family <device-family>
The device family to limit the search query to.
(default: iPhone)
--log-level <log-level> The log level. (default: info)
--version Show the version.
-h, --help Show help information.
```
+6 -3
View File
@@ -25,9 +25,12 @@ struct Download: ParsableCommand {
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
private var country: String = "US"
@Option
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
@Option(name: [.long], help: "The log level.")
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
}
@@ -41,7 +44,7 @@ extension Download {
do {
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(country)'...", level: .info)
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier, country: country)
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
} catch {
logger.log("\(error)", level: .debug)
+1 -1
View File
@@ -11,7 +11,7 @@ struct IPATool: ParsableCommand {
static var configuration: CommandConfiguration {
return .init(commandName: "ipatool",
abstract: "A cli tool for interacting with Apple's ipa files.",
version: "1.0.4",
version: "1.0.5",
subcommands: [Download.self, Search.self])
}
}
+5 -2
View File
@@ -22,7 +22,10 @@ struct Search: ParsableCommand {
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
private var country: String = "US"
@Option
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
@Option(name: [.long], help: "The log level.")
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
@@ -38,7 +41,7 @@ extension Search {
do {
logger.log("Searching for '\(term)' using the '\(country)' store front...", level: .info)
let results = try itunesClient.search(term: term, limit: limit, country: country)
let results = try itunesClient.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
guard !results.isEmpty else {
logger.log("No results found.", level: .error)
+24 -10
View File
@@ -8,16 +8,23 @@
import Foundation
protocol iTunesClientInterface {
func lookup(bundleIdentifier: String, country: String, completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
func search(term: String, limit: Int, country: String, completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
func lookup(bundleIdentifier: String,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
func search(term: String,
limit: Int,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
}
extension iTunesClientInterface {
func lookup(bundleIdentifier: String, country: String) throws -> iTunesResponse.Result {
func lookup(bundleIdentifier: String, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> iTunesResponse.Result {
let semaphore = DispatchSemaphore(value: 0)
var result: Result<iTunesResponse.Result, Error>?
lookup(bundleIdentifier: bundleIdentifier, country: country) {
lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily) {
result = $0
semaphore.signal()
}
@@ -34,11 +41,11 @@ extension iTunesClientInterface {
}
}
func search(term: String, limit: Int, country: String) throws -> [iTunesResponse.Result] {
func search(term: String, limit: Int, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> [iTunesResponse.Result] {
let semaphore = DispatchSemaphore(value: 0)
var result: Result<[iTunesResponse.Result], Error>?
search(term: term, limit: limit, country: country) {
search(term: term, limit: limit, country: country, deviceFamily: deviceFamily) {
result = $0
semaphore.signal()
}
@@ -63,8 +70,11 @@ final class iTunesClient: iTunesClientInterface {
self.httpClient = httpClient
}
func lookup(bundleIdentifier: String, country: String, completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier, country: country)
func lookup(bundleIdentifier: String,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
httpClient.send(request) { result in
switch result {
@@ -82,8 +92,12 @@ final class iTunesClient: iTunesClientInterface {
}
}
func search(term: String, limit: Int, country: String, completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
let request = iTunesRequest.search(term: term, limit: limit, country: country)
func search(term: String,
limit: Int,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
let request = iTunesRequest.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
httpClient.send(request) { result in
switch result {
+27 -7
View File
@@ -5,11 +5,31 @@
// Created by Majd Alfhaily on 22.05.21.
//
import Foundation
import ArgumentParser
enum iTunesRequest {
case search(term: String, limit: Int, country: String)
case lookup(bundleIdentifier: String, country: String)
case search(term: String, limit: Int, country: String, deviceFamily: DeviceFamily = .phone)
case lookup(bundleIdentifier: String, country: String, deviceFamily: DeviceFamily = .phone)
}
extension iTunesRequest {
enum DeviceFamily: String, ExpressibleByArgument {
case phone = "iPhone"
case pad = "iPad"
var defaultValueDescription: String {
return rawValue
}
var entity: String {
switch self {
case .phone:
return "software"
case .pad:
return "iPadSoftware"
}
}
}
}
extension iTunesRequest: HTTPRequest {
@@ -28,10 +48,10 @@ extension iTunesRequest: HTTPRequest {
var payload: HTTPPayload? {
switch self {
case let .lookup(bundleIdentifier, country):
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1", "country": country])
case let .search(term, limit, country):
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)", "country": country])
case let .lookup(bundleIdentifier, country, deviceFamily):
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1", "country": country, "entity": deviceFamily.entity])
case let .search(term, limit, country, deviceFamily):
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)", "country": country, "entity": deviceFamily.entity])
}
}
}
@@ -53,6 +53,14 @@
<CommandLineArguments>
<CommandLineArgument
argument = "download --help"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "search &quot;Swift Playgrounds&quot; --device-family iPhone"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "search &quot;Swift Playgrounds&quot; --device-family iPad"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument