This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename package and CLI to app-store-reviews and add page, reviews and…
… territories commands
- Loading branch information
Showing
10 changed files
with
157 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
import ArgumentParser | ||
import AppStoreReviews | ||
|
||
/// Encapsulates `page` command behavior. | ||
struct Page: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Fetch the App Store Reviews feed page for the provided app ID, territory and page number." | ||
) | ||
|
||
@Argument(help: "The ID of the app.") | ||
var appID: Int | ||
|
||
@Argument(help: "App Store country or region.") | ||
var territory: Territory | ||
|
||
@Argument(help: "The page number.") | ||
var page: Int | ||
|
||
@Argument(help: "The reviews file output.") | ||
var fileOutput: String | ||
|
||
func run() throws { | ||
let pageToFetch = try AppStoreReviews.Page(appID: appID, territory: territory, page: page) | ||
|
||
let loader = Downloader() | ||
loader.fetch(page: pageToFetch) { result in | ||
switch result { | ||
case .success(let feed): | ||
do { | ||
try Output.write(feed, to: fileOutput) | ||
Self.exit() | ||
} catch { | ||
Self.exit(withError: error) | ||
} | ||
case .failure(let error): | ||
Self.exit(withError: error) | ||
} | ||
} | ||
dispatchMain() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import ArgumentParser | ||
import AppStoreReviews | ||
|
||
/// Encapsulates `reviews` command behavior. | ||
struct Reviews: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Fetch all the reviews from the App Store Reviews feed for the provided app ID and territory." | ||
) | ||
|
||
@Argument(help: "The ID of the app.") | ||
var appID: Int | ||
|
||
@Argument(help: "App Store country or region.") | ||
var territory: Territory | ||
|
||
@Argument(help: "The reviews file output.") | ||
var fileOutput: String | ||
|
||
func run() throws { | ||
let loader = ReviewsLoader() | ||
loader.fetchAll(appID: appID, territory: territory) { result in | ||
switch result { | ||
case .success(let reviews): | ||
do { | ||
try Output.write(reviews, to: fileOutput) | ||
Self.exit() | ||
} catch { | ||
Self.exit(withError: error) | ||
} | ||
case .failure(let error): | ||
Self.exit(withError: error) | ||
} | ||
} | ||
dispatchMain() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
import ArgumentParser | ||
import AppStoreReviews | ||
|
||
/// Encapsulates `territories` command behavior. | ||
struct Territories: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Print the list of territories reviews can be fetched for." | ||
) | ||
|
||
func run() throws { | ||
AppStoreReviews.Territory.allCases.forEach { territory in | ||
/* e.g. | ||
... | ||
TON Tonga | ||
TR Turkey | ||
... | ||
*/ | ||
print("\(territory.isoCode.padding(toLength: 3, withPad: " ", startingAt: 0)) \(territory.name)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import ArgumentParser | ||
|
||
enum Output { | ||
static func write<Value: Encodable>(_ data: Value, to file: String) throws { | ||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = .prettyPrinted | ||
let json = try encoder.encode(data) | ||
let outputURL = URL(fileURLWithPath: file) | ||
try json.write(to: outputURL) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Sources/app-store-reviews/Utilities/TerritoryExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import ArgumentParser | ||
import AppStoreReviews | ||
|
||
extension Territory: ExpressibleByArgument {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ArgumentParser | ||
import AppStoreReviews | ||
|
||
/// Encapsulates `--version` flag behavior. | ||
struct VersionOptions: ParsableArguments { | ||
@Flag(name: .shortAndLong, help: "Print the version and exit") | ||
var version: Bool = false | ||
|
||
func validate() throws { | ||
if version { | ||
print(AppStoreReviews.version) | ||
throw ExitCode.success | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ArgumentParser | ||
|
||
/// Collects the command line options that were passed to `app-store-reviews` and dispatches to the | ||
/// appropriate subcommand. | ||
struct AppStoreReviewsCommand: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
commandName: "app-store-reviews", | ||
abstract: "Fetch user reviews from the Apple App Stores", | ||
subcommands: [ | ||
Reviews.self, | ||
Page.self, | ||
Territories.self, | ||
], | ||
defaultSubcommand: nil | ||
) | ||
|
||
@OptionGroup() | ||
var versionOptions: VersionOptions | ||
} | ||
|
||
AppStoreReviewsCommand.main() |