PageRenderTime 43ms CodeModel.GetById 27ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/FSKit/Source/iPhone/Common/FSKIdentityService.m

http://fskit.googlecode.com/
Objective C | 142 lines | 93 code | 25 blank | 24 comment | 4 complexity | 1b758c16b0280f43f0042c4ffa068d5d MD5 | raw file
Possible License(s): BSD-3-Clause
  1//
  2//  FSKIdentityService.m
  3//  FSKit
  4//
  5//  Created by Logan Allred on 1/20/08.
  6//  Copyright 2008 Logan Allred. All rights reserved.
  7//
  8
  9#import "FSKIdentityService.h"
 10#import "FSKIdentityResponse.h"
 11
 12BOOL isReady = NO;
 13
 14@implementation FSKIdentityService
 15
 16+ (FSKIdentityService *)identityServiceWithConnection:(FSKConnection *)familySearchConnection delegate:theDelegate
 17{
 18	return [[[FSKIdentityService alloc] initWithConnection:familySearchConnection delegate:theDelegate] autorelease];
 19}
 20
 21- (id)initWithConnection:(FSKConnection *)familySearchConnection delegate:(id)theDelegate
 22{
 23    if ((self = [super initWithConnection:familySearchConnection delegate:theDelegate]) != nil) 
 24	{ 
 25		moduleName = @"identity";
 26		versionString = @"v2";
 27		identityProperties = [[FSKProperties alloc] initWithFamilySearchConnection:familySearchConnection 
 28																		  delegate:self 
 29																		  endpoint:[NSString stringWithFormat:@"%@/%@", moduleName, versionString]];
 30	}
 31	return self;
 32}
 33
 34- (void)dealloc
 35{
 36	[identityProperties release];
 37	[super dealloc];
 38}
 39
 40- (void)fetchProperties
 41{
 42	NSLog(@"%s", __PRETTY_FUNCTION__);
 43	NSLog(@"identityProperties hasProperties? %@", ([identityProperties hasProperties] ? @"YES" : @"NO"));
 44	[identityProperties refreshProperties];
 45//	FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handlePropertiesResponse:)] retain]; 
 46//	[request sendPropertiesRequest];
 47}	
 48
 49- (void)pingSession {
 50	NSLog(@"%s", __PRETTY_FUNCTION__);
 51	FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleSessionResponse:)] retain]; 
 52	[request sendSessionPingRequest];
 53}
 54
 55- (void)makeReady
 56{
 57	// ping session
 58	[self pingSession];
 59	// get properties
 60	[self fetchProperties];
 61}
 62
 63- (void)login {
 64	NSLog(@"%s", __PRETTY_FUNCTION__);
 65	FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleLoginResponse:)] retain]; 
 66	[request sendLoginRequest];
 67		}
 68
 69- (void)loginWithCredential:(NSURLCredential *)credential
 70{
 71//	NSXMLDocument* responseXML = [connection postFamilySearchData:myURL
 72//												  withData:[[NSString stringWithFormat:@"username=%@&password=%@&key=%@", 
 73//													  [credential user], [credential password], developerKey] dataUsingEncoding:NSUTF8StringEncoding] ofType:nil];
 74
 75}
 76
 77- (void)logout
 78{
 79	NSLog(@"%s", __PRETTY_FUNCTION__);
 80	FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleLoginResponse:)] retain]; 
 81	[request sendLogoutRequest];
 82}
 83
 84//-(void) requestFinished:(id <EnunciateXML>)response
 85//{
 86//	NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
 87//}
 88//
 89//-(void) requestFailed:(NSError *)error
 90//{
 91//	NSLog(@"%s %@", __PRETTY_FUNCTION__, error);
 92//}
 93
 94- (NSArray *)permissions
 95{
 96	return nil;
 97}
 98
 99- (FSKUserProfile *)profile
100{
101	return nil;
102}
103
104@end
105
106@implementation FSKIdentityService(PrivateMethods)
107- (void)handleLoginResponse:(FSKIdentityResponse *)response
108{
109	NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
110
111	[connection setSessionId:[response sessionId]]; 
112	[connection setNeedsAuthentication:NO];
113	
114	if ([_delegate respondsToSelector:@selector(request:didReturnResponse:)])
115	{
116		[_delegate request:nil didReturnResponse:response];
117	}
118	
119}
120
121- (void)handlePropertiesResponse:(FSKIdentityResponse *)response
122{
123	NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
124	
125	NSMutableDictionary *propertyDict = [NSMutableDictionary dictionary];
126	NSArray *propertiesList = [response valueForKeyPath:@"xmlDocument.properties"];
127	NSEnumerator *enumerator = [propertiesList objectEnumerator];
128	FSIDENTITYV2AIdentityProperty *property;
129	while ((property = [enumerator nextObject])) {
130		[propertyDict setObject:[property value] forKey:[property name]];
131	}
132	properties = propertyDict;
133}
134
135-(void)fetchIdentityData:(NSString *)module path:(NSSet *)idList parameters:(NSDictionary *)parameterDict
136{
137	NSLog(@"%s, %@, %@, %@", __PRETTY_FUNCTION__, module, idList, parameterDict);
138	[self makeFamilySearchRequest:module idList:idList parameters:parameterDict];
139//	return nil;
140}
141
142@end