2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
// FeedbackSocket.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/27/05.
|
2005-07-02 21:02:06 +00:00
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "FeedbackSocket.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@implementation FeedbackSocket
|
|
|
|
|
|
|
|
NSString *encodeForURL(NSString *s)
|
|
|
|
{
|
|
|
|
return [(NSString*) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)s, NULL, NULL, kCFStringEncodingUTF8) autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendFeedbackThread:(id)sender
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
NSString *f = encodeForURL(from);
|
|
|
|
NSString *s = encodeForURL(subject);
|
|
|
|
NSString *m = encodeForURL(message);
|
2007-05-27 15:34:04 +00:00
|
|
|
NSString *v = encodeForURL(version);
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2007-05-27 15:34:04 +00:00
|
|
|
NSString *postString = [NSString stringWithFormat:@"from=%@&subject=%@&message=%@&version=%@", f, s, m, v];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding];
|
|
|
|
|
2013-10-22 01:26:57 +00:00
|
|
|
NSURL *url = [NSURL URLWithString:@"http://cogx.org/feedback.php"];
|
2005-06-02 18:16:43 +00:00
|
|
|
NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[post addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
|
|
|
|
[post setHTTPMethod:@"POST"];
|
|
|
|
[post setHTTPBody:postData];
|
|
|
|
|
|
|
|
NSError* error;
|
|
|
|
NSURLResponse* response;
|
|
|
|
NSData* resultData = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
|
|
|
|
NSString *resultString = [[[NSString alloc] initWithData:resultData encoding:NSASCIIStringEncoding] autorelease];
|
2013-10-11 12:03:55 +00:00
|
|
|
//DLog(@"RESULT: %@", resultString);
|
2005-06-02 18:16:43 +00:00
|
|
|
if ([resultString caseInsensitiveCompare:@"SUCCESS"] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread:@selector(returnSuccess:) withObject:nil waitUntilDone:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread:@selector(returnFailure:) withObject:nil waitUntilDone:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:34:04 +00:00
|
|
|
- (void)sendFeedback: (NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
if ([f isEqualToString:@""])
|
|
|
|
{
|
|
|
|
f = @"Anonymous";
|
|
|
|
}
|
|
|
|
[self setFrom:f];
|
|
|
|
[self setSubject:s];
|
|
|
|
[self setMessage:m];
|
2007-05-27 15:34:04 +00:00
|
|
|
[self setVersion:v];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
[NSThread detachNewThreadSelector:@selector(sendFeedbackThread:) toTarget:self withObject:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)returnSuccess:(id)userInfo
|
|
|
|
{
|
2009-03-07 23:08:43 +00:00
|
|
|
if ([delegate respondsToSelector:@selector(feedbackDidSend:)]) {
|
|
|
|
[delegate feedbackDidSend:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)returnFailure:(id)userInfo
|
|
|
|
{
|
2009-03-07 23:08:43 +00:00
|
|
|
if ([delegate respondsToSelector:@selector(feedbackDidNotSend:)]) {
|
|
|
|
[delegate feedbackDidNotSend:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2009-03-07 23:08:43 +00:00
|
|
|
-(void)setDelegate:(id<FeedbackSocketDelegate>)d
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2009-03-07 23:08:43 +00:00
|
|
|
delegate = d;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setFrom:(NSString *)f
|
|
|
|
{
|
|
|
|
[f retain];
|
|
|
|
[from release];
|
|
|
|
|
|
|
|
from = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSubject:(NSString *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[subject release];
|
|
|
|
|
|
|
|
subject = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMessage:(NSString *)m
|
|
|
|
{
|
|
|
|
[m retain];
|
|
|
|
[message release];
|
|
|
|
|
|
|
|
message = m;
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:34:04 +00:00
|
|
|
- (void)setVersion:(NSString *)v
|
|
|
|
{
|
|
|
|
[v retain];
|
|
|
|
[version release];
|
|
|
|
|
|
|
|
version = v;
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|