FIRSendVerificationCodeRequest.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "FIRSendVerificationCodeRequest.h"
  17. #import "../Private/FIRAuthAppCredential.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @var kSendVerificationCodeEndPoint
  20. @brief The "sendVerificationCodeEnd" endpoint.
  21. */
  22. static NSString *const kSendVerificationCodeEndPoint = @"sendVerificationCode";
  23. /** @var kPhoneNumberKey
  24. @brief The key for the Phone Number parameter in the request.
  25. */
  26. static NSString *const kPhoneNumberKey = @"phoneNumber";
  27. /** @var kReceiptKey
  28. @brief The key for the receipt parameter in the request.
  29. */
  30. static NSString *const kReceiptKey = @"iosReceipt";
  31. /** @var kSecretKey
  32. @brief The key for the Secret parameter in the request.
  33. */
  34. static NSString *const kSecretKey = @"iosSecret";
  35. @implementation FIRSendVerificationCodeRequest {
  36. }
  37. - (nullable instancetype)initWithPhoneNumber:(NSString *)phoneNumber
  38. appCredential:(FIRAuthAppCredential *)appCredential
  39. APIKey:(NSString *)APIKey {
  40. self = [super initWithEndpoint:kSendVerificationCodeEndPoint APIKey:APIKey];
  41. if (self) {
  42. _phoneNumber = [phoneNumber copy];
  43. _appCredential = appCredential;
  44. }
  45. return self;
  46. }
  47. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  48. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  49. if (_phoneNumber) {
  50. postBody[kPhoneNumberKey] = _phoneNumber;
  51. }
  52. if (_appCredential.receipt) {
  53. postBody[kReceiptKey] = _appCredential.receipt;
  54. }
  55. if (_appCredential.secret) {
  56. postBody[kSecretKey] = _appCredential.secret;
  57. }
  58. return postBody;
  59. }
  60. @end
  61. NS_ASSUME_NONNULL_END