/Source/externals/GData/Source/Clients/YouTube/GDataEntryYouTubeUserEvent.m

http://google-email-uploader-mac.googlecode.com/ · Objective C · 165 lines · 104 code · 41 blank · 20 comment · 6 complexity · 0a583a64fb9881c4f3ac5317d76ecbb7 MD5 · raw file

  1. /* Copyright (c) 2009 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GDataEntryYouTubeUserEvent.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
  19. #import "GDataEntryYouTubeUserEvent.h"
  20. #import "GDataYouTubeConstants.h"
  21. #import "GDataYouTubeElements.h"
  22. @implementation GDataEntryYouTubeUserEvent
  23. + (GDataEntryYouTubeUserEvent *)userEventEntry {
  24. GDataEntryYouTubeUserEvent *entry = [self object];
  25. [entry setNamespaces:[GDataYouTubeConstants youTubeNamespaces]];
  26. return entry;
  27. }
  28. #pragma mark -
  29. + (NSString *)standardEntryKind {
  30. return kGDataCategoryYouTubeUserEvent;
  31. }
  32. + (void)load {
  33. [self registerEntryClass];
  34. }
  35. - (void)addExtensionDeclarations {
  36. [super addExtensionDeclarations];
  37. [self addExtensionDeclarationForParentClass:[self class]
  38. childClasses:
  39. // YouTube element extensions
  40. [GDataYouTubeVideoID class],
  41. [GDataYouTubeUsername class],
  42. [GDataYouTubeRating class],
  43. nil];
  44. }
  45. #if !GDATA_SIMPLE_DESCRIPTIONS
  46. - (NSMutableArray *)itemsForDescription {
  47. GDataYouTubeRating *rating = [self rating];
  48. NSString *ratingStr = nil;
  49. if (rating) {
  50. ratingStr = [NSString stringWithFormat:@"+%@/-%@",
  51. [rating numberOfLikes], [rating numberOfDislikes]];
  52. }
  53. struct GDataDescriptionRecord descRecs[] = {
  54. { @"eventType", @"userEventType", kGDataDescValueLabeled }, // report the category's term
  55. { @"videoID", @"videoID", kGDataDescValueLabeled },
  56. { @"username", @"username", kGDataDescValueLabeled },
  57. { @"rating", ratingStr, kGDataDescValueIsKeyPath },
  58. { nil, nil, (GDataDescRecTypes)0 }
  59. };
  60. NSMutableArray *items = [super itemsForDescription];
  61. [self addDescriptionRecords:descRecs toItems:items];
  62. return items;
  63. }
  64. #endif
  65. + (NSString *)defaultServiceVersion {
  66. return kGDataYouTubeDefaultServiceVersion;
  67. }
  68. #pragma mark -
  69. - (NSString *)videoID {
  70. GDataYouTubeVideoID *obj;
  71. obj = [self objectForExtensionClass:[GDataYouTubeVideoID class]];
  72. return [obj stringValue];
  73. }
  74. - (void)setVideoID:(NSString *)str {
  75. GDataYouTubeVideoID *obj = [GDataYouTubeVideoID valueWithString:str];
  76. [self setObject:obj forExtensionClass:[GDataYouTubeVideoID class]];
  77. }
  78. - (NSString *)username {
  79. GDataYouTubeUsername *obj = [self objectForExtensionClass:[GDataYouTubeUsername class]];
  80. return [obj stringValue];
  81. }
  82. - (void)setUsername:(NSString *)str {
  83. GDataYouTubeUsername *obj = [GDataYouTubeUsername valueWithString:str];
  84. [self setObject:obj forExtensionClass:[GDataYouTubeUsername class]];
  85. }
  86. - (GDataYouTubeRating *)rating {
  87. return [self objectForExtensionClass:[GDataYouTubeRating class]];
  88. }
  89. - (void)setRating:(GDataYouTubeRating *)obj {
  90. [self setObject:obj forExtensionClass:[GDataYouTubeRating class]];
  91. }
  92. #pragma mark -
  93. - (NSString *)userEventType {
  94. NSArray *eventCats = [self categoriesWithScheme:kGDataSchemeYouTubeUserEvents];
  95. if ([eventCats count] > 0) {
  96. GDataCategory *category = [eventCats objectAtIndex:0];
  97. NSString *typeStr = [category term];
  98. return typeStr;
  99. }
  100. return nil;
  101. }
  102. - (void)setUserEventType:(NSString *)typeStr {
  103. // replace any existing event categories (though there should be only one)
  104. // as in the Java interfaces
  105. NSArray *eventCats = [self categoriesWithScheme:kGDataSchemeYouTubeUserEvents];
  106. for (GDataCategory *cat in eventCats) {
  107. [self removeCategory:cat];
  108. }
  109. if (typeStr != nil) {
  110. GDataCategory *newCat;
  111. newCat = [GDataCategory categoryWithScheme:kGDataSchemeYouTubeUserEvents
  112. term:typeStr];
  113. [self addCategory:newCat];
  114. }
  115. }
  116. #pragma mark -
  117. - (GDataLink *)videoLink {
  118. return [self linkWithRelAttributeValue:kGDataLinkYouTubeVideo];
  119. }
  120. - (GDataLink *)commentLink {
  121. return [self linkWithRelAttributeValue:kGDataLinkYouTubeComments];
  122. }
  123. @end
  124. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE