PageRenderTime 111ms CodeModel.GetById 50ms app.highlight 57ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/YouTube/GDataEntryYouTubeVideo.m

http://macfuse.googlecode.com/
Objective C | 301 lines | 198 code | 72 blank | 31 comment | 13 complexity | 6f2156d6d44ea8e9f3c5241a09ba98f4 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//  GDataEntryYouTubeVideo.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
 21
 22#import "GDataEntryYouTubeVideo.h"
 23#import "GDataYouTubeConstants.h"
 24#import "GDataYouTubeElements.h"
 25
 26@implementation GDataEntryYouTubeVideo
 27
 28+ (GDataEntryYouTubeVideo *)videoEntry {
 29  
 30  GDataEntryYouTubeVideo *entry = [self object];
 31
 32  [entry setNamespaces:[GDataYouTubeConstants youTubeNamespaces]];
 33  
 34  return entry;
 35}
 36
 37#pragma mark -
 38
 39+ (NSString *)standardEntryKind {
 40  return kGDataCategoryYouTubeVideo;
 41}
 42
 43+ (void)load {
 44  [self registerEntryClass];
 45}
 46
 47- (void)addExtensionDeclarations {
 48  
 49  [super addExtensionDeclarations];
 50  
 51  Class entryClass = [self class];
 52
 53  [self addExtensionDeclarationForParentClass:entryClass
 54                                 childClasses:
 55   [GDataComment class],
 56   [GDataYouTubeRating class],
 57   
 58   // YouTube element extensions
 59   [GDataYouTubeStatistics class],
 60   [GDataYouTubeNonEmbeddable class],
 61   [GDataYouTubeLocation class],
 62   [GDataYouTubeRecordedDate class],
 63   [GDataYouTubeAccessControl class],
 64   
 65   // YouTubeMediaGroup encapsulates YouTubeMediaContent
 66   [GDataYouTubeMediaGroup class],
 67   nil];
 68  
 69  // Geo
 70  [GDataGeo addGeoExtensionDeclarationsToObject:self
 71                                 forParentClass:entryClass];  
 72  
 73  // the publication state element is an extension to the Atom publishing
 74  // control element
 75  Class atomPubControlClass = [GDataAtomPubControl class];
 76  [self addExtensionDeclarationForParentClass:atomPubControlClass
 77                                 childClasses:
 78   [GDataYouTubePublicationState class],
 79   [GDataYouTubeIncomplete class],
 80   nil];
 81
 82  // the token element is an extension to the edit-media GDataLink
 83  [self addExtensionDeclarationForParentClass:[GDataLink class]
 84                                   childClass:[GDataYouTubeToken class]];
 85}
 86
 87#if !GDATA_SIMPLE_DESCRIPTIONS
 88- (NSMutableArray *)itemsForDescription {
 89
 90  // report notEmbeddable since it's the unusual case
 91  NSString *nonEmbeddableValue = [self isEmbeddable] ? nil : @"YES";
 92
 93  GDataYouTubeRating *rating = [self rating];
 94  NSString *ratingStr = nil;
 95  if (rating) {
 96    ratingStr = [NSString stringWithFormat:@"+%@/-%@",
 97                 [rating numberOfLikes], [rating numberOfDislikes]];
 98  }
 99
100  struct GDataDescriptionRecord descRecs[] = {
101    { @"state",             @"publicationState",   kGDataDescValueLabeled   },
102    { @"rating",            ratingStr,             kGDataDescValueIsKeyPath },
103    { @"comment",           @"comment",            kGDataDescValueLabeled   },
104    { @"stats",             @"statistics",         kGDataDescValueLabeled   },
105    { @"mediaGroup",        @"mediaGroup",         kGDataDescValueLabeled   },
106    { @"geoLocation",       @"geoLocation",        kGDataDescValueLabeled   },
107    { @"notEmbeddable",     nonEmbeddableValue,    kGDataDescValueIsKeyPath },
108    { @"pubState",          @"publicationState",   kGDataDescValueLabeled   },
109    { @"recorded",          @"recordedDate",       kGDataDescValueLabeled   },
110    { @"incomplete",        @"isIncomplete",       kGDataDescBooleanPresent },
111    { @"accessControls",    @"accessControls",     kGDataDescArrayDescs     },
112    { nil, nil, (GDataDescRecTypes)0 }
113  };
114
115  NSMutableArray *items = [super itemsForDescription];
116  [self addDescriptionRecords:descRecs toItems:items];
117  return items;
118}
119#endif
120
121+ (NSString *)defaultServiceVersion {
122  return kGDataYouTubeDefaultServiceVersion;
123}
124
125#pragma mark -
126
127- (GDataYouTubeStatistics *)statistics {
128  return [self objectForExtensionClass:[GDataYouTubeStatistics class]];
129}
130
131- (void)setStatistics:(GDataYouTubeStatistics *)obj {
132  [self setObject:obj forExtensionClass:[GDataYouTubeStatistics class]];
133}
134
135- (GDataComment *)comment {
136  return [self objectForExtensionClass:[GDataComment class]];
137}
138
139- (void)setComment:(GDataComment *)obj {
140  [self setObject:obj forExtensionClass:[GDataComment class]];
141}
142
143- (NSString *)location {
144  GDataYouTubeLocation *obj;
145
146  obj = [self objectForExtensionClass:[GDataYouTubeLocation class]];
147  return [obj stringValue];
148}
149
150- (void)setLocation:(NSString *)str {
151  GDataYouTubeLocation *obj = [GDataYouTubeLocation valueWithString:str];
152  [self setObject:obj forExtensionClass:[GDataYouTubeLocation class]];
153}
154
155- (GDataDateTime *)recordedDate {
156  GDataYouTubeRecordedDate *obj;
157
158  obj = [self objectForExtensionClass:[GDataYouTubeRecordedDate class]];
159  return [obj dateTimeValue];
160}
161
162- (void)setRecordedDate:(GDataDateTime *)dateTime {
163  GDataYouTubeRecordedDate *obj;
164
165  // recordedDate is date only, no time
166  [dateTime setHasTime:NO];
167
168  obj = [GDataYouTubeRecordedDate valueWithDateTime:dateTime];
169  [self setObject:obj forExtensionClass:[GDataYouTubeRecordedDate class]];
170}
171
172- (NSArray *)accessControls {
173  return [self objectsForExtensionClass:[GDataYouTubeAccessControl class]];
174}
175
176- (void)setAccessControls:(NSArray *)array {
177  [self setObjects:array forExtensionClass:[GDataYouTubeAccessControl class]];
178}
179
180- (void)addAccessControl:(GDataYouTubeAccessControl *)obj {
181  [self addObject:obj forExtensionClass:[GDataYouTubeAccessControl class]];
182}
183
184- (BOOL)isEmbeddable {
185  // note that the element is actually "non-embeddable", so we reverse the
186  // sense
187  GDataYouTubeNonEmbeddable *obj = [self objectForExtensionClass:[GDataYouTubeNonEmbeddable class]];
188  return (obj == nil);
189}
190
191- (void)setIsEmbeddable:(BOOL)flag {
192  if (!flag) {
193    GDataYouTubeNonEmbeddable *nonEmbed = [GDataYouTubeNonEmbeddable implicitValue];
194    [self setObject:nonEmbed forExtensionClass:[GDataYouTubeNonEmbeddable class]];
195  } else {
196    [self setObject:nil forExtensionClass:[GDataYouTubeNonEmbeddable class]];
197  }
198}
199
200- (GDataYouTubeRating *)rating {
201  return [self objectForExtensionClass:[GDataYouTubeRating class]];
202}
203
204- (void)setRating:(GDataYouTubeRating *)obj {
205  [self setObject:obj forExtensionClass:[GDataYouTubeRating class]];
206}
207
208- (GDataYouTubeMediaGroup *)mediaGroup {
209  return [self objectForExtensionClass:[GDataYouTubeMediaGroup class]];
210}
211
212- (void)setMediaGroup:(GDataYouTubeMediaGroup *)obj {
213  [self setObject:obj forExtensionClass:[GDataYouTubeMediaGroup class]];
214}
215
216- (GDataYouTubePublicationState *)publicationState {
217  // publication state is an extension to the entry's atomPubControl
218  GDataAtomPubControl *atomPubControl = [self atomPubControl];
219  return [atomPubControl objectForExtensionClass:[GDataYouTubePublicationState class]];
220}
221
222- (void)setGDataYouTubePublicationState:(GDataYouTubePublicationState *)obj {
223  
224  GDataAtomPubControl *atomPubControl = [self atomPubControl];
225  
226  if (obj != nil && atomPubControl == nil) {
227    // to add the publication state, we need to make an atomPubControl element
228    atomPubControl = [GDataAtomPubControl atomPubControl]; 
229  }
230  
231  [atomPubControl setObject:obj forExtensionClass:[GDataYouTubePublicationState class]];
232}
233
234- (BOOL)isIncomplete {
235  // incomplete is an extension to the entry's atomPubControl
236  GDataAtomPubControl *atomPubControl = [self atomPubControl];
237
238  GDataYouTubeIncomplete *obj;
239  obj = [atomPubControl objectForExtensionClass:[GDataYouTubeIncomplete class]];
240  return (obj != nil);
241}
242
243- (void)setIsIncomplete:(BOOL)flag {
244
245  GDataAtomPubControl *atomPubControl = [self atomPubControl];
246  GDataYouTubeIncomplete *obj = nil;
247
248  if (flag) {
249    obj = [GDataYouTubeIncomplete implicitValue];
250
251    if (atomPubControl == nil) {
252      // to add the incomplete, we need to make an atomPubControl element
253      atomPubControl = [GDataAtomPubControl atomPubControl];
254    }
255  }
256
257  [atomPubControl setObject:obj
258          forExtensionClass:[GDataYouTubeIncomplete class]];
259}
260
261#pragma mark -
262
263- (GDataGeo *)geoLocation {
264  return [GDataGeo geoLocationForObject:self];
265}
266
267- (void)setGeoLocation:(GDataGeo *)geo {
268  [GDataGeo setGeoLocation:geo forObject:self];
269}
270
271#pragma mark -
272
273- (GDataLink *)videoResponsesLink {
274  return [self linkWithRelAttributeValue:kGDataLinkYouTubeResponses]; 
275}
276
277- (GDataLink *)ratingsLink {
278  return [self linkWithRelAttributeValue:kGDataLinkYouTubeRatings]; 
279}
280
281- (GDataLink *)complaintsLink {
282  return [self linkWithRelAttributeValue:kGDataLinkYouTubeComplaints]; 
283}
284
285- (GDataLink *)captionTracksLink {
286  return [self linkWithRelAttributeValue:kGDataLinkYouTubeCaptionTracks];
287}
288
289@end
290
291@implementation GDataLink (GDataYouTubeVideoEntryAdditions)
292- (GDataYouTubeToken *)youTubeToken {
293  return [self objectForExtensionClass:[GDataYouTubeToken class]];
294}
295
296- (void)setYouTubeToken:(GDataYouTubeToken *)obj {
297  [self setObject:obj forExtensionClass:[GDataYouTubeToken class]];
298}
299@end
300
301#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE