Permalink
Browse files

Merge branch 'master' of github.com:skylarsch/SSPostmark

  • Loading branch information...
2 parents 69ee790 + 6e3b3f0 commit 5e1a12fd5abd0a527a07adfa739020b72beb1c8d @skylarsch committed Dec 22, 2012
View
@@ -59,13 +59,6 @@
*/
- (BOOL)sendMessage:(SSPostmarkMessage *)message;
-/** <#Description#>
-
- <#Discussion#>
-
- */
-- (BOOL)sendMessage:(SSPostmarkMessage *)message completionHandler:(void (^)(void))completionHandler;
-
/** <#Description#>
<#Discussion#>
View
@@ -37,10 +37,7 @@ @implementation SSPostmark
#pragma mark -
#pragma mark - Sending Postmark Messages
- (BOOL)sendMessage:(SSPostmarkMessage *)message {
- return [self ss_SendMessage:message completionHandler:nil];
-}
-- (BOOL)sendMessage:(SSPostmarkMessage *)message completionHandler:(void (^)(void))completionHandler {
- return [self ss_SendMessage:message completionHandler:completionHandler];
+ return [self ss_SendMessage:message];
}
@@ -76,7 +73,7 @@ + (NSURL *)postmarkBatchAPIURL {
#pragma mark -
#pragma mark - Private helper methods
-- (BOOL)ss_SendMessage:(SSPostmarkMessage *)message completionHandler:(void (^)(void))completionHandler {
+- (BOOL)ss_SendMessage:(SSPostmarkMessage *)message {
if (![message isValid]) {
return NO;
}
@@ -99,7 +96,9 @@ - (BOOL)ss_SendMessage:(SSPostmarkMessage *)message completionHandler:(void (^)(
if (JSONError != nil) {
return;
}
- NSLog(@"(%i) :: %@",response.statusCode,JSON);
+ if (message.completion) {
+ message.completion(message, response.statusCode, JSON);
+ }
}];
return YES;
}
@@ -40,7 +40,9 @@ NSString static const *kSSPostmarkHeaders = @"Headers";
NSString static const *kSSPostmarkAttachments = @"Attachments";
-@class SSPostmarkAttachment;
+@class SSPostmarkAttachment, SSPostmarkMessage;
+
+typedef void (^SSPostmarkMessageCompletion)(SSPostmarkMessage *message, NSUInteger statusCode, NSDictionary *responseJSON);
/** <#Description#>
@@ -171,4 +173,18 @@ NSString static const *kSSPostmarkAttachments = @"Attachments";
*/
@property (nonatomic, readonly, getter = isValid) BOOL valid;
+#pragma mark -
+
+/** <#Description#>
+
+ <#Discussion#>
+ */
+@property (nonatomic, copy) SSPostmarkMessageCompletion completion;
+
+/** <#Description#>
+
+ <#Discussion#>
+ */
+- (void)addCompletionBlock:(SSPostmarkMessageCompletion)completion;
+
@end
@@ -96,4 +96,11 @@ - (void)removeAttachments:(NSSet *)objects {
}
}
+
+#pragma mark -
+#pragma mark -
+- (void)addCompletionBlock:(SSPostmarkMessageCompletion)completion {
+ _completion = completion;
+}
+
@end
@@ -19,16 +19,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
-
- NSLog(@"SSPostmark Version: '%@'",[SSPostmark version]);
-
SSPostmarkMessage *message = [SSPostmarkMessage new];
message.fromEmail = @"ss@schipp.co";
message.replyTo = @"ss@schipp.co";
message.to = @"ss@schipp.co";
message.textBody = @"Test Email";
message.subject = @"Just a test";
message.tag = @"sspm-test";
+ [message addCompletionBlock:^(SSPostmarkMessage *message, NSUInteger statusCode, NSDictionary *responseJSON) {
+ NSLog(@"(%i)\n%@",statusCode,responseJSON);
+ }];
SSPostmarkAttachment *att = [[SSPostmarkAttachment alloc] init];
att.content = UIImagePNGRepresentation([UIImage imageNamed:@"sunset.jpg"]);

0 comments on commit 5e1a12f

Please sign in to comment.