// // NYTUser.m // Notifications for YouTube // // Created by Kim Wittenburg on 18.06.13. // Copyright (c) 2013 Kim Wittenburg. All rights reserved. // #import "NYTUser.h" @implementation NYTUser - (id)initWithUserProfilePage:(NSXMLNode *)node { self = [super init]; if (self) { static NSString *const displayNamePath = @"./entry/author/name"; static NSString *const userIDPath = @"./entry/yt:username"; static NSString *const summaryPath = @"./entry/content"; NSXMLElement *displayNameElement = [node nodesForXPath:displayNamePath error:nil][0]; NSXMLElement *userIDElement = [node nodesForXPath:userIDPath error:nil][0]; NSXMLElement *summaryElement = [node nodesForXPath:summaryPath error:nil][0]; _displayName = displayNameElement.stringValue; _userID = userIDElement.stringValue; _channelID = [NSString stringWithFormat:@"UC%@", _userID]; _summary = summaryElement.stringValue; } return self; } - (id)initWithSubscriptionEntry:(NSXMLNode *)entry { self = [super init]; if (self) { static NSString *const displayNamePath = @"./yt:username/@display"; static NSString *const imagePath = @"./media:thumbnail/@url"; static NSString *const channelIDPath = @"./yt:channelId"; NSXMLElement *displayNameElement = [entry nodesForXPath:displayNamePath error:nil][0]; NSXMLElement *imageElement = [entry nodesForXPath:imagePath error:nil][0]; NSXMLElement *channelIDElement = [entry nodesForXPath:channelIDPath error:nil][0]; _displayName = displayNameElement.stringValue; _imageURL = [NSURL URLWithString:imageElement.stringValue]; _channelID = channelIDElement.stringValue; _userID = [_channelID substringFromIndex:2]; } return self; } - (BOOL)isEqual:(id)object { if (self == object) { return YES; } if (object == nil) { return NO; } if (![object isKindOfClass:[NYTUser class]]) { return NO; } return [self isEqualToUser:object]; } - (BOOL)isEqualToUser:(NYTUser *)user { if (self == user) { return YES; } if (self.userID) { if (user.userID) { return [self.userID isEqualToString:user.userID]; } else { NSString *otherUserID = [user.channelID substringFromIndex:2]; // Remove the UC from channel ID return [self.userID isEqualToString:otherUserID]; } } else if (self.channelID) { if (user.channelID) { return [self.channelID isEqualToString:user.channelID]; } else { NSString *userID = [self.channelID substringFromIndex:2]; // Remove the UC from channel ID return [userID isEqualToString:user.userID]; } } return NO; // Probably won't get here } @end