Skip to content

Commit

Permalink
Merge pull request #775 from Shopify/develop
Browse files Browse the repository at this point in the history
SDK 3.1.2
  • Loading branch information
dbart01 authored Oct 18, 2017
2 parents fe88fb8 + 1dbcb24 commit 3f2d874
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 45 deletions.
32 changes: 16 additions & 16 deletions Buy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1922,11 +1922,11 @@
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Pay/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -1947,11 +1947,11 @@
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Pay/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down Expand Up @@ -2000,11 +2000,11 @@
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -2027,11 +2027,11 @@
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down Expand Up @@ -2162,11 +2162,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -2184,11 +2184,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -2207,11 +2207,11 @@
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -2236,11 +2236,11 @@
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.1.1;
CURRENT_PROJECT_VERSION = 3.1.2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3.1.1;
DYLIB_CURRENT_VERSION = 3.1.2;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Buy/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
24 changes: 15 additions & 9 deletions Buy/Client/Graph.Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ internal extension Graph {

internal class Cache {

static let cacheName = "com.buy.graph.cache-\(Global.frameworkVersion)"
let cacheDirectory: URL

private static let fileManager = FileManager.default
private static let cacheName = "com.buy.graph.cache"

private let memoryCache = NSCache<NSString, CacheItem>()

// ----------------------------------
// MARK: - Init -
//
init() {
init(shopName: String) {
self.cacheDirectory = Cache.cacheDirectory(for: shopName)
self.createCacheDirectoryIfNeeded()
}

private func createCacheDirectoryIfNeeded() {
let cacheDirectory = Cache.cacheDirectory()
let cacheDirectory = self.cacheDirectory
if !Cache.fileManager.fileExists(atPath: cacheDirectory.path) {
try! Cache.fileManager.createDirectory(at: cacheDirectory, withIntermediateDirectories: true, attributes: nil)
}
Expand All @@ -59,7 +61,7 @@ internal extension Graph {
func purge() {
self.purgeInMemory()

try? Cache.fileManager.removeItem(at: Cache.cacheDirectory())
try? Cache.fileManager.removeItem(at: self.cacheDirectory)
self.createCacheDirectoryIfNeeded()
}

Expand All @@ -71,7 +73,7 @@ internal extension Graph {
return cacheItem

} else {
let location = Graph.CacheItem.Location(inParent: Cache.cacheDirectory(), hash: hash)
let location = Graph.CacheItem.Location(inParent: self.cacheDirectory, hash: hash)
if let cacheItem = CacheItem(at: location) {

self.setInMemory(cacheItem)
Expand All @@ -85,15 +87,15 @@ internal extension Graph {
func set(_ cacheItem: CacheItem) {
self.setInMemory(cacheItem)

let location = Graph.CacheItem.Location(inParent: Cache.cacheDirectory(), hash: cacheItem.hash)
let location = Graph.CacheItem.Location(inParent: self.cacheDirectory, hash: cacheItem.hash)

cacheItem.write(to: location)
}

func remove(for hash: Hash) {
self.removeInMemory(for: hash)

let location = Graph.CacheItem.Location(inParent: Cache.cacheDirectory(), hash: hash)
let location = Graph.CacheItem.Location(inParent: self.cacheDirectory, hash: hash)
do {
try Cache.fileManager.removeItem(at: location.dataURL)
try Cache.fileManager.removeItem(at: location.metaURL)
Expand All @@ -120,9 +122,13 @@ internal extension Graph {
// ----------------------------------
// MARK: - File System Cache -
//
static func cacheDirectory() -> URL {
private static func cacheDirectory(for shopName: String) -> URL {
let tmp = URL(fileURLWithPath: NSTemporaryDirectory())
let url = tmp.appendingPathComponent(Cache.cacheName)
var url = tmp

url = url.appendingPathComponent(Cache.cacheName)
url = url.appendingPathComponent(Global.frameworkVersion)
url = url.appendingPathComponent(MD5.hash(shopName))

return url
}
Expand Down
5 changes: 3 additions & 2 deletions Buy/Client/Graph.Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ extension Graph {
/// The `URLSession` backing all `Client` network operations. You can provide your own session when initializing a new `Client`.
public let session: URLSession

internal let cache = Cache()
internal let cache: Cache

internal let apiURL: URL
internal let headers: [String : String]

Expand All @@ -84,6 +84,7 @@ extension Graph {

let shopURL = Client.urlFor(shopDomain)
self.apiURL = Client.urlFor(shopDomain, path: "/api/graphql")
self.cache = Cache(shopName: shopDomain)
self.session = session
self.headers = [
Header.userAgent : Global.userAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(note: String? = nil, customAttributes: [AttributeInput]? = nil, allowPartialAddresses: Bool? = nil) {
self.init(note: note.orNull, customAttributes: customAttributes.orNull, allowPartialAddresses: allowPartialAddresses.orNull)
self.init(note: note.orUndefined, customAttributes: customAttributes.orUndefined, allowPartialAddresses: allowPartialAddresses.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CheckoutCreateInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(email: String? = nil, lineItems: [CheckoutLineItemInput]? = nil, shippingAddress: MailingAddressInput? = nil, note: String? = nil, customAttributes: [AttributeInput]? = nil, allowPartialAddresses: Bool? = nil) {
self.init(email: email.orNull, lineItems: lineItems.orNull, shippingAddress: shippingAddress.orNull, note: note.orNull, customAttributes: customAttributes.orNull, allowPartialAddresses: allowPartialAddresses.orNull)
self.init(email: email.orUndefined, lineItems: lineItems.orUndefined, shippingAddress: shippingAddress.orUndefined, note: note.orUndefined, customAttributes: customAttributes.orUndefined, allowPartialAddresses: allowPartialAddresses.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CheckoutLineItemInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(quantity: Int32, variantId: GraphQL.ID, customAttributes: [AttributeInput]? = nil) {
self.init(quantity: quantity, variantId: variantId, customAttributes: customAttributes.orNull)
self.init(quantity: quantity, variantId: variantId, customAttributes: customAttributes.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CheckoutLineItemUpdateInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(id: GraphQL.ID? = nil, variantId: GraphQL.ID? = nil, quantity: Int32? = nil, customAttributes: [AttributeInput]? = nil) {
self.init(id: id.orNull, variantId: variantId.orNull, quantity: quantity.orNull, customAttributes: customAttributes.orNull)
self.init(id: id.orUndefined, variantId: variantId.orUndefined, quantity: quantity.orUndefined, customAttributes: customAttributes.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CreditCardPaymentInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(amount: Decimal, idempotencyKey: String, billingAddress: MailingAddressInput, vaultId: String, test: Bool? = nil) {
self.init(amount: amount, idempotencyKey: idempotencyKey, billingAddress: billingAddress, vaultId: vaultId, test: test.orNull)
self.init(amount: amount, idempotencyKey: idempotencyKey, billingAddress: billingAddress, vaultId: vaultId, test: test.orUndefined)
}

internal func serialize() -> String {
Expand Down
3 changes: 3 additions & 0 deletions Buy/Generated/Storefront/CurrencyCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ extension Storefront {
/// Syrian Pound (SYP)
case syp = "SYP"

/// Swazi Lilangeni (SZL)
case szl = "SZL"

/// Thai baht (THB)
case thb = "THB"

Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CustomerCreateInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(email: String, password: String, firstName: String? = nil, lastName: String? = nil, phone: String? = nil, acceptsMarketing: Bool? = nil) {
self.init(email: email, password: password, firstName: firstName.orNull, lastName: lastName.orNull, phone: phone.orNull, acceptsMarketing: acceptsMarketing.orNull)
self.init(email: email, password: password, firstName: firstName.orUndefined, lastName: lastName.orUndefined, phone: phone.orUndefined, acceptsMarketing: acceptsMarketing.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/CustomerUpdateInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(firstName: String? = nil, lastName: String? = nil, email: String? = nil, phone: String? = nil, password: String? = nil, acceptsMarketing: Bool? = nil) {
self.init(firstName: firstName.orNull, lastName: lastName.orNull, email: email.orNull, phone: phone.orNull, password: password.orNull, acceptsMarketing: acceptsMarketing.orNull)
self.init(firstName: firstName.orUndefined, lastName: lastName.orUndefined, email: email.orUndefined, phone: phone.orUndefined, password: password.orUndefined, acceptsMarketing: acceptsMarketing.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/MailingAddressInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(address1: String? = nil, address2: String? = nil, city: String? = nil, company: String? = nil, country: String? = nil, firstName: String? = nil, lastName: String? = nil, phone: String? = nil, province: String? = nil, zip: String? = nil) {
self.init(address1: address1.orNull, address2: address2.orNull, city: city.orNull, company: company.orNull, country: country.orNull, firstName: firstName.orNull, lastName: lastName.orNull, phone: phone.orNull, province: province.orNull, zip: zip.orNull)
self.init(address1: address1.orUndefined, address2: address2.orUndefined, city: city.orUndefined, company: company.orUndefined, country: country.orUndefined, firstName: firstName.orUndefined, lastName: lastName.orUndefined, phone: phone.orUndefined, province: province.orUndefined, zip: zip.orUndefined)
}

internal func serialize() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Buy/Generated/Storefront/TokenizedPaymentInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension Storefront {
///
@available(*, deprecated, message: "Use the static create() method instead.")
public convenience init(amount: Decimal, idempotencyKey: String, billingAddress: MailingAddressInput, type: String, paymentData: String, test: Bool? = nil, identifier: String? = nil) {
self.init(amount: amount, idempotencyKey: idempotencyKey, billingAddress: billingAddress, type: type, paymentData: paymentData, test: test.orNull, identifier: identifier.orNull)
self.init(amount: amount, idempotencyKey: idempotencyKey, billingAddress: billingAddress, type: type, paymentData: paymentData, test: test.orUndefined, identifier: identifier.orUndefined)
}

internal func serialize() -> String {
Expand Down
16 changes: 14 additions & 2 deletions BuyTests/Client/Graph.CacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import XCTest

class Graph_CacheTests: XCTestCase {

let shopDomain = "cachetests.myshopify.com"

enum Query {
case one
case two
Expand All @@ -47,10 +49,20 @@ class Graph_CacheTests: XCTestCase {
// MARK: - Init -
//
func testInit() {
let cache = Graph.Cache()
let cache = Graph.Cache(shopName: self.shopDomain)
XCTAssertNotNil(cache)
}

// ----------------------------------
// MARK: - Cache Directory -
//
func testShopDependantDirectory() {
let cache1 = Graph.Cache(shopName: "store1")
let cache2 = Graph.Cache(shopName: "store2")

XCTAssertNotEqual(cache1.cacheDirectory, cache2.cacheDirectory)
}

// ----------------------------------
// MARK: - Purge -
//
Expand Down Expand Up @@ -154,7 +166,7 @@ class Graph_CacheTests: XCTestCase {
// MARK: - Private -
//
private func defaultCache() -> Graph.Cache {
return Graph.Cache()
return Graph.Cache(shopName: self.shopDomain)
}

private func defaultRequest(query: Query = .one) -> URLRequest {
Expand Down
4 changes: 2 additions & 2 deletions BuyTests/Client/Graph.TaskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import XCTest

class Graph_TaskTests: XCTestCase {

let cache = Graph.Cache()
let cache = Graph.Cache(shopName: "tasktests.myshopify.com")
let url = URL(string: "https://www.google.com")!

// ----------------------------------
// MARK: - Init -
//
func testInit() {
let session = MockSession()
let cache = Graph.Cache()
let cache = Graph.Cache(shopName: "shop.myshopify.com")
let payload = self.defaultQueryPayload()
let request = self.defaultRequest(for: payload.query)
let retry = Graph.RetryHandler<Storefront.QueryRoot> { query, error in
Expand Down
2 changes: 1 addition & 1 deletion Dependencies/Swift Gen
2 changes: 1 addition & 1 deletion Mobile-Buy-SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'Mobile-Buy-SDK'
s.version = '3.1.1'
s.version = '3.1.2'
s.summary = 'Create custom Shopify storefront on iOS.'
s.description = 'Shopify’s Mobile Buy SDK makes it simple to create custom storefronts in your mobile app. Utitlizing the power and flexibility of GraphQL you can build native storefront experiences using the Shopify platform.'
s.homepage = 'https://github.com/Shopify/mobile-buy-sdk-ios'
Expand Down
Loading

0 comments on commit 3f2d874

Please sign in to comment.