Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
6a53263e
Commit
6a53263e
authored
Jun 07, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BUYStatusOperation aggregate operation and super class.
parent
e7632aba
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
382 additions
and
70 deletions
+382
-70
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+16
-0
BUYClient+Checkout.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
+11
-1
BUYClient+Internal.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
+4
-0
BUYAggregateOperation.h
...Buy SDK/Mobile Buy SDK/Operations/BUYAggregateOperation.h
+39
-0
BUYAggregateOperation.m
...Buy SDK/Mobile Buy SDK/Operations/BUYAggregateOperation.m
+127
-0
BUYCheckoutOperation.h
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.h
+3
-6
BUYCheckoutOperation.m
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
+15
-63
BUYStatusOperation.h
...le Buy SDK/Mobile Buy SDK/Operations/BUYStatusOperation.h
+42
-0
BUYStatusOperation.m
...le Buy SDK/Mobile Buy SDK/Operations/BUYStatusOperation.m
+125
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
6a53263e
...
...
@@ -249,6 +249,10 @@
9A585C0B1CE6440B001F20F0
/* BUYOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A585C041CE6440B001F20F0
/* BUYOperation.h */
;
};
9A585C0D1CE6440B001F20F0
/* BUYOperation.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A585C051CE6440B001F20F0
/* BUYOperation.m */
;
};
9A6B03791CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6B03781CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m */
;
};
9A6C1D411D07485F00BFF4F9
/* BUYStatusOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6C1D3F1D07485F00BFF4F9
/* BUYStatusOperation.h */
;
};
9A6C1D421D07485F00BFF4F9
/* BUYStatusOperation.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6C1D401D07485F00BFF4F9
/* BUYStatusOperation.m */
;
};
9A6C1D451D0749FC00BFF4F9
/* BUYAggregateOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6C1D431D0749FC00BFF4F9
/* BUYAggregateOperation.h */
;
};
9A6C1D461D0749FC00BFF4F9
/* BUYAggregateOperation.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6C1D441D0749FC00BFF4F9
/* BUYAggregateOperation.m */
;
};
9A7652C31CF487BD00220E4B
/* BUYOperationTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A7652C21CF487BD00220E4B
/* BUYOperationTests.m */
;
};
9A807E841CF74EBE00023160
/* BUYClient+Address.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A807E811CF74EBE00023160
/* BUYClient+Address.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9A807E861CF74EBE00023160
/* BUYClient+Address.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A807E821CF74EBE00023160
/* BUYClient+Address.m */
;
};
...
...
@@ -491,6 +495,10 @@
9A585C111CE65811001F20F0
/* BUYRequestOperation.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYRequestOperation.h
;
sourceTree
=
"<group>"
;
};
9A585C121CE65811001F20F0
/* BUYRequestOperation.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYRequestOperation.m
;
sourceTree
=
"<group>"
;
};
9A6B03781CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYAccountCredentialsTests.m
;
sourceTree
=
"<group>"
;
};
9A6C1D3F1D07485F00BFF4F9
/* BUYStatusOperation.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYStatusOperation.h
;
sourceTree
=
"<group>"
;
};
9A6C1D401D07485F00BFF4F9
/* BUYStatusOperation.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYStatusOperation.m
;
sourceTree
=
"<group>"
;
};
9A6C1D431D0749FC00BFF4F9
/* BUYAggregateOperation.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYAggregateOperation.h
;
sourceTree
=
"<group>"
;
};
9A6C1D441D0749FC00BFF4F9
/* BUYAggregateOperation.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYAggregateOperation.m
;
sourceTree
=
"<group>"
;
};
9A7652C21CF487BD00220E4B
/* BUYOperationTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYOperationTests.m
;
sourceTree
=
"<group>"
;
};
9A807E811CF74EBE00023160
/* BUYClient+Address.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"BUYClient+Address.h"
;
sourceTree
=
"<group>"
;
};
9A807E821CF74EBE00023160
/* BUYClient+Address.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+Address.m"
;
sourceTree
=
"<group>"
;
};
...
...
@@ -826,6 +834,10 @@
9A0B0CAB1CEDDBD80037D68F
/* Aggregate */
=
{
isa
=
PBXGroup
;
children
=
(
9A6C1D431D0749FC00BFF4F9
/* BUYAggregateOperation.h */
,
9A6C1D441D0749FC00BFF4F9
/* BUYAggregateOperation.m */
,
9A6C1D3F1D07485F00BFF4F9
/* BUYStatusOperation.h */
,
9A6C1D401D07485F00BFF4F9
/* BUYStatusOperation.m */
,
9A0B0CA51CED0A860037D68F
/* BUYCheckoutOperation.h */
,
9A0B0CA61CED0A860037D68F
/* BUYCheckoutOperation.m */
,
);
...
...
@@ -1064,6 +1076,7 @@
84B0A7311CE10ED900253EB0
/* BUYApplePayPaymentProvider.h in Headers */
,
9019313C1BC5B9BC00D1134E
/* BUYShop.h in Headers */
,
9019313D1BC5B9BC00D1134E
/* BUYShippingRate.h in Headers */
,
9A6C1D451D0749FC00BFF4F9
/* BUYAggregateOperation.h in Headers */
,
9019313E1BC5B9BC00D1134E
/* BUYApplePayAdditions.h in Headers */
,
9A807E841CF74EBE00023160
/* BUYClient+Address.h in Headers */
,
84980F531CB7616900CFAB58
/* BUYDecimalNumberTransformer.h in Headers */
,
...
...
@@ -1086,6 +1099,7 @@
84980F331CB75C2900CFAB58
/* NSEntityDescription+BUYAdditions.h in Headers */
,
901931491BC5B9BC00D1134E
/* BUYGiftCard.h in Headers */
,
84CD7C2E1CC65D5A00B6EE61
/* _BUYCheckoutAttribute.h in Headers */
,
9A6C1D411D07485F00BFF4F9
/* BUYStatusOperation.h in Headers */
,
901931501BC5B9BC00D1134E
/* BUYOrder.h in Headers */
,
84D9154C1CC03F1600D334FB
/* BUYManagedObject.h in Headers */
,
84DD12CF1CC6401400A2442D
/* BUYCustomer.h in Headers */
,
...
...
@@ -1303,6 +1317,7 @@
84D73C091CDD194D000F978A
/* BUYAddress.m in Sources */
,
901931031BC5B9BC00D1134E
/* BUYOptionValue.m in Sources */
,
84980F551CB7616900CFAB58
/* BUYDecimalNumberTransformer.m in Sources */
,
9A6C1D421D07485F00BFF4F9
/* BUYStatusOperation.m in Sources */
,
901931041BC5B9BC00D1134E
/* BUYApplePayAdditions.m in Sources */
,
901931061BC5B9BC00D1134E
/* BUYDiscount.m in Sources */
,
9A0B0C5D1CE662EC0037D68F
/* BUYRequestOperation.m in Sources */
,
...
...
@@ -1324,6 +1339,7 @@
84DD12C81CC63FEE00A2442D
/* _BUYMaskedCreditCard.m in Sources */
,
84DD12AC1CC63FE600A2442D
/* _BUYProduct.m in Sources */
,
84DD12A21CC63FE600A2442D
/* _BUYImageLink.m in Sources */
,
9A6C1D461D0749FC00BFF4F9
/* BUYAggregateOperation.m in Sources */
,
841ADE1A1CB6C942000004B0
/* NSRegularExpression+BUYAdditions.m in Sources */
,
8498DCBE1CDD1FA400BD12A8
/* BUYAccountCredentials.m in Sources */
,
9032F2DD1BE9457A00BB9EEF
/* BUYCheckoutAttribute.m in Sources */
,
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
View file @
6a53263e
...
...
@@ -29,6 +29,7 @@
#import "BUYClient+Routing.h"
#import "BUYRequestOperation.h"
#import "BUYCheckoutOperation.h"
#import "BUYStatusOperation.h"
#import "BUYAddress.h"
#import "BUYCheckout.h"
#import "BUYGiftCard.h"
...
...
@@ -104,7 +105,7 @@
-
(
BUYOperation
*
)
completeCheckoutWithToken
:(
NSString
*
)
checkoutToken
paymentToken
:(
id
<
BUYPaymentToken
>
)
paymentToken
completion
:(
BUYDataCheckoutBlock
)
block
{
BUYCheckoutOperation
*
operation
=
[
[
BUYCheckoutOperation
alloc
]
init
WithClient
:
self
checkoutToken
:
checkoutToken
token
:
paymentToken
completion
:
block
];
BUYCheckoutOperation
*
operation
=
[
BUYCheckoutOperation
operation
WithClient
:
self
checkoutToken
:
checkoutToken
token
:
paymentToken
completion
:
block
];
[
self
startOperation
:
operation
];
return
operation
;
}
...
...
@@ -152,6 +153,15 @@
}];
}
-
(
NSOperation
*
)
pollCompletionStatusAndGetCheckoutWithToken
:(
NSString
*
)
token
start
:(
BOOL
)
start
completion
:(
BUYDataCheckoutBlock
)
block
{
BUYStatusOperation
*
operation
=
[
BUYStatusOperation
operationWithClient
:
self
checkoutToken
:
token
completion
:
block
];
if
(
start
)
{
[
self
startOperation
:
operation
];
}
return
operation
;
}
-
(
NSOperation
*
)
postCheckout
:(
NSDictionary
*
)
checkoutJSON
completion
:(
BUYDataCheckoutBlock
)
block
{
return
[
self
postRequestForURL
:[
self
urlForCheckouts
]
object
:
checkoutJSON
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
View file @
6a53263e
...
...
@@ -35,6 +35,10 @@ typedef void (^BUYClientRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResp
@interface
BUYClient
(
Internal
)
@property
(
nonatomic
,
strong
)
NSOperationQueue
*
requestQueue
;
-
(
NSOperation
*
)
pollCompletionStatusAndGetCheckoutWithToken
:(
NSString
*
)
token
start
:(
BOOL
)
start
completion
:(
BUYDataCheckoutBlock
)
block
;
-
(
NSOperation
*
)
getRequestForURL
:(
NSURL
*
)
url
completionHandler
:(
BUYClientRequestJSONCompletion
)
completionHandler
;
-
(
NSOperation
*
)
deleteRequestForURL
:(
NSURL
*
)
url
completionHandler
:(
BUYClientRequestJSONCompletion
)
completionHandler
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYAggregateOperation.h
0 → 100644
View file @
6a53263e
//
// BUYAggregateOperation.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYOperation.h"
@interface
BUYAggregateOperation
:
BUYOperation
@property
(
strong
,
atomic
)
NSArray
<
NSOperation
*>
*
operations
;
+
(
instancetype
)
operationWithQueue
:(
NSOperationQueue
*
)
queue
operations
:(
NSArray
<
NSOperation
*>
*
)
operations
;
-
(
instancetype
)
initWithQueue
:(
NSOperationQueue
*
)
queue
operations
:(
NSArray
<
NSOperation
*>
*
)
operations
;
-
(
void
)
finishWithObject
:(
id
)
object
;
-
(
void
)
finishWithError
:(
NSError
*
)
error
;
@end
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYAggregateOperation.m
0 → 100644
View file @
6a53263e
//
// BUYAggregateOperation.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYAggregateOperation.h"
@interface
BUYAggregateOperation
()
@property
(
strong
,
nonatomic
)
NSOperationQueue
*
queue
;
@end
@implementation
BUYAggregateOperation
#pragma mark - Init -
+
(
instancetype
)
operationWithQueue
:(
NSOperationQueue
*
)
queue
operations
:(
NSArray
<
NSOperation
*>
*
)
operations
{
return
[[[
self
class
]
alloc
]
initWithQueue
:
queue
operations
:
operations
];
}
-
(
instancetype
)
initWithQueue
:(
NSOperationQueue
*
)
queue
operations
:(
NSArray
<
NSOperation
*>
*
)
operations
{
self
=
[
super
init
];
if
(
self
)
{
_queue
=
queue
;
self
.
operations
=
operations
;
}
return
self
;
}
#pragma mark - Finishing -
-
(
void
)
finishWithObject
:(
id
)
object
{
if
(
self
.
cancelled
)
{
return
;
}
[
self
finishExecution
];
}
-
(
void
)
finishWithError
:(
NSError
*
)
error
{
if
(
self
.
cancelled
)
{
return
;
}
[
self
cancelAllOperations
];
[
self
finishExecution
];
}
#pragma mark - Execution -
-
(
void
)
startExecution
{
if
(
self
.
cancelled
)
{
return
;
}
[
super
startExecution
];
[
self
linkDependencies
];
[
self
startAllOperations
];
}
-
(
void
)
cancelExecution
{
[
super
cancelExecution
];
[
self
cancelAllOperations
];
}
#pragma mark - Dependencies -
-
(
void
)
linkDependencies
{
if
(
self
.
operations
.
count
>
1
)
{
int
i
=
(
int
)
self
.
operations
.
count
-
1
;
while
(
i
>
0
)
{
NSOperation
*
latter
=
self
.
operations
[
i
];
NSOperation
*
former
=
self
.
operations
[
i
-
1
];
[
latter
addDependency
:
former
];
i
--
;
}
}
}
#pragma mark - Start / Stop -
-
(
void
)
startAllOperations
{
for
(
NSOperation
*
operation
in
self
.
operations
)
{
[
self
.
queue
addOperation
:
operation
];
}
}
-
(
void
)
cancelAllOperations
{
for
(
NSOperation
*
operation
in
self
.
operations
)
{
[
operation
cancel
];
}
}
@end
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.h
View file @
6a53263e
...
...
@@ -24,7 +24,8 @@
// THE SOFTWARE.
//
#import <Buy/BUYOperation.h>
#import <Buy/BUYAggregateOperation.h>
#import <Buy/BUYStatusOperation.h>
NS_ASSUME_NONNULL_BEGIN
@class
BUYClient
;
...
...
@@ -32,11 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol
BUYPaymentToken
;
typedef
void
(
^
BUYCheckoutOperationCompletion
)(
BUYCheckout
*
_Nullable
checkout
,
NSError
*
_Nullable
error
);
@interface
BUYCheckoutOperation
:
BUYOperation
@property
(
strong
,
nonatomic
,
readonly
,
nonnull
)
BUYClient
*
client
;
@interface
BUYCheckoutOperation
:
BUYAggregateOperation
+
(
instancetype
)
operationWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
token
:(
id
<
BUYPaymentToken
>
)
token
completion
:(
BUYCheckoutOperationCompletion
)
completion
;
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
token
:(
id
<
BUYPaymentToken
>
)
token
completion
:(
BUYCheckoutOperationCompletion
)
completion
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
View file @
6a53263e
...
...
@@ -29,15 +29,15 @@
#import "BUYClient+Internal.h"
#import "BUYPaymentToken.h"
#import "BUYRequestOperation.h"
#import "BUYStatusOperation.h"
@interface
BUYCheckoutOperation
()
@property
(
strong
,
nonatomic
,
readonly
)
BUYClient
*
client
;
@property
(
strong
,
nonatomic
,
readonly
)
NSString
*
checkoutToken
;
@property
(
strong
,
nonatomic
,
readonly
)
id
<
BUYPaymentToken
>
token
;
@property
(
strong
,
nonatomic
,
readonly
)
BUYCheckoutOperationCompletion
completion
;
@property
(
strong
,
atomic
)
NSArray
*
operations
;
@end
@implementation
BUYCheckoutOperation
...
...
@@ -51,7 +51,7 @@
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
token
:(
id
<
BUYPaymentToken
>
)
token
completion
:(
BUYCheckoutOperationCompletion
)
completion
{
self
=
[
super
init
];
self
=
[
super
init
WithQueue
:
client
.
requestQueue
operations
:
nil
];
if
(
self
)
{
_client
=
client
;
_token
=
token
;
...
...
@@ -63,25 +63,23 @@
#pragma mark - Finishing -
-
(
void
)
finishWith
Checkout
:(
BUYCheckout
*
)
checkou
t
-
(
void
)
finishWith
Object
:(
id
)
objec
t
{
[
super
finishWithObject
:
object
];
if
(
self
.
cancelled
)
{
return
;
}
[
self
finishExecution
];
self
.
completion
(
checkout
,
nil
);
self
.
completion
(
object
,
nil
);
}
-
(
void
)
finishWithError
:(
NSError
*
)
error
{
[
super
finishWithError
:
error
];
if
(
self
.
cancelled
)
{
return
;
}
[
self
cancelAllOperations
];
[
self
finishExecution
];
self
.
completion
(
nil
,
error
);
}
...
...
@@ -93,44 +91,12 @@
return
;
}
[
super
startExecution
];
NSOperation
*
beginOperation
=
[
self
createBeginOperation
];
NSOperation
*
pollOperation
=
[
self
createPollOperation
];
NSOperation
*
getOperation
=
[
self
createGetOperation
];
[
pollOperation
addDependency
:
beginOperation
];
[
getOperation
addDependency
:
pollOperation
];
self
.
operations
=
@[
beginOperation
,
pollOperation
,
getOperation
,
[
self
createBeginOperation
],
[
self
createStatusOperation
],
];
[
self
startAllOperations
];
}
-
(
void
)
cancelExecution
{
[
super
cancelExecution
];
[
self
cancelAllOperations
];
}
#pragma mark - Start / Stop -
-
(
void
)
startAllOperations
{
for
(
BUYRequestOperation
*
operation
in
self
.
operations
)
{
[
self
.
client
startOperation
:
operation
];
}
}
-
(
void
)
cancelAllOperations
{
for
(
BUYRequestOperation
*
operation
in
self
.
operations
)
{
[
operation
cancel
];
}
[
super
startExecution
];
}
#pragma mark - Operations -
...
...
@@ -144,25 +110,11 @@
}];
}
-
(
NSOperation
*
)
createPollOperation
{
BUYRequestOperation
*
operation
=
(
BUYRequestOperation
*
)[
self
.
client
getCompletionStatusOfCheckoutWithToken
:
self
.
checkoutToken
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
status
!=
BUYStatusComplete
)
{
[
self
finishWithError
:
error
];
}
}];
operation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
return
response
.
statusCode
==
BUYStatusProcessing
;
};
return
operation
;
}
-
(
NSOperation
*
)
createGetOperation
-
(
NSOperation
*
)
createStatusOperation
{
return
[
self
.
client
g
etCheckoutWithToken
:
self
.
checkoutToken
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
return
[
self
.
client
pollCompletionStatusAndG
etCheckoutWithToken
:
self
.
checkoutToken
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
)
{
[
self
finishWith
Checkou
t
:
checkout
];
[
self
finishWith
Objec
t
:
checkout
];
}
else
{
[
self
finishWithError
:
error
];
}
...
...
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYStatusOperation.h
0 → 100644
View file @
6a53263e
//
// BUYStatusOperation.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYAggregateOperation.h"
NS_ASSUME_NONNULL_BEGIN
@class
BUYCheckout
;
@class
BUYClient
;
typedef
void
(
^
BUYCheckoutOperationCompletion
)(
BUYCheckout
*
_Nullable
checkout
,
NSError
*
_Nullable
error
);
@interface
BUYStatusOperation
:
BUYAggregateOperation
+
(
instancetype
)
operationWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
completion
:(
BUYCheckoutOperationCompletion
)
completion
;
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
completion
:(
BUYCheckoutOperationCompletion
)
completion
;
@end
NS_ASSUME_NONNULL_END
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYStatusOperation.m
0 → 100644
View file @
6a53263e
//
// BUYStatusOperation.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYStatusOperation.h"
#import "BUYClient+Checkout.h"
#import "BUYClient+Internal.h"
#import "BUYRequestOperation.h"
@interface
BUYStatusOperation
()
@property
(
strong
,
nonatomic
,
readonly
)
BUYClient
*
client
;
@property
(
strong
,
nonatomic
,
readonly
)
NSString
*
checkoutToken
;
@property
(
strong
,
nonatomic
,
readonly
)
BUYCheckoutOperationCompletion
completion
;
@end
@implementation
BUYStatusOperation
#pragma mark - Init -
+
(
instancetype
)
operationWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
completion
:(
BUYCheckoutOperationCompletion
)
completion
{
return
[[[
self
class
]
alloc
]
initWithClient
:
client
checkoutToken
:
checkoutToken
completion
:
completion
];
}
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
checkoutToken
:(
NSString
*
)
checkoutToken
completion
:(
BUYCheckoutOperationCompletion
)
completion
{
self
=
[
super
initWithQueue
:
client
.
requestQueue
operations
:
nil
];
if
(
self
)
{
_client
=
client
;
_completion
=
completion
;
_checkoutToken
=
checkoutToken
;
}
return
self
;
}
#pragma mark - Execution -
-
(
void
)
startExecution
{
if
(
self
.
cancelled
)
{
return
;
}
self
.
operations
=
@[
[
self
createPollOperation
],
[
self
createGetOperation
],
];
[
super
startExecution
];
}
#pragma mark - Finishing -
-
(
void
)
finishWithObject
:
(
id
)
object
{
[
super
finishWithObject
:
object
];
if
(
self
.
cancelled
)
{
return
;
}
self
.
completion
(
object
,
nil
);
}
-
(
void
)
finishWithError
:
(
NSError
*
)
error
{
[
super
finishWithError
:
error
];
if
(
self
.
cancelled
)
{
return
;
}
self
.
completion
(
nil
,
error
);
}
#pragma mark - Operations -
-
(
NSOperation
*
)
createPollOperation
{
BUYRequestOperation
*
operation
=
(
BUYRequestOperation
*
)[
self
.
client
getCompletionStatusOfCheckoutWithToken
:
self
.
checkoutToken
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
status
!=
BUYStatusComplete
)
{
[
self
finishWithError
:
error
];
}
}];
operation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
return
response
.
statusCode
==
BUYStatusProcessing
;
};
return
operation
;
}
-
(
NSOperation
*
)
createGetOperation
{
return
[
self
.
client
getCheckoutWithToken
:
self
.
checkoutToken
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
)
{
[
self
finishWithObject
:
checkout
];
}
else
{
[
self
finishWithError
:
error
];
}
}];
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment