/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

  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. #import "FSKIdentityService.h"
  9. #import "FSKIdentityResponse.h"
  10. BOOL isReady = NO;
  11. @implementation FSKIdentityService
  12. + (FSKIdentityService *)identityServiceWithConnection:(FSKConnection *)familySearchConnection delegate:theDelegate
  13. {
  14. return [[[FSKIdentityService alloc] initWithConnection:familySearchConnection delegate:theDelegate] autorelease];
  15. }
  16. - (id)initWithConnection:(FSKConnection *)familySearchConnection delegate:(id)theDelegate
  17. {
  18. if ((self = [super initWithConnection:familySearchConnection delegate:theDelegate]) != nil)
  19. {
  20. moduleName = @"identity";
  21. versionString = @"v2";
  22. identityProperties = [[FSKProperties alloc] initWithFamilySearchConnection:familySearchConnection
  23. delegate:self
  24. endpoint:[NSString stringWithFormat:@"%@/%@", moduleName, versionString]];
  25. }
  26. return self;
  27. }
  28. - (void)dealloc
  29. {
  30. [identityProperties release];
  31. [super dealloc];
  32. }
  33. - (void)fetchProperties
  34. {
  35. NSLog(@"%s", __PRETTY_FUNCTION__);
  36. NSLog(@"identityProperties hasProperties? %@", ([identityProperties hasProperties] ? @"YES" : @"NO"));
  37. [identityProperties refreshProperties];
  38. // FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handlePropertiesResponse:)] retain];
  39. // [request sendPropertiesRequest];
  40. }
  41. - (void)pingSession {
  42. NSLog(@"%s", __PRETTY_FUNCTION__);
  43. FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleSessionResponse:)] retain];
  44. [request sendSessionPingRequest];
  45. }
  46. - (void)makeReady
  47. {
  48. // ping session
  49. [self pingSession];
  50. // get properties
  51. [self fetchProperties];
  52. }
  53. - (void)login {
  54. NSLog(@"%s", __PRETTY_FUNCTION__);
  55. FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleLoginResponse:)] retain];
  56. [request sendLoginRequest];
  57. }
  58. - (void)loginWithCredential:(NSURLCredential *)credential
  59. {
  60. // NSXMLDocument* responseXML = [connection postFamilySearchData:myURL
  61. // withData:[[NSString stringWithFormat:@"username=%@&password=%@&key=%@",
  62. // [credential user], [credential password], developerKey] dataUsingEncoding:NSUTF8StringEncoding] ofType:nil];
  63. }
  64. - (void)logout
  65. {
  66. NSLog(@"%s", __PRETTY_FUNCTION__);
  67. FSKIdentityRequest *request = [[[FSKIdentityRequest alloc] initWithFamilySearchConnection:connection delegate:self selector:@selector(handleLoginResponse:)] retain];
  68. [request sendLogoutRequest];
  69. }
  70. //-(void) requestFinished:(id <EnunciateXML>)response
  71. //{
  72. // NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
  73. //}
  74. //
  75. //-(void) requestFailed:(NSError *)error
  76. //{
  77. // NSLog(@"%s %@", __PRETTY_FUNCTION__, error);
  78. //}
  79. - (NSArray *)permissions
  80. {
  81. return nil;
  82. }
  83. - (FSKUserProfile *)profile
  84. {
  85. return nil;
  86. }
  87. @end
  88. @implementation FSKIdentityService(PrivateMethods)
  89. - (void)handleLoginResponse:(FSKIdentityResponse *)response
  90. {
  91. NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
  92. [connection setSessionId:[response sessionId]];
  93. [connection setNeedsAuthentication:NO];
  94. if ([_delegate respondsToSelector:@selector(request:didReturnResponse:)])
  95. {
  96. [_delegate request:nil didReturnResponse:response];
  97. }
  98. }
  99. - (void)handlePropertiesResponse:(FSKIdentityResponse *)response
  100. {
  101. NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
  102. NSMutableDictionary *propertyDict = [NSMutableDictionary dictionary];
  103. NSArray *propertiesList = [response valueForKeyPath:@"xmlDocument.properties"];
  104. NSEnumerator *enumerator = [propertiesList objectEnumerator];
  105. FSIDENTITYV2AIdentityProperty *property;
  106. while ((property = [enumerator nextObject])) {
  107. [propertyDict setObject:[property value] forKey:[property name]];
  108. }
  109. properties = propertyDict;
  110. }
  111. -(void)fetchIdentityData:(NSString *)module path:(NSSet *)idList parameters:(NSDictionary *)parameterDict
  112. {
  113. NSLog(@"%s, %@, %@, %@", __PRETTY_FUNCTION__, module, idList, parameterDict);
  114. [self makeFamilySearchRequest:module idList:idList parameters:parameterDict];
  115. // return nil;
  116. }
  117. @end