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
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *encodeForURL(NSString *s) {
|
|
|
|
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)s, NULL, NULL, kCFStringEncodingUTF8));
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)sendFeedbackThread:(id)sender {
|
|
|
|
@autoreleasepool {
|
|
|
|
NSString *f = encodeForURL(from);
|
|
|
|
NSString *s = encodeForURL(subject);
|
|
|
|
NSString *m = encodeForURL(message);
|
|
|
|
NSString *v = encodeForURL(version);
|
|
|
|
|
|
|
|
NSString *postString = [NSString stringWithFormat:@"from=%@&subject=%@&message=%@&version=%@", f, s, m, v];
|
|
|
|
|
|
|
|
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:@"https://kode54.net/cog/feedback.php"];
|
|
|
|
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];
|
|
|
|
// DLog(@"RESULT: %@", resultString);
|
|
|
|
if([resultString caseInsensitiveCompare:@"SUCCESS"] == NSOrderedSame) {
|
|
|
|
[self performSelectorOnMainThread:@selector(returnSuccess:) withObject:nil waitUntilDone:NO];
|
|
|
|
} else {
|
|
|
|
[self performSelectorOnMainThread:@selector(returnFailure:) withObject:nil waitUntilDone:NO];
|
|
|
|
}
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)sendFeedback:(NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v {
|
|
|
|
if([f isEqualToString:@""]) {
|
2005-06-02 18:16:43 +00:00
|
|
|
f = @"Anonymous";
|
|
|
|
}
|
|
|
|
[self setFrom:f];
|
|
|
|
[self setSubject:s];
|
|
|
|
[self setMessage:m];
|
2007-05-27 15:34:04 +00:00
|
|
|
[self setVersion:v];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[NSThread detachNewThreadSelector:@selector(sendFeedbackThread:) toTarget:self withObject:nil];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)returnSuccess:(id)userInfo {
|
|
|
|
if([delegate respondsToSelector:@selector(feedbackDidSend:)]) {
|
2009-03-07 23:08:43 +00:00
|
|
|
[delegate feedbackDidSend:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)returnFailure:(id)userInfo {
|
|
|
|
if([delegate respondsToSelector:@selector(feedbackDidNotSend:)]) {
|
2009-03-07 23:08:43 +00:00
|
|
|
[delegate feedbackDidNotSend:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setDelegate:(id<FeedbackSocketDelegate>)d {
|
|
|
|
delegate = d;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setFrom:(NSString *)f {
|
2005-06-02 18:16:43 +00:00
|
|
|
from = f;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setSubject:(NSString *)s {
|
2005-06-02 18:16:43 +00:00
|
|
|
subject = s;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setMessage:(NSString *)m {
|
2005-06-02 18:16:43 +00:00
|
|
|
message = m;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setVersion:(NSString *)v {
|
2007-05-27 15:34:04 +00:00
|
|
|
version = v;
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|