FIRHTTPSCallable.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2017 Google
  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. #import "Functions/FirebaseFunctions/Public/FIRHTTPSCallable.h"
  15. #import "Functions/FirebaseFunctions/FIRHTTPSCallable+Internal.h"
  16. #import "Functions/FirebaseFunctions/FIRFunctions+Internal.h"
  17. #import "Functions/FirebaseFunctions/FUNUsageValidation.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @implementation FIRHTTPSCallableResult
  20. - (instancetype)initWithData:(id)data {
  21. self = [super init];
  22. if (self) {
  23. _data = data;
  24. }
  25. return self;
  26. }
  27. @end
  28. @interface FIRHTTPSCallable () {
  29. // The functions client to use for making calls.
  30. FIRFunctions *_functions;
  31. // The name of the http endpoint this reference refers to.
  32. NSString *_name;
  33. }
  34. @end
  35. @implementation FIRHTTPSCallable
  36. - (instancetype)initWithFunctions:(FIRFunctions *)functions name:(NSString *)name {
  37. self = [super init];
  38. if (self) {
  39. if (!name) {
  40. FUNThrowInvalidArgument(@"FIRHTTPSCallable name cannot be nil.");
  41. }
  42. _name = [name copy];
  43. _functions = functions;
  44. _timeoutInterval = 70.0;
  45. }
  46. return self;
  47. }
  48. - (void)callWithCompletion:(void (^)(FIRHTTPSCallableResult *_Nullable result,
  49. NSError *_Nullable error))completion {
  50. [self callWithObject:nil completion:completion];
  51. }
  52. - (void)callWithObject:(nullable id)data
  53. completion:(void (^)(FIRHTTPSCallableResult *_Nullable result,
  54. NSError *_Nullable error))completion {
  55. [_functions callFunction:_name
  56. withObject:data
  57. timeout:self.timeoutInterval
  58. completion:completion];
  59. }
  60. @end
  61. NS_ASSUME_NONNULL_END