PageRenderTime 33ms CodeModel.GetById 11ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

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