Skip to content
This repository has been archived by the owner on Feb 17, 2018. It is now read-only.

Commit

Permalink
Conform SSPostmarkEmail & SSPostmarkAttachment to NSCoding.
Browse files Browse the repository at this point in the history
closes #16
  • Loading branch information
Skylar Schipper committed Jun 16, 2013
1 parent 0fbf9af commit 32ef66c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SSPostmark/SSPostmarkAttachment.h
Expand Up @@ -18,7 +18,7 @@ extern NSString * const SSPostmarkAttachmentInvalidNameException;
Postmark will handle sending attachments with emails as long as the raw data doesn't exceed 10MB per message total.
*/
@interface SSPostmarkAttachment : NSObject
@interface SSPostmarkAttachment : NSObject <NSCoding>

/** The name for the attached file
Expand Down
17 changes: 17 additions & 0 deletions SSPostmark/SSPostmarkAttachment.m
Expand Up @@ -113,6 +113,23 @@ - (NSData *)binaryJSON {
return [NSJSONSerialization dataWithJSONObject:[self asJSONObject] options:0 error:nil];
}

#pragma mark -
#pragma mark - coding
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.name forKey:@"name"];
[aCoder encodeObject:self.content forKey:@"content"];
[aCoder encodeObject:self.contentType forKey:@"contentType"];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [self init];
if (self) {
self.name = [aDecoder decodeObjectForKey:@"name"];
self.content = [aDecoder decodeObjectForKey:@"content"];
self.contentType = [aDecoder decodeObjectForKey:@"contentType"];
}
return self;
}

@end

NSString * const SSPostmarkAttachmentInvalidNameException = @"SSPostmarkAttachmentInvalidNameException";
2 changes: 1 addition & 1 deletion SSPostmark/SSPostmarkEmail.h
Expand Up @@ -47,7 +47,7 @@
/** The email object that represents a Postmark Email
*/
@interface SSPostmarkEmail : NSObject
@interface SSPostmarkEmail : NSObject <NSCoding>

/** Who to send the email to
Expand Down
33 changes: 33 additions & 0 deletions SSPostmark/SSPostmarkEmail.m
Expand Up @@ -273,4 +273,37 @@ - (NSString *)description {
return [NSString stringWithFormat:@"%@ Tag: \"%@\" Subject: \"%@\" From: \"%@\" To: %@\nBody: %@\nCustom Headers: %@",NSStringFromClass([self class]),self.tag,self.subject,self.fromAddress,self.toAddresses,self.body,self.customHeaders];
}

#pragma mark -
#pragma mark - Coding
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.toAddresses forKey:@"toAddresses"];
[aCoder encodeObject:self.ccAddresses forKey:@"ccAddresses"];
[aCoder encodeObject:self.bccAddresses forKey:@"bccAddresses"];
[aCoder encodeObject:self.fromAddress forKey:@"fromAddress"];
[aCoder encodeObject:self.nameForFromAddress forKey:@"nameForFromAddress"];
[aCoder encodeObject:self.replyTo forKey:@"replyTo"];
[aCoder encodeObject:self.subject forKey:@"subject"];
[aCoder encodeObject:self.body forKey:@"body"];
[aCoder encodeBool:self.html forKey:@"html"];
[aCoder encodeObject:self.attachments forKey:@"attachments"];
[aCoder encodeObject:self.customHeaders forKey:@"customHeaders"];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [self init];
if (self) {
self.toAddresses = [aDecoder decodeObjectForKey:@"toAddresses"];
self.ccAddresses = [aDecoder decodeObjectForKey:@"ccAddresses"];
self.bccAddresses = [aDecoder decodeObjectForKey:@"bccAddresses"];
self.fromAddress = [aDecoder decodeObjectForKey:@"fromAddress"];
self.nameForFromAddress = [aDecoder decodeObjectForKey:@"nameForFromAddress"];
self.replyTo = [aDecoder decodeObjectForKey:@"replyTo"];
self.subject = [aDecoder decodeObjectForKey:@"subject"];
self.body = [aDecoder decodeObjectForKey:@"body"];
self.html = [aDecoder decodeBoolForKey:@"html"];
self.attachments = [aDecoder decodeObjectForKey:@"attachments"];
self.customHeaders = [aDecoder decodeObjectForKey:@"customHeaders"];
}
return self;
}

@end

0 comments on commit 32ef66c

Please sign in to comment.