Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendGrid API now available for OS X as well! :-) #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Classes/SendGrid.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ - (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObje
{
for (int i = 0; i < email.imgs.count; i++)
{
UIImage *img = [email.imgs objectAtIndex:i];
#if TARGET_IPHONE_OS
UIImage *img = [email.imgs objectAtIndex:i];
#else
NSImage *img = [email.imgs objectAtIndex:i];
#endif
NSString *filename = [NSString stringWithFormat:@"image%d.png", i];
NSString *name = [NSString stringWithFormat:@"files[image%d.png]", i];
NSLog(@"name: %@, Filename: %@", name, filename);
NSData *imageData = UIImagePNGRepresentation(img);
[formData appendPartWithFileData:imageData name:name fileName:filename mimeType:@"image/png"];
#if TARGET_IPHONE_OS
NSData *imageData = UIImagePNGRepresentation(img);
NSString *mimeType = @"image/png";
#else
// TODO: Find UIImagePNGRepresentation for NSImage. TIFF probably huge
NSData *imageData = [img TIFFRepresentation];
NSString *mimeType = @"image/tiff";
#endif
[formData appendPartWithFileData:imageData name:name fileName:filename mimeType:mimeType];
}
}
success:^(AFHTTPRequestOperation *operation, id responseObject)
Expand Down
5 changes: 4 additions & 1 deletion Classes/SendGridEmail.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "SMTPAPI.h"
#import "SendGridEmailAttachment.h"

Expand Down Expand Up @@ -40,7 +39,11 @@
- (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)parameterName parameterValue:(NSString *)parameterValue;
- (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)parameterName parameterIntValue:(int)parameterIntValue;

#if TARGET_IPHONE_OS
- (void)attachImage:(UIImage *)img;
#else
- (void)attachImage:(NSImage *)img;
#endif
- (void)attachFile:(SendGridEmailAttachment *)attachment;
- (NSDictionary *)parametersDictionary:(NSString *)apiUser apiKey:(NSString *)apiKey;

Expand Down
18 changes: 11 additions & 7 deletions Classes/SendGridEmail.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ - (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)pa
return self;
}

- (void)attachImage:(UIImage *)img
#if TARGET_IPHONE_OS
- (void)attachImage:(UIImage *)img;
#else
- (void)attachImage:(NSImage *)img;
#endif
{
if (self.imgs == NULL)
self.imgs = [[NSMutableArray alloc] init];
if (self.imgs == NULL) {
self.imgs = [NSMutableArray new];
}
[self.imgs addObject:img];
}

Expand All @@ -82,15 +87,14 @@ - (void)attachFile:(SendGridEmailAttachment *)attachment
[self.attachments addObject:attachment];
}

- (NSDictionary *)parametersDictionary:(NSString *)apiUser apiKey:(NSString *)apiKey
- (NSDictionary *)parametersDictionary:(nonnull NSString *)apiUser apiKey:(nonnull NSString *)apiKey
{
[self.smtpapi configureHeader];
self.xsmtpapi = [self.smtpapi encodedHeader];
NSLog(@"%@", self.xsmtpapi);

if (self.html != nil && self.text == nil)
self.text = self.html;

self.text = (self.html != nil && self.text == nil) ? self.html : @"";

//must set the "to" parameter even if X-SMTPAPI tos array is set
if ([self.smtpapi getTos] != nil && [[self.smtpapi getTos] count] > 0 && self.to == nil)
[self setTo:[[self.smtpapi getTos] objectAtIndex:0]];
Expand Down