Skip to content

Instantly share code, notes, and snippets.

@zmcartor
Created March 5, 2013 00:51
Show Gist options
  • Save zmcartor/5087111 to your computer and use it in GitHub Desktop.
Save zmcartor/5087111 to your computer and use it in GitHub Desktop.
#import "HKZFakeWebserver.h"
@implementation HKZFakeWebserver
// This function returns the correct JSON data, or whatever for the requested URL
// via the ILURLProtocol
- (NSData *)responseDataForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest*)request {
NSData *responseData = nil;
// Dog profile information
if ([request.URL.absoluteString isEqual:@"http://dogpark.net/api/profile?id=33"] &&
[request.HTTPMethod isEqualToString:@"GET"]) {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *resource = [bundle pathForResource:@"profile" ofType:@"json"];
responseData = [[NSData alloc] initWithContentsOfFile:resource];
}
// Error handling for DogPark signup
else if ([request.URL.absoluteString isEqual:@"http://dogpark.net/api/new"] &&
[request.HTTPMethod isEqualToString:@"POST"]) {
// Post data, if we need it is here
// NSString *postString = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *resource = [bundle pathForResource:@"signupError" ofType:@"json"];
responseData = [[NSData alloc] initWithContentsOfFile:resource];
}
return responseData;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment