GTMURLBuilder.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // GTMURLBuilder.h
  3. //
  4. // Copyright 2012 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. //
  19. // Class for creating URLs. It handles URL encoding of parameters.
  20. //
  21. // Usage example:
  22. //
  23. // GTMURLBuilder *URLBuilder =
  24. // [GTMURLBuilder builderWithString:@"http://www.google.com"];
  25. // [URLBuilder setValue:@"abc" forParameter:@"q"];
  26. // NSURL *URL = [URLBuilder URL];
  27. //
  28. // NOTE: Apps targeting iOS 8 or OS X 10.10 and later should use
  29. // NSURLComponents and NSURLQueryItem to create URLs with
  30. // query arguments instead of using this class.
  31. #import <Foundation/Foundation.h>
  32. #import "GTMDefines.h"
  33. #if (!TARGET_OS_IPHONE && defined(MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) \
  34. || (TARGET_OS_IPHONE && defined(__IPHONE_8_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
  35. __deprecated_msg("GTMURLBuilder is obsolete; update your app to use NSURLComponents queryItems property instead.")
  36. #endif
  37. @interface GTMURLBuilder : NSObject {
  38. @private
  39. NSMutableDictionary *params_;
  40. }
  41. @property(nonatomic, readonly) NSString *baseURLString;
  42. // |URLString| is expected to be a valid URL with already escaped parameter
  43. // values.
  44. + (GTMURLBuilder *)builderWithString:(NSString *)URLString;
  45. + (GTMURLBuilder *)builderWithURL:(NSURL *)URL;
  46. // |URLString| The base URL to which parameters will be appended.
  47. // If the URL already contains parameters, they should already be encoded.
  48. - (id)initWithString:(NSString *)URLString;
  49. - (void)setValue:(NSString *)value forParameter:(NSString *)parameter;
  50. - (void)setIntegerValue:(NSInteger)value forParameter:(NSString *)parameter;
  51. - (NSString *)valueForParameter:(NSString *)parameter;
  52. // Returns 0 if there is no value for |parameter| or if the value cannot
  53. // be parsed into an NSInteger. Use valueForParameter if you want to make
  54. // sure that the value is set before attempting the parsing.
  55. - (NSInteger)integerValueForParameter:(NSString *)parameter;
  56. - (void)removeParameter:(NSString *)parameter;
  57. - (void)setParameters:(NSDictionary *)parameters;
  58. - (NSDictionary *)parameters;
  59. - (NSURL *)URL;
  60. - (NSString *)URLString;
  61. // Case-sensitive comparison of the URL. Also protocol and host are compared
  62. // as case-sensitive strings. The order of URL parameters is ignored.
  63. - (BOOL)isEqual:(GTMURLBuilder *)URLBuilder;
  64. @end