FIRSignUpNewUserRequest.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRSignUpNewUserRequest.h"
  17. /** @var kSignupNewUserEndpoint
  18. @brief The "SingupNewUserEndpoint" endpoint.
  19. */
  20. static NSString *const kSignupNewUserEndpoint = @"signupNewUser";
  21. /** @var kEmailKey
  22. @brief The key for the "email" value in the request.
  23. */
  24. static NSString *const kEmailKey = @"email";
  25. /** @var kPasswordKey
  26. @brief The key for the "password" value in the request.
  27. */
  28. static NSString *const kPasswordKey = @"password";
  29. /** @var kDisplayNameKey
  30. @brief The key for the "kDisplayName" value in the request.
  31. */
  32. static NSString *const kDisplayNameKey = @"displayName";
  33. /** @var kReturnSecureTokenKey
  34. @brief The key for the "returnSecureToken" value in the request.
  35. */
  36. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  37. @implementation FIRSignUpNewUserRequest
  38. - (nullable instancetype)initWithAPIKey:(NSString *)APIKey
  39. email:(NSString *)email
  40. password:(NSString *)password
  41. displayName:(NSString *)displayName {
  42. self = [super initWithEndpoint:kSignupNewUserEndpoint APIKey:APIKey];
  43. if (self) {
  44. _email = [email copy];
  45. _password = [password copy];
  46. _displayName = [displayName copy];
  47. _returnSecureToken = YES;
  48. }
  49. return self;
  50. }
  51. - (nullable instancetype)initWithAPIKey:(NSString *)APIKey{
  52. self = [self initWithAPIKey:APIKey email:nil password:nil displayName:nil];
  53. return self;
  54. }
  55. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  56. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  57. if (_email) {
  58. postBody[kEmailKey] = _email;
  59. }
  60. if (_password) {
  61. postBody[kPasswordKey] = _password;
  62. }
  63. if (_displayName) {
  64. postBody[kDisplayNameKey] = _displayName;
  65. }
  66. if (_returnSecureToken) {
  67. postBody[kReturnSecureTokenKey] = @YES;
  68. }
  69. return postBody;
  70. }
  71. @end