/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Docs/GDataServiceGoogleDocs.m

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