/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Contacts/GDataServiceGoogleContact.m

http://macfuse.googlecode.com/ · Objective C · 124 lines · 75 code · 31 blank · 18 comment · 1 complexity · 52d3081cde75102a461daf032f147f7c 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. // GDataServiceGoogleContact.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE
  19. #define GDATASERVICEGOOGLECONTACT_DEFINE_GLOBALS 1
  20. #import "GDataServiceGoogleContact.h"
  21. #import "GDataQueryContact.h"
  22. #import "GDataFeedContact.h"
  23. #import "GDataContactConstants.h"
  24. @implementation GDataServiceGoogleContact
  25. // feed is contacts or groups; projection is thin, default, or property-<key>
  26. + (NSURL *)contactURLForFeedName:(NSString *)feedName
  27. userID:(NSString *)userID
  28. projection:(NSString *)projection {
  29. NSString *baseURLString = [self serviceRootURLString];
  30. NSString *const templateStr = @"%@%@/%@/%@";
  31. NSString *feedURLString = [NSString stringWithFormat:templateStr,
  32. baseURLString,
  33. [GDataUtilities stringByURLEncodingForURI:feedName],
  34. [GDataUtilities stringByURLEncodingForURI:userID],
  35. [GDataUtilities stringByURLEncodingForURI:projection]];
  36. NSURL *url = [NSURL URLWithString:feedURLString];
  37. return url;
  38. }
  39. + (NSURL *)contactFeedURLForPropertyName:(NSString *)property {
  40. NSString *projection = [NSString stringWithFormat:@"property-%@", property];
  41. NSURL *url = [self contactURLForFeedName:kGDataGoogleContactAllContactsFeedName
  42. userID:kGDataServiceDefaultUser
  43. projection:projection];
  44. return url;
  45. }
  46. + (NSURL *)contactGroupFeedURLForPropertyName:(NSString *)property {
  47. NSString *projection = [NSString stringWithFormat:@"property-%@", property];
  48. NSURL *url = [self contactURLForFeedName:kGDataGoogleContactGroupsFeedName
  49. userID:kGDataServiceDefaultUser
  50. projection:projection];
  51. return url;
  52. }
  53. + (NSURL *)contactFeedURLForUserID:(NSString *)userID {
  54. NSURL *url = [self contactURLForFeedName:kGDataGoogleContactAllContactsFeedName
  55. userID:userID
  56. projection:kGDataGoogleContactFullProjection];
  57. return url;
  58. }
  59. + (NSURL *)groupFeedURLForUserID:(NSString *)userID {
  60. NSURL *url = [self contactURLForFeedName:kGDataGoogleContactGroupsFeedName
  61. userID:userID
  62. projection:kGDataGoogleContactFullProjection];
  63. return url;
  64. }
  65. + (NSURL *)contactFeedURLForUserID:(NSString *)userID
  66. projection:(NSString *)projection {
  67. NSURL *url = [self contactURLForFeedName:kGDataGoogleContactAllContactsFeedName
  68. userID:userID
  69. projection:projection];
  70. return url;
  71. }
  72. - (GDataServiceTicket *)fetchContactFeedForUsername:(NSString *)username
  73. delegate:(id)delegate
  74. didFinishSelector:(SEL)finishedSelector {
  75. NSURL *url = [[self class] contactFeedURLForUserID:username];
  76. return [self fetchFeedWithURL:url
  77. delegate:delegate
  78. didFinishSelector:finishedSelector];
  79. }
  80. + (NSString *)serviceID {
  81. return @"cp";
  82. }
  83. + (NSString *)serviceRootURLString {
  84. return @"https://www.google.com/m8/feeds/";
  85. }
  86. + (NSString *)defaultServiceVersion {
  87. return kGDataContactDefaultServiceVersion;
  88. }
  89. + (NSDictionary *)standardServiceNamespaces {
  90. return [GDataContactConstants contactNamespaces];
  91. }
  92. @end
  93. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE