Permalink
Browse files

Adds a sample app.

  • Loading branch information...
1 parent ed75246 commit ad7715d02d9ca68b50674f111c00d50a8a670ca9 @zonble committed Dec 9, 2009
View
@@ -6,4 +6,5 @@ build
.DS_Store
CommitVersion.xcconfig
dsa_priv.pem
-*PlurkAPI.h*
+*PlurkAPI.h*
+*PlurkAPIKey.h*
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
Oops, something went wrong.
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
Oops, something went wrong.
@@ -0,0 +1,37 @@
+//
+// SimplePlurkClientAppDelegate.h
+// SimplePlurkClient
+//
+// Created by zonble on 12/10/09.
+// Copyright 2009 Lithoglyph Inc.. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "ObjectivePlurk.h"
+#import "PlurkAPIKey.h"
+
+@interface SimplePlurkClientAppDelegate : NSObject <NSApplicationDelegate>
+{
+ NSWindow *window;
+ IBOutlet NSWindow *loginWindow;
+ IBOutlet NSButton *loginButton;
+ IBOutlet NSButton *cancelLoginButton;
+ IBOutlet NSTextField *loginNameField;
+ IBOutlet NSTextField *passwordField;
+ IBOutlet NSProgressIndicator *loginProgressIndicator;
+
+ IBOutlet NSArrayController *plurkArrayController;
+
+ NSMutableString *loginName;
+ NSMutableString *password;
+}
+
+- (void)setLoginUIEnabled:(BOOL)flag;
+
+- (IBAction)showLoginSheet:(id)sender;
+- (IBAction)loginAction:(id)sender;
+- (IBAction)cancelLoginAction:(id)sender;
+
+@property (assign) IBOutlet NSWindow *window;
+
+@end
@@ -0,0 +1,113 @@
+//
+// SimplePlurkClientAppDelegate.m
+// SimplePlurkClient
+//
+// Created by zonble on 12/10/09.
+// Copyright 2009 Lithoglyph Inc.. All rights reserved.
+//
+
+#import "SimplePlurkClientAppDelegate.h"
+
+@implementation SimplePlurkClientAppDelegate
+
+- (void) dealloc
+{
+ [loginName release];
+ [password release];
+ [super dealloc];
+}
+
+
+- (id)init
+{
+ self = [super init];
+ if (self != nil) {
+ loginName = [[NSMutableString alloc] init];
+ password = [[NSMutableString alloc] init];
+ }
+ return self;
+}
+
+- (void)awakeFromNib
+{
+ [loginWindow setDefaultButtonCell:[loginButton cell]];
+ [loginProgressIndicator setHidden:YES];
+}
+
+- (void)setLoginUIEnabled:(BOOL)flag
+{
+ [loginButton setEnabled:flag];
+ [passwordField setEnabled:flag];
+ [loginNameField setEditable:flag];
+ [passwordField setEditable:flag];
+}
+
+- (IBAction)showLoginSheet:(id)sender
+{
+ if ([self.window attachedSheet]) {
+ return;
+ }
+ [NSApp beginSheet:loginWindow modalForWindow:self.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
+}
+
+- (IBAction)loginAction:(id)sender
+{
+ [self setLoginUIEnabled:NO];
+ [[ObjectivePlurk sharedInstance] loginWithUsername:loginName password:password delegate:self];
+ [loginProgressIndicator setHidden:NO];
+ [loginProgressIndicator startAnimation:self];
+}
+
+- (IBAction)cancelLoginAction:(id)sender
+{
+ [NSApp endSheet:loginWindow];
+ [loginWindow orderOut:self];
+}
+
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ [ObjectivePlurk sharedInstance].APIKey = API_KEY;
+ [self showLoginSheet:self];
+ // Insert code here to initialize your application
+}
+
+- (void)plurk:(ObjectivePlurk *)plurk didLoggedIn:(NSDictionary *)result
+{
+ [loginProgressIndicator setHidden:YES];
+ [loginProgressIndicator stopAnimation:self];
+ [self cancelLoginAction:self];
+ [self setLoginUIEnabled:YES];
+// NSLog(@"result:%@", [result description]);
+
+ NSMutableArray *plurks = [NSMutableArray array];
+ NSArray *inPlurks = [result valueForKey:@"plurks"];
+ NSDictionary *inUsers = [result valueForKey:@"plurks_users"];
+ for (NSDictionary *d in inPlurks) {
+ NSString *ownerID = [d valueForKey:@"owner_id"];
+ if ([ownerID isKindOfClass:[NSNumber class]]) {
+ ownerID = [(NSNumber *)ownerID stringValue];
+ }
+ NSDictionary *userDictionary = [inUsers valueForKey:ownerID];
+ NSMutableDictionary *newDictionary = [NSMutableDictionary dictionaryWithDictionary:d];
+ [newDictionary setValue:[[userDictionary copy] autorelease] forKey:@"userDictionary"];
+ [plurks addObject:newDictionary];
+ }
+// NSLog(@"plurks:%@", [plurks description]);
+ [plurkArrayController setContent:plurks];
+
+}
+- (void)plurk:(ObjectivePlurk *)plurk didFailLoggingIn:(NSError *)error
+{
+ [self setLoginUIEnabled:YES];
+ [loginProgressIndicator setHidden:YES];
+ [loginProgressIndicator stopAnimation:self];
+ NSRunAlertPanelRelativeToWindow([error localizedDescription], @"", @"OK", nil, nil, loginWindow);
+}
+
+
+
+@synthesize window;
+
+
+@end
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'SimplePlurkClient' target in the 'SimplePlurkClient' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
@@ -0,0 +1,14 @@
+//
+// main.m
+// SimplePlurkClient
+//
+// Created by zonble on 12/10/09.
+// Copyright 2009 Lithoglyph Inc.. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, char *argv[])
+{
+ return NSApplicationMain(argc, (const char **) argv);
+}

0 comments on commit ad7715d

Please sign in to comment.