Skip to content

Commit

Permalink
Add more countries
Browse files Browse the repository at this point in the history
Fix worthbak#15 (japan)
Fix worthbak#16 (china)
Fix worthbak#26 (singapore)
Add worthbak#1 (austria)

Add taiwan, netherlands
Try to add Brazil
  • Loading branch information
theontho committed May 18, 2022
1 parent 80cb266 commit 07851b9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
66 changes: 62 additions & 4 deletions InventoryWatch/Countries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@

import Foundation

/// Represents metadata to pull info about products for specific countries.
///
/// Maybe accurate skucode list: https://discussions.apple.com/thread/251748775
///
/// Also can figure out sku codes by going to a country's web store and adding a non customized item to your cart and looking at the URL in the accessories upsell page:
/// Example: https://www.apple.com/nl/shop/buy-mac/macbook-pro?bfil=0&product=MK1A3N/A&step=attach
/// The item's SKU root is `MK1A3`, the `skucode` is `N` , the `storePathComponent`is `/nl` , etc.
struct Country: Hashable {
let name: String
let storePathComponent: String
let storePathComponent: String /// Not actually used, the two letter string key in Countries is the path component that is actually used
let skuCode: String
let altSkuCode: String? // for ipad in some countries
let altSkuCode: String? /// for ipad in some countries
}

let USData = Country(
Expand All @@ -21,6 +28,7 @@ let USData = Country(
altSkuCode: nil
)


let Countries: [String: Country] = [
"US": USData,
"CA": Country(
Expand All @@ -41,6 +49,12 @@ let Countries: [String: Country] = [
skuCode: "D",
altSkuCode: "FD"
),
"NL": Country(
name: "Netherlands",
storePathComponent: "/nl",
skuCode: "N",
altSkuCode: nil
),
"UK": Country(
name: "United Kingdom",
storePathComponent: "/uk",
Expand All @@ -52,21 +66,65 @@ let Countries: [String: Country] = [
storePathComponent: "/kr",
skuCode: "KH",
altSkuCode: nil
),
),
"HK": Country(
name: "Hong Kong",
storePathComponent: "/hk",
skuCode: "ZP",
altSkuCode: nil
)
),
"SG": Country(
name: "Singapore",
storePathComponent: "/sg",
skuCode: "ZP",
altSkuCode: nil
),
"JP": Country(
name: "Japan",
storePathComponent: "/jp",
skuCode: "J",
altSkuCode: nil
),
"CN": Country(
name: "China",
storePathComponent: ".cn",
skuCode: "CH",
altSkuCode: nil
),
"AT": Country(
name: "Austria",
storePathComponent: "/at",
skuCode: "D",
altSkuCode: nil
),
"TW": Country(
name: "Taiwan",
storePathComponent: "/tw",
skuCode: "TA",
altSkuCode: nil
),
//Brazil does not have in store pickup, even though they have apple stores?
// "BR": Country(
// name: "Brazil",
// storePathComponent: "/br",
// skuCode: "BZ",
// altSkuCode: nil
// ),
];

let OrderedCountries = [
"US",
"CA",
"AU",
"DE",
"AT",
"NL",
"UK",
"KR",
"JP",
"SG",
"HK",
"CN",
"TW",
// "BR", // doesn't seem to work, no in store pickup?
]
10 changes: 7 additions & 3 deletions InventoryWatch/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ final class Model: ObservableObject {
private var countryPathElement: String {
let country = preferredCountry
if country == "US" {
return ""
return "/"
} else if country == "CN" {
return ".cn/"
} else {
return country + "/"
return "/" + country + "/"
}
}

Expand Down Expand Up @@ -378,14 +380,16 @@ final class Model: ObservableObject {
let filterForPreferredModels = UserDefaults.standard.bool(forKey: "showResultsOnlyForPreferredModels")
let filterModels = filterForPreferredModels ? preferredSKUs : nil

let urlRoot = "https://www.apple.com/\(countryPathElement.lowercased())shop/fulfillment-messages?"
let urlRoot = "https://www.apple.com\(countryPathElement.lowercased())shop/fulfillment-messages?"
let query = generateQueryString()

guard let url = URL(string: urlRoot + query) else {
updateErrorState(to: ModelError.couldNotGenerateURL)
return
}

print("query url: \(url)")

URLSession.shared.dataTask(with: url) { data, response, error in
do {
try self.parseStoreResponse(data, filterForModels: filterModels)
Expand Down

0 comments on commit 07851b9

Please sign in to comment.