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

Commit

Permalink
Made the initializer take the API key and optional queue name. Allowe…
Browse files Browse the repository at this point in the history
…d for attachments to be sent.
  • Loading branch information
coneybeare committed Jun 18, 2012
1 parent 1eebc25 commit 8dc1506
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
17 changes: 11 additions & 6 deletions SSPostmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
#warning "This project uses NSJSONSerialization. Only available in iOS >= 5.0"
#endif

/**
*
* Set your API key
*
*/
#define pm_YOUR_API_KEY @"POSTMARK_API_TEST"
/**
*
* Set async queue name
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 23 additions & 6 deletions SSPostmark.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***
/***
* QuietSight Framework
* @author - Skylar Schipper
* @copyright - (2011 - 2012) (c) Skylar Schipper
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
Expand Down Expand Up @@ -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"]];
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -312,7 +325,8 @@ @implementation SSPostmarkMessage
replyTo = _replyTo,
cc = _cc,
bcc = _bcc,
headers = _headers;
headers = _headers,
attachments = _attachments;


- (BOOL)isValid {
Expand Down Expand Up @@ -357,6 +371,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;
}
Expand Down

0 comments on commit 8dc1506

Please sign in to comment.