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

http://google-email-uploader-mac.googlecode.com/ · Objective C · 129 lines · 74 code · 31 blank · 24 comment · 4 complexity · 06b6e7eca4ad0af9441ab4b56b81816d MD5 · raw file

  1. /* Copyright (c) 2008 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. // GDataYouTubeStatistics.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
  19. #import "GDataYouTubeStatistics.h"
  20. #import "GDataYouTubeConstants.h"
  21. static NSString* const kViewCountAttr = @"viewCount";
  22. static NSString* const kVideoWatchCountAttr = @"videoWatchCount";
  23. static NSString* const kSubscriberCountAttr = @"subscriberCount";
  24. static NSString* const kFavoriteCountAttr = @"favoriteCount";
  25. static NSString* const kLastWebAccessAttr = @"lastWebAccess";
  26. static NSString* const kTotalUploadViewsAttr = @"totalUploadViews";
  27. @implementation GDataYouTubeStatistics
  28. // <yt:statistics viewCount="2"
  29. // videoWatchCount="77"
  30. // lastWebAccess="2008-01-26T10:32:41.000-08:00"/>
  31. + (NSString *)extensionElementURI { return kGDataNamespaceYouTube; }
  32. + (NSString *)extensionElementPrefix { return kGDataNamespaceYouTubePrefix; }
  33. + (NSString *)extensionElementLocalName { return @"statistics"; }
  34. + (GDataYouTubeStatistics *)youTubeStatistics {
  35. GDataYouTubeStatistics *obj = [self object];
  36. return obj;
  37. }
  38. - (void)addParseDeclarations {
  39. NSArray *attrs = [NSArray arrayWithObjects:
  40. kViewCountAttr, kVideoWatchCountAttr,
  41. kSubscriberCountAttr, kFavoriteCountAttr,
  42. kLastWebAccessAttr, kTotalUploadViewsAttr, nil];
  43. [self addLocalAttributeDeclarations:attrs];
  44. }
  45. - (void)addAttributesToElement:(NSXMLElement *)element {
  46. // this overrides the base class's method
  47. //
  48. // as in the java, skip adding attributes that are zero
  49. NSString *name;
  50. NSDictionary *attributes = [self attributes];
  51. NSEnumerator *enumerator = [attributes keyEnumerator];
  52. while ((name = [enumerator nextObject]) != nil) {
  53. NSString *value = [attributes valueForKey:name];
  54. // add it if it's not "0"
  55. if (![value isEqual:@"0"]) {
  56. [self addToElement:element attributeValueIfNonNil:value withName:name];
  57. }
  58. }
  59. }
  60. #pragma mark -
  61. - (NSNumber *)viewCount {
  62. return [self longLongNumberForAttribute:kViewCountAttr];
  63. }
  64. - (void)setViewCount:(NSNumber *)num {
  65. [self setStringValue:[num stringValue] forAttribute:kViewCountAttr];
  66. }
  67. - (NSNumber *)videoWatchCount {
  68. return [self longLongNumberForAttribute:kVideoWatchCountAttr];
  69. }
  70. - (void)setVideoWatchCount:(NSNumber *)num {
  71. [self setStringValue:[num stringValue] forAttribute:kVideoWatchCountAttr];
  72. }
  73. - (NSNumber *)subscriberCount {
  74. return [self longLongNumberForAttribute:kSubscriberCountAttr];
  75. }
  76. - (void)setSubscriberCount:(NSNumber *)num {
  77. [self setStringValue:[num stringValue] forAttribute:kSubscriberCountAttr];
  78. }
  79. - (NSNumber *)favoriteCount {
  80. return [self longLongNumberForAttribute:kFavoriteCountAttr];
  81. }
  82. - (void)setFavoriteCount:(NSNumber *)num {
  83. [self setStringValue:[num stringValue] forAttribute:kFavoriteCountAttr];
  84. }
  85. - (GDataDateTime *)lastWebAccess {
  86. return [self dateTimeForAttribute:kLastWebAccessAttr];
  87. }
  88. - (void)setLastWebAccess:(GDataDateTime *)dateTime {
  89. [self setDateTimeValue:dateTime forAttribute:kLastWebAccessAttr];
  90. }
  91. - (NSNumber *)totalUploadViews {
  92. return [self longLongNumberForAttribute:kTotalUploadViewsAttr];
  93. }
  94. - (void)setTotalUploadViews:(NSNumber *)num {
  95. [self setStringValue:[num stringValue] forAttribute:kTotalUploadViewsAttr];
  96. }
  97. @end
  98. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE