PageRenderTime 31ms CodeModel.GetById 10ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/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//
 17//  GDataEntryYouTubeUserEvent.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
 21
 22#import "GDataEntryYouTubeUserEvent.h"
 23#import "GDataYouTubeConstants.h"
 24#import "GDataYouTubeElements.h"
 25
 26@implementation GDataEntryYouTubeUserEvent
 27
 28+ (GDataEntryYouTubeUserEvent *)userEventEntry {
 29
 30  GDataEntryYouTubeUserEvent *entry = [self object];
 31
 32  [entry setNamespaces:[GDataYouTubeConstants youTubeNamespaces]];
 33
 34  return entry;
 35}
 36
 37#pragma mark -
 38
 39+ (NSString *)standardEntryKind {
 40  return kGDataCategoryYouTubeUserEvent;
 41}
 42
 43+ (void)load {
 44  [self registerEntryClass];
 45}
 46
 47- (void)addExtensionDeclarations {
 48
 49  [super addExtensionDeclarations];
 50
 51  [self addExtensionDeclarationForParentClass:[self class]
 52                                 childClasses:
 53   // YouTube element extensions
 54   [GDataYouTubeVideoID class],
 55   [GDataYouTubeUsername class],
 56   [GDataYouTubeRating class],
 57   nil];
 58}
 59
 60#if !GDATA_SIMPLE_DESCRIPTIONS
 61- (NSMutableArray *)itemsForDescription {
 62
 63  GDataYouTubeRating *rating = [self rating];
 64  NSString *ratingStr = nil;
 65  if (rating) {
 66    ratingStr = [NSString stringWithFormat:@"+%@/-%@",
 67                 [rating numberOfLikes], [rating numberOfDislikes]];
 68  }
 69
 70  struct GDataDescriptionRecord descRecs[] = {
 71    { @"eventType", @"userEventType", kGDataDescValueLabeled   }, // report the category's term
 72    { @"videoID",   @"videoID",       kGDataDescValueLabeled   },
 73    { @"username",  @"username",      kGDataDescValueLabeled   },
 74    { @"rating",    ratingStr,        kGDataDescValueIsKeyPath },
 75    { nil, nil, (GDataDescRecTypes)0 }
 76  };
 77
 78  NSMutableArray *items = [super itemsForDescription];
 79  [self addDescriptionRecords:descRecs toItems:items];
 80  return items;
 81}
 82#endif
 83
 84+ (NSString *)defaultServiceVersion {
 85  return kGDataYouTubeDefaultServiceVersion;
 86}
 87
 88#pragma mark -
 89
 90- (NSString *)videoID {
 91  GDataYouTubeVideoID *obj;
 92
 93  obj = [self objectForExtensionClass:[GDataYouTubeVideoID class]];
 94  return [obj stringValue];
 95}
 96
 97- (void)setVideoID:(NSString *)str {
 98  GDataYouTubeVideoID *obj = [GDataYouTubeVideoID valueWithString:str];
 99  [self setObject:obj forExtensionClass:[GDataYouTubeVideoID class]];
100}
101
102- (NSString *)username {
103  GDataYouTubeUsername *obj = [self objectForExtensionClass:[GDataYouTubeUsername class]];
104  return [obj stringValue];
105}
106
107- (void)setUsername:(NSString *)str {
108  GDataYouTubeUsername *obj = [GDataYouTubeUsername valueWithString:str];
109  [self setObject:obj forExtensionClass:[GDataYouTubeUsername class]];
110}
111
112- (GDataYouTubeRating *)rating {
113  return [self objectForExtensionClass:[GDataYouTubeRating class]];
114}
115
116- (void)setRating:(GDataYouTubeRating *)obj {
117  [self setObject:obj forExtensionClass:[GDataYouTubeRating class]];
118}
119
120#pragma mark -
121
122- (NSString *)userEventType {
123
124  NSArray *eventCats = [self categoriesWithScheme:kGDataSchemeYouTubeUserEvents];
125
126  if ([eventCats count] > 0) {
127    GDataCategory *category = [eventCats objectAtIndex:0];
128    NSString *typeStr = [category term];
129    return typeStr;
130  }
131  return nil;
132}
133
134- (void)setUserEventType:(NSString *)typeStr {
135
136  // replace any existing event categories (though there should be only one)
137  // as in the Java interfaces
138  NSArray *eventCats = [self categoriesWithScheme:kGDataSchemeYouTubeUserEvents];
139
140  for (GDataCategory *cat in eventCats) {
141    [self removeCategory:cat];
142  }
143
144  if (typeStr != nil) {
145    GDataCategory *newCat;
146    newCat = [GDataCategory categoryWithScheme:kGDataSchemeYouTubeUserEvents
147                                          term:typeStr];
148    [self addCategory:newCat];
149  }
150}
151
152
153#pragma mark -
154
155- (GDataLink *)videoLink {
156  return [self linkWithRelAttributeValue:kGDataLinkYouTubeVideo];
157}
158
159- (GDataLink *)commentLink {
160  return [self linkWithRelAttributeValue:kGDataLinkYouTubeComments];
161}
162
163@end
164
165#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE