/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Photos/GDataServiceGooglePhotos.m

http://macfuse.googlecode.com/ · Objective C · 124 lines · 75 code · 30 blank · 19 comment · 8 complexity · 226ec5c912aec54d497f07eb345ef710 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. // GDataServiceGooglePhotos.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_PHOTOS_SERVICE
  19. #define GDATASERVICEGOOGLEPHOTOS_DEFINE_GLOBALS 1
  20. #import "GDataServiceGooglePhotos.h"
  21. #import "GDataEntryPhotoBase.h"
  22. #import "GDataQueryGooglePhotos.h"
  23. #import "GDataPhotoConstants.h"
  24. @implementation GDataServiceGooglePhotos
  25. + (NSURL *)photoFeedURLForUserID:(NSString *)userID
  26. albumID:(NSString *)albumIDorNil
  27. albumName:(NSString *)albumNameOrNil
  28. photoID:(NSString *)photoIDorNil
  29. kind:(NSString *)feedKindOrNil
  30. access:(NSString *)accessOrNil {
  31. NSString *albumID = @"";
  32. if (albumIDorNil) {
  33. albumID = [NSString stringWithFormat:@"/albumid/%@",
  34. [GDataUtilities stringByURLEncodingForURI:albumIDorNil]];
  35. }
  36. NSString *albumName = @"";
  37. if (albumNameOrNil && !albumIDorNil) {
  38. albumName = [NSString stringWithFormat:@"/album/%@",
  39. [GDataUtilities stringByURLEncodingForURI:albumNameOrNil]];
  40. }
  41. NSString *photo = @"";
  42. if (photoIDorNil) {
  43. photo = [NSString stringWithFormat:@"/photoid/%@", photoIDorNil];
  44. }
  45. // make an array for the kind and access query params, and join the arra items
  46. // into a query string
  47. NSString *query = @"";
  48. NSMutableArray *queryItems = [NSMutableArray array];
  49. if (feedKindOrNil) {
  50. feedKindOrNil = [GDataUtilities stringByURLEncodingStringParameter:feedKindOrNil];
  51. NSString *kindStr = [NSString stringWithFormat:@"kind=%@", feedKindOrNil];
  52. [queryItems addObject:kindStr];
  53. }
  54. if (accessOrNil) {
  55. accessOrNil = [GDataUtilities stringByURLEncodingStringParameter:accessOrNil];
  56. NSString *accessStr = [NSString stringWithFormat:@"access=%@", accessOrNil];
  57. [queryItems addObject:accessStr];
  58. }
  59. if ([queryItems count]) {
  60. NSString *queryList = [queryItems componentsJoinedByString:@"&"];
  61. query = [NSString stringWithFormat:@"?%@", queryList];
  62. }
  63. NSString *root = [self serviceRootURLString];
  64. NSString *const templateStr = @"%@feed/api/user/%@%@%@%@%@";
  65. NSString *urlString = [NSString stringWithFormat:templateStr,
  66. root, [GDataUtilities stringByURLEncodingForURI:userID],
  67. albumID, albumName, photo, query];
  68. return [NSURL URLWithString:urlString];
  69. }
  70. + (NSURL *)photoContactsFeedURLForUserID:(NSString *)userID {
  71. NSString *root = [self serviceRootURLString];
  72. NSString *const templateStr = @"%@feed/api/user/%@/contacts?kind=user";
  73. NSString *urlString = [NSString stringWithFormat:templateStr,
  74. root, [GDataUtilities stringByURLEncodingForURI:userID]];
  75. return [NSURL URLWithString:urlString];
  76. }
  77. #pragma mark -
  78. + (NSString *)serviceID {
  79. return @"lh2";
  80. }
  81. + (NSString *)serviceRootURLString {
  82. return @"https://photos.googleapis.com/data/";
  83. }
  84. + (NSString *)defaultServiceVersion {
  85. return kGDataPhotosDefaultServiceVersion;
  86. }
  87. + (NSUInteger)defaultServiceUploadChunkSize {
  88. return kGDataStandardUploadChunkSize;
  89. }
  90. + (NSDictionary *)standardServiceNamespaces {
  91. return [GDataPhotoConstants photoNamespaces];
  92. }
  93. @end
  94. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_PHOTOS_SERVICE