Skip to content
Browse files

Made the initializer take the API key and optional queue name. Allowe…

…d for attachments to be sent.
  • Loading branch information...
1 parent 1eebc25 commit 8dc1506888735ddbe21f679a278ae2337e9ba421 @coneybeare coneybeare committed
Showing with 34 additions and 12 deletions.
  1. +11 −6 SSPostmark.h
  2. +23 −6 SSPostmark.m
View
17 SSPostmark.h
@@ -49,12 +49,6 @@
/**
*
- * Set your API key
- *
- */
-#define pm_YOUR_API_KEY @"POSTMARK_API_TEST"
-/**
- *
* Set async queue name
*
*/
@@ -84,6 +78,11 @@ static const NSString *kSSPostmarkTag = @"Tag"; // Expects NSString
static const NSString *kSSPostmarkReplyTo = @"ReplyTo"; // Expects NSString
static const NSString *kSSPostmarkHeaders = @"Headers";// Expects NSDictionary :: OPTIONAL
+// See http://developer.postmarkapp.com/developer-build.html#attachments
+static const NSString *kSSPostmarkAttachments = @"Attachments";// :: OPTIONAL :: Expects NSArray of NSDictionaries with the following attachment keys
+static const NSString *kSSPostmarkAttachmentName = @"Name";// Expects NSString
+static const NSString *kSSPostmarkAttachmentContent = @"Content";// Expects Base64-encoded binary content as an NSString
+static const NSString *kSSPostmarkAttachmentContentType = @"ContentType";// Expects NSString
/**
*
* Response Keys
@@ -100,9 +99,14 @@ static const NSString *kSSPostmarkResp_To = @"To";
@class SSPostmarkMessage;
@interface SSPostmark : NSObject <NSURLConnectionDataDelegate, NSURLConnectionDelegate>
+@property (nonatomic, retain) NSString *apiKey;
+@property (nonatomic, retain) NSString *queueName;
@property (nonatomic, assign) id <SSPostmarkDelegate> delegate;
+- (id)initWithApiKey:(NSString *)apiKey;
+- (id)initWithApiKey:(NSString *)apiKey queueName:(NSString *)queueName;
+
- (void)sendEmailWithParamaters:(NSDictionary *)params asynchronously:(BOOL)async __attribute__((deprecated("Use sendEmail: instead")));
- (void)sendEmail:(SSPostmarkMessage *)message;
- (void)sendBatchMessages:(NSArray *)messages;
@@ -154,6 +158,7 @@ typedef enum {
@property (nonatomic, retain) NSString *cc;
@property (nonatomic, retain) NSString *bcc;
@property (nonatomic, retain) NSDictionary *headers;
+@property (nonatomic, retain) NSArray *attachments;
- (BOOL)isValid;
- (NSDictionary *)asDict;
View
29 SSPostmark.m
@@ -1,4 +1,4 @@
-/***
+ /***
* QuietSight Framework
* @author - Skylar Schipper
* @copyright - (2011 - 2012) (c) Skylar Schipper
@@ -62,7 +62,19 @@ - (void)_send:(NSData *)data toURL:(NSURL *)url;
@end
@implementation SSPostmark
-@synthesize delegate;
+@synthesize apiKey = _apiKey, queueName = _queueName, delegate;
+
+- (id)initWithApiKey:(NSString *)apiKey queueName:(NSString *)queueName {
+ if ((self = [super init])) {
+ self.apiKey = apiKey;
+ self.queueName = queueName;
+ }
+ return self;
+}
+- (id)initWithApiKey:(NSString *)apiKey {
+ return [self initWithApiKey:apiKey queueName:pm_ASYNC_QUEUE_NAME];
+}
+
- (void)sendEmailWithParamaters:(NSDictionary *)params asynchronously:(BOOL)async {
if (async) {
@@ -71,7 +83,7 @@ - (void)sendEmailWithParamaters:(NSDictionary *)params asynchronously:(BOOL)asyn
[self sendEmailWithParamaters:params];
}];
NSOperationQueue* queue = [[NSOperationQueue alloc]init];
- queue.name = pm_ASYNC_QUEUE_NAME;
+ queue.name = self.queueName;
[queue addOperation:opp];
} else {
[self sendEmailWithParamaters:params];
@@ -188,7 +200,8 @@ - (void)_send:(NSData *)data toURL:(NSURL *)url {
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse * resp = (NSHTTPURLResponse *)response;
- if (resp.statusCode == 422) {
+ NSInteger code = resp.statusCode;
+ if (code >= 400) {
[NSNotification notificationWithName:pm_POSTMARK_NOTIFICATION
object:self
userInfo:[NSDictionary dictionaryWithObject:@"failed" forKey:@"status"]];
@@ -253,7 +266,7 @@ - (id)parseJSON:(NSData *)data {
- (void)createHeaders {
[_request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
- [_request setValue:pm_YOUR_API_KEY forHTTPHeaderField:@"X-Postmark-Server-Token"];
+ [_request setValue:self.apiKey forHTTPHeaderField:@"X-Postmark-Server-Token"];
}
- (BOOL)isValidMailDict:(NSDictionary *)message{
if (![message objectForKey:kSSPostmarkFrom]) {
@@ -312,7 +325,8 @@ @implementation SSPostmarkMessage
replyTo = _replyTo,
cc = _cc,
bcc = _bcc,
-headers = _headers;
+headers = _headers,
+attachments = _attachments;
- (BOOL)isValid {
@@ -358,6 +372,9 @@ - (NSDictionary *)asDict {
if (self.headers != nil) {
[d setObject:self.headers forKey:kSSPostmarkHeaders];
}
+ if (self.attachments != nil) {
+ [d setObject:self.attachments forKey:kSSPostmarkAttachments];
+ }
return d;
}

0 comments on commit 8dc1506

Please sign in to comment.
Something went wrong with that request. Please try again.