PageRenderTime 78ms CodeModel.GetById 14ms app.highlight 60ms RepoModel.GetById 2ms app.codeStats 0ms

/Source/externals/GData/Source/Clients/Docs/GDataServiceGoogleDocs.m

http://google-email-uploader-mac.googlecode.com/
Objective C | 174 lines | 112 code | 38 blank | 24 comment | 13 complexity | 4eaff0f5af73cb160ba87f1223b5ad94 MD5 | raw file
  1/* Copyright (c) 2007 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//  GDataServiceGoogleDocs.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_DOCS_SERVICE
 21
 22#define GDATASERVICEDOCS_DEFINE_GLOBALS 1
 23#import "GDataServiceGoogleDocs.h"
 24#import "GDataDocConstants.h"
 25#import "GDataEntryDocBase.h"
 26#import "GDataQueryDocs.h"
 27#import "GDataFeedDocList.h"
 28#import "GDataFeedDocRevision.h"
 29
 30
 31@implementation GDataServiceGoogleDocs
 32
 33+ (NSURL *)docsFeedURL {
 34  NSURL *url = [self docsURLForUserID:kGDataServiceDefaultUser
 35                           visibility:kGDataGoogleDocsVisibilityPrivate
 36                           projection:kGDataGoogleDocsProjectionFull
 37                           resourceID:nil
 38                             feedType:nil
 39                           revisionID:nil];
 40  return url;
 41}
 42
 43+ (NSURL *)folderContentsFeedURLForFolderID:(NSString *)resourceID {
 44  NSURL *url = [self docsURLForUserID:kGDataServiceDefaultUser
 45                           visibility:kGDataGoogleDocsVisibilityPrivate
 46                           projection:kGDataGoogleDocsProjectionFull
 47                           resourceID:resourceID
 48                             feedType:kGDataGoogleDocsFeedTypeFolderContents
 49                           revisionID:nil];
 50  return url;
 51}
 52
 53+ (NSURL *)docsURLForUserID:(NSString *)userID
 54                 visibility:(NSString *)visibility
 55                 projection:(NSString *)projection
 56                 resourceID:(NSString *)resourceID
 57                   feedType:(NSString *)feedType
 58                 revisionID:(NSString *)revisionID {
 59  NSString *rootURLStr = [self serviceRootURLString];
 60
 61  if (projection == nil) {
 62    projection = @"full";
 63  }
 64
 65  NSString *templateStr = @"%@%@/%@/%@";
 66  NSString *encodedUser = [GDataUtilities stringByURLEncodingForURI:userID];
 67  NSString *urlStr = [NSString stringWithFormat:templateStr,
 68                      rootURLStr, encodedUser, visibility, projection];
 69
 70  // now add the optional parts
 71  if (resourceID) {
 72    NSString *encodedResID = [GDataUtilities stringByURLEncodingForURI:resourceID];
 73    urlStr = [urlStr stringByAppendingFormat:@"/%@", encodedResID];
 74  }
 75
 76  if (feedType) {
 77    urlStr = [urlStr stringByAppendingFormat:@"/%@", feedType];
 78  }
 79
 80  if (revisionID) {
 81    urlStr = [urlStr stringByAppendingFormat:@"/%@", revisionID];
 82  }
 83
 84  return [NSURL URLWithString:urlStr];
 85}
 86
 87+ (NSURL *)docsUploadURL {
 88  NSString *const kPath = @"upload/create-session/default/private/full";
 89  NSString *root = [self serviceRootURLString];
 90  NSString *urlString = [root stringByAppendingString:kPath];
 91
 92  return [NSURL URLWithString:urlString];
 93}
 94
 95+ (NSURL *)metadataEntryURLForUserID:(NSString *)userID {
 96  NSString *encodedUser = [GDataUtilities stringByURLEncodingForURI:userID];
 97  NSString *const kTemplate = @"%@metadata/%@";
 98
 99  NSString *root = [self serviceRootURLString];
100  NSString *urlString = [NSString stringWithFormat:kTemplate,
101                         root, encodedUser];
102
103  return [NSURL URLWithString:urlString];
104}
105
106+ (NSURL *)changesFeedURLForUserID:(NSString *)userID {
107  NSString *encodedUser = [GDataUtilities stringByURLEncodingForURI:userID];
108  NSString *const kTemplate = @"%@%@/private/changes";
109
110  NSString *root = [self serviceRootURLString];
111  NSString *urlString = [NSString stringWithFormat:kTemplate,
112                         root, encodedUser];
113
114  return [NSURL URLWithString:urlString];
115}
116
117
118#pragma mark -
119
120// updating a document entry with data requires the editMediaLink rather than
121// the editLink, per
122//
123// http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UpdatingContent
124
125- (GDataServiceTicket *)fetchEntryByUpdatingEntry:(GDataEntryBase *)entryToUpdate
126                                         delegate:(id)delegate
127                                didFinishSelector:(SEL)finishedSelector {
128  GDataLink *updateLink;
129
130  if (([entryToUpdate uploadData] == nil
131         && [entryToUpdate uploadFileHandle] == nil)
132      || [self serviceUploadChunkSize] == 0) {
133    // not uploading document data, or else doing a multipart MIME upload
134    updateLink = [entryToUpdate editLink];
135  } else {
136    // doing a chunked upload
137    updateLink = [entryToUpdate uploadEditLink];
138  }
139
140  NSURL *editURL = [updateLink URL];
141
142  GDataServiceTicket *ticket = [self fetchEntryByUpdatingEntry:entryToUpdate
143                                                   forEntryURL:editURL
144                                                      delegate:delegate
145                                             didFinishSelector:finishedSelector];
146
147  return ticket;
148}
149
150#pragma mark -
151
152+ (NSString *)serviceRootURLString {
153  return @"https://docs.google.com/feeds/";
154}
155
156+ (NSString *)serviceID {
157  return @"writely";
158}
159
160+ (NSString *)defaultServiceVersion {
161  return kGDataDocsDefaultServiceVersion;
162}
163
164+ (NSUInteger)defaultServiceUploadChunkSize {
165  return kGDataStandardUploadChunkSize;
166}
167
168+ (NSDictionary *)standardServiceNamespaces {
169  return [GDataDocConstants baseDocumentNamespaces];
170}
171
172@end
173
174#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_DOCS_SERVICE