Skip to content

Commit

Permalink
- Started building an install dmg
Browse files Browse the repository at this point in the history
- Finished Amazon search authentication
- Made Info.plist's preprocessed
- Refactored out a base class for REST based searches
  • Loading branch information
griff committed Nov 18, 2009
1 parent 6fb98ab commit 518571b
Show file tree
Hide file tree
Showing 24 changed files with 650 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
build
junk
sparkle_private.pem
Plugins/Amazon/Access
26 changes: 14 additions & 12 deletions App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/KEXT.icns</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>mzplugin</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/KEXT.icns</string>
<key>CFBundleTypeName</key>
<string>MetaZ Plugin</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>org.maven-group.${PRODUCT_NAME:identifier}.plugin</string>
</array>
<key>LSTypeIsPackage</key>
<true/>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
Expand Down Expand Up @@ -138,11 +138,13 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.7a</string>
<string>RELEASE</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${DATEV}</string>
<string>BUILDDATE</string>
<key>BuildId</key>
<string>BUILDID</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2009, Brian Olsen</string>
<key>NSMainNibFile</key>
Expand All @@ -162,14 +164,14 @@
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIconFile</key>
<string>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/KEXT.icns</string>
<key>UTTypeDescription</key>
<string>MetaZ Plugin</string>
<key>UTTypeConformsTo</key>
<array>
<string>com.apple.plugin</string>
</array>
<key>UTTypeDescription</key>
<string>MetaZ Plugin</string>
<key>UTTypeIconFile</key>
<string>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/KEXT.icns</string>
<key>UTTypeIdentifier</key>
<string>org.maven-group.${PRODUCT_NAME:identifier}.plugin</string>
<key>UTTypeTagSpecification</key>
Expand All @@ -184,12 +186,12 @@
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>protected MPEG-4 movie</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.movie</string>
</array>
<key>UTTypeDescription</key>
<string>protected MPEG-4 movie</string>
<key>UTTypeIdentifier</key>
<string>com.apple.protected-mpeg-4-video</string>
<key>UTTypeTagSpecification</key>
Expand Down
16 changes: 9 additions & 7 deletions Framework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>Copyright 2009 Brian Olsen</string>
<key>CFBundleIdentifier</key>
<string>org.maven-group.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>RELEASE</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>0.7a</string>
<key>CFBundleVersion</key>
<string>${DATEV}</string>
<key>CFBundleGetInfoString</key>
<string>Copyright 2009 Brian Olsen</string>
<string>BUILDDATE</string>
<key>BuildId</key>
<string>BUILDID</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2009, Brian Olsen</string>
</dict>
Expand Down
34 changes: 34 additions & 0 deletions Framework/src/MZRESTSearch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// MZRESTSearch.h
// MetaZ
//
// Created by Brian Olsen on 18/11/09.
// Copyright 2009 Maven-Group. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <MetaZKit/MZRESTWrapper.h>
#import <MetaZKit/MZSearchProvider.h>

@interface MZRESTSearch : NSOperation <MZRESTWrapperDelegate>
{
id provider;
MZRESTWrapper* wrapper;
id<MZSearchProviderDelegate> delegate;
NSURL* searchURL;
NSString* verb;
NSDictionary* parameters;
BOOL isFinished;
BOOL isExecuting;
}
@property(assign) BOOL isFinished;
@property(assign) BOOL isExecuting;

- (id)initWithProvider:(id)provider delegate:(id<MZSearchProviderDelegate>)delegate url:(NSURL *)url usingVerb:(NSString *)verb parameters:(NSDictionary *)params;
- (void)start;
- (BOOL)isConcurrent;
- (BOOL)isExecuting;
- (BOOL)isFinished;
- (void)cancel;

@end
119 changes: 119 additions & 0 deletions Framework/src/MZRESTSearch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// MZRESTSearch.m
// MetaZ
//
// Created by Brian Olsen on 18/11/09.
// Copyright 2009 Maven-Group. All rights reserved.
//

#import "MZRESTSearch.h"
#import "MZSearchProvider.h"

@implementation MZRESTSearch
@synthesize isFinished;
@synthesize isExecuting;

- (id)initWithProvider:(id)theProvider delegate:(id<MZSearchProviderDelegate>)theDelegate url:(NSURL *)url usingVerb:(NSString *)theVerb parameters:(NSDictionary *)params;
{
self = [super init];
if(self)
{
searchURL = [url retain];
verb = [theVerb retain];
parameters = [params retain];
provider = [theProvider retain];
delegate = [theDelegate retain];
wrapper = [[MZRESTWrapper alloc] init];
wrapper.delegate = self;
}
return self;
}

- (void)dealloc
{
self.isExecuting = NO;
self.isFinished = YES;
[parameters release];
[searchURL release];
[verb release];
[wrapper cancelConnection];
[wrapper release];
[delegate release];
[super dealloc];
}

- (void)start
{
self.isExecuting = YES;
if([self isCancelled])
{
id del = delegate;
[del performSelectorOnMainThread:@selector(searchFinished) withObject:nil waitUntilDone:NO];
//[delegate searchFinished];
self.isExecuting = NO;
self.isFinished = YES;
}
else
[wrapper sendRequestTo:searchURL usingVerb:verb withParameters:parameters];
}

- (BOOL)isConcurrent
{
return YES;
}

/*
- (BOOL)isExecuting
{
return wrapper.connection != nil;
}
- (BOOL)isFinished
{
return self.finished;
}
*/

- (void)cancel
{
[super cancel];
if(self.isExecuting)
[wrapper cancelConnection];
}

#pragma mark - MZRESTWrapperDelegate

- (void)wrapper:(MZRESTWrapper *)theWrapper didRetrieveData:(NSData *)data
{
//NSLog(@"Got response:\n%@", [theWrapper responseAsText]);
[delegate searchProvider:provider result:[NSArray array]];
[delegate searchFinished];
self.isExecuting = NO;
self.isFinished = YES;
}

- (void)wrapper:(MZRESTWrapper *)theWrapper didFailWithError:(NSError *)error
{
NSLog(@"%@ search failed: %@", [self class], [error localizedDescription]);
[delegate searchFinished];
self.isExecuting = NO;
self.isFinished = YES;
}

- (void)wrapper:(MZRESTWrapper *)theWrapper didReceiveStatusCode:(int)statusCode
{
NSLog(@"%@ got status code: %d", [self class], statusCode);
[delegate searchFinished];
self.isExecuting = NO;
self.isFinished = YES;
}

- (void)wrapperWasCanceled:(MZRESTWrapper *)theWrapper
{
if(self.isExecuting)
[delegate searchFinished];
self.isExecuting = NO;
self.isFinished = YES;
}

@end
3 changes: 3 additions & 0 deletions Framework/src/MZRESTWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@
- (NSDictionary *)responseAsPropertyList;
- (NSString *)responseAsText;
- (NSXMLDocument *)responseAsXml;

- (NSDictionary *)preparedParameterDictionaryForInput:(NSDictionary *)inParams;
- (NSString *)queryStringForParameterDictionary:(NSDictionary *)parameters withUrl:(NSURL *)url;

@end
59 changes: 55 additions & 4 deletions Framework/src/MZRESTWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ - (void)dealloc
- (void)sendRequestTo:(NSURL *)url usingVerb:(NSString *)verb withParameters:(NSDictionary *)parameters
{
NSData *body = nil;
NSMutableString *params = nil;
NSString *params = nil;
NSString *contentType = @"text/html; charset=utf-8";
NSURL *finalURL = url;
if (parameters != nil)
{
parameters = [self preparedParameterDictionaryForInput:parameters];
params = [[self queryStringForParameterDictionary:parameters withUrl:url] retain];
/*
NSArray* paramNames = [[parameters allKeys] sortedArrayUsingSelector:@selector(compare:)];
params = [[NSMutableString alloc] init];
for (id key in paramNames)
Expand All @@ -83,6 +86,7 @@ - (void)sendRequestTo:(NSURL *)url usingVerb:(NSString *)verb withParameters:(NS
CFRelease(encodedValue);
}
[params deleteCharactersInRange:NSMakeRange([params length] - 1, 1)];
*/
}

if ([verb isEqualToString:@"POST"] || [verb isEqualToString:@"PUT"])
Expand Down Expand Up @@ -185,6 +189,47 @@ - (NSXMLDocument *)responseAsXml
return [[[NSXMLDocument alloc] initWithData:receivedData options:0 error:NULL] autorelease];
}

#pragma mark Protected methods
- (NSDictionary *)preparedParameterDictionaryForInput:(NSDictionary *)inParams
{
return inParams;
}

- (NSString *)queryStringForParameterDictionary:(NSDictionary *)parameters withUrl:(NSURL *)url
{
NSMutableDictionary* temp = [NSMutableDictionary dictionary];
for(NSString* key in parameters)
{
//CFStringRef keyStr = (CFStringRef)[key copy];
CFStringRef encodedKey = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)key,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
CFStringRef value = (CFStringRef)[[parameters objectForKey:key] copy];
// Escape even the "reserved" characters for URLs
// as defined in http://www.ietf.org/rfc/rfc2396.txt
CFStringRef encodedValue = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
value,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
[temp setObject:(NSString*)encodedValue forKey:(NSString*)encodedKey];
CFRelease(value);
CFRelease(encodedValue);
CFRelease(encodedKey);
}
NSArray* paramNames = [[temp allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSMutableString *queryString = [NSMutableString string];
int i, n = [paramNames count];
for (i = 0; i < n; i++) {
NSString *paramName = [paramNames objectAtIndex:i];
[queryString appendFormat:@"%@=%@", paramName, [temp objectForKey:paramName]];
if (i < n - 1) [queryString appendString:@"&"];
}
return queryString;
}

#pragma mark -
#pragma mark Private methods

Expand All @@ -194,8 +239,7 @@ - (void)startConnection:(NSURLRequest *)request
{
[self terminateConnection];
NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
delegate:self];

if (!conn)
{
Expand All @@ -207,7 +251,14 @@ - (void)startConnection:(NSURLRequest *)request
[delegate wrapper:self didFailWithError:error];
}
}
else {
else
{
if([NSRunLoop currentRunLoop] != [NSRunLoop mainRunLoop])
{
[conn unscheduleFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[conn scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
[conn start];
self.connection = conn;
}

Expand Down
1 change: 1 addition & 0 deletions Framework/src/MetaZKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import <MetaZKit/MZTimeCode.h>
#import <MetaZKit/MZTimedTextItem.h>
#import <MetaZKit/MZRESTWrapper.h>
#import <MetaZKit/MZRESTSearch.h>
#import <MetaZKit/MZRemoteData.h>
#import <MetaZKit/MZPriorObserverFix.h>
#import <MetaZKit/MZMethodData.h>
Expand Down

0 comments on commit 518571b

Please sign in to comment.