FIRHTTPSCallable.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "FIRHTTPSCallable.h"
  15. #import "FIRHTTPSCallable+Internal.h"
  16. #import "FIRFunctions+Internal.h"
  17. #import "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. }
  45. return self;
  46. }
  47. - (void)callWithCompletion:(void (^)(FIRHTTPSCallableResult *_Nullable result,
  48. NSError *_Nullable error))completion {
  49. [self callWithObject:nil completion:completion];
  50. }
  51. - (void)callWithObject:(nullable id)data
  52. completion:(void (^)(FIRHTTPSCallableResult *_Nullable result,
  53. NSError *_Nullable error))completion {
  54. [_functions callFunction:_name withObject:data completion:completion];
  55. }
  56. @end
  57. NS_ASSUME_NONNULL_END