From 36db0d683e886f2b80b1e80ea5c29c1446dbfe76 Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Fri, 19 Oct 2018 12:15:52 +0200 Subject: [PATCH 1/3] add httpscallable --- FIRHTTPSCallable+Rx.swift | 74 +++++++++++++++++++++++++++++++++++++++ Podfile | 1 + Podfile.lock | 24 +++++++++---- RxFirebase.podspec | 4 +++ 4 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 FIRHTTPSCallable+Rx.swift diff --git a/FIRHTTPSCallable+Rx.swift b/FIRHTTPSCallable+Rx.swift new file mode 100644 index 0000000..303eeb1 --- /dev/null +++ b/FIRHTTPSCallable+Rx.swift @@ -0,0 +1,74 @@ +// +// FIRHTTPSCallable+Rx.swift +// RxFirebase +// +// Created by Arnaud Dorgans on 19/10/2018. +// + +import RxSwift +import FirebaseFunctions + +extension Reactive where Base: HTTPSCallable { + + /** + * Executes this Callable HTTPS trigger asynchronously without any parameters. + * + * The request to the Cloud Functions backend made by this method automatically includes a + * Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase + * Auth, an auth ID token for the user is also automatically included. + * + * Firebase Instance ID sends data to the Firebase backend periodically to collect information + * regarding the app instance. To stop this, see `[FIRInstanceID deleteIDWithHandler:]`. It + * resumes with a new Instance ID the next time you call this method. + * + * @param completion The block to call when the HTTPS request has completed. + */ + public func call() -> Observable { + return Observable.create { observer in + self.base.call { result, error in + if let result = result { + observer.onNext(result) + observer.onCompleted() + } else if let error = error { + observer.onError(error) + } + } + return Disposables.create() + } + } + + /** + * Executes this Callable HTTPS trigger asynchronously. + * + * The data passed into the trigger can be any of the following types: + * * NSNull + * * NSString + * * NSNumber + * * NSArray, where the contained objects are also one of these types. + * * NSDictionary, where the values are also one of these types. + * + * The request to the Cloud Functions backend made by this method automatically includes a + * Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase + * Auth, an auth ID token for the user is also automatically included. + * + * Firebase Instance ID sends data to the Firebase backend periodically to collect information + * regarding the app instance. To stop this, see `[FIRInstanceID deleteIDWithHandler:]`. It + * resumes with a new Instance ID the next time you call this method. + * + * @param data Parameters to pass to the trigger. + * @param completion The block to call when the HTTPS request has completed. + */ + public func call(_ data: Any?) -> Observable { + return Observable.create { observer in + self.base.call(data) { result, error in + if let result = result { + observer.onNext(result) + observer.onCompleted() + } else if let error = error { + observer.onError(error) + } + } + return Disposables.create() + } + } +} diff --git a/Podfile b/Podfile index 8b80dca..131eff2 100644 --- a/Podfile +++ b/Podfile @@ -7,6 +7,7 @@ target 'RxFirebase_Example' do pod 'RxFirebase/Database', :path => './' pod 'RxFirebase/Storage', :path => './' pod 'RxFirebase/Auth', :path => './' + pod 'RxFirebase/Functions', :path => './' target 'RxFirebase_Tests' do inherit! :search_paths diff --git a/Podfile.lock b/Podfile.lock index 9482dab..411d446 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -43,6 +43,9 @@ PODS: - leveldb-library (~> 1.18) - nanopb (~> 0.3.8) - Protobuf (~> 3.1) + - FirebaseFunctions (2.1.1): + - FirebaseCore (~> 5.0) + - GTMSessionFetcher/Core (~> 1.1) - FirebaseInstanceID (3.2.1): - FirebaseCore (~> 5.1) - GoogleUtilities/Environment (~> 5.2) @@ -110,24 +113,28 @@ PODS: - Protobuf (3.6.1) - RxCocoa (4.2.0): - RxSwift (~> 4.0) - - RxFirebase/Auth (0.2.2): + - RxFirebase/Auth (0.2.4): - FirebaseAuth (~> 5) - FirebaseCore (~> 5.1) - RxCocoa (~> 4) - RxSwift (~> 4) - - RxFirebase/Database (0.2.2): + - RxFirebase/Database (0.2.4): - FirebaseDatabase (~> 5) - RxCocoa (~> 4) - RxSwift (~> 4) - - RxFirebase/Firestore (0.2.2): + - RxFirebase/Firestore (0.2.4): - FirebaseFirestore (~> 0.12) - RxCocoa (~> 4) - RxSwift (~> 4) - - RxFirebase/RemoteConfig (0.2.2): + - RxFirebase/Functions (0.2.4): + - FirebaseFunctions (~> 2) + - RxCocoa (~> 4) + - RxSwift (~> 4) + - RxFirebase/RemoteConfig (0.2.4): - FirebaseRemoteConfig (~> 3) - RxCocoa (~> 4) - RxSwift (~> 4) - - RxFirebase/Storage (0.2.2): + - RxFirebase/Storage (0.2.4): - FirebaseStorage (~> 3) - RxCocoa (~> 4) - RxSwift (~> 4) @@ -137,6 +144,7 @@ DEPENDENCIES: - RxFirebase/Auth (from `./`) - RxFirebase/Database (from `./`) - RxFirebase/Firestore (from `./`) + - RxFirebase/Functions (from `./`) - RxFirebase/RemoteConfig (from `./`) - RxFirebase/Storage (from `./`) @@ -150,6 +158,7 @@ SPEC REPOS: - FirebaseCore - FirebaseDatabase - FirebaseFirestore + - FirebaseFunctions - FirebaseInstanceID - FirebaseRemoteConfig - FirebaseStorage @@ -179,6 +188,7 @@ SPEC CHECKSUMS: FirebaseCore: 3a97432acb324b439fbed338e642f9cbb516a63d FirebaseDatabase: 27be5ac5bc75e0b17537b2bbfada8258addcc8cd FirebaseFirestore: 7eec93809ad61e7ebe303089c5cc5efa63424b72 + FirebaseFunctions: 6c03d7c5d62520be4678dc3fb7957654aab82b4f FirebaseInstanceID: ea5af6920d0a4a29b40459d055bebe4a6c1333c4 FirebaseRemoteConfig: 7b6d675dfb11f0e0e638caee00908b06af150d56 FirebaseStorage: 43f823b96b72a08539eba21a7de043348a69d4c6 @@ -193,9 +203,9 @@ SPEC CHECKSUMS: nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5 RxCocoa: 0b54909c902e1e581212a03e690bbd94032d8baa - RxFirebase: 8fa5c30d4ad3645f3be7cc0e780a0dc6083430ad + RxFirebase: 223375f163b3e5ed7db665e3fc596851840131be RxSwift: 99e10317ddfcc7fbe01356aafd118fde4a0be104 -PODFILE CHECKSUM: 65fe2926d5235467f5da97e2c5e400ae4db298cf +PODFILE CHECKSUM: db4e0a593103ec732f32da4bf8e8163883660ceb COCOAPODS: 1.5.3 diff --git a/RxFirebase.podspec b/RxFirebase.podspec index b825a9b..6a1c71b 100644 --- a/RxFirebase.podspec +++ b/RxFirebase.podspec @@ -52,6 +52,10 @@ Pod::Spec.new do |s| storage.source_files = 'Sources/Storage/**/*' storage.dependency 'FirebaseStorage', '~> 3' end + s.subspec 'Functions' do |functions| + functions.source_files = 'Sources/Functions/**/*' + functions.dependency 'FirebaseFunctions', '~> 2' + end s.subspec 'Auth' do |auth| auth.source_files = 'Sources/Auth/**/*' auth.dependency 'FirebaseAuth', '~> 5' From 3ca9b591c5285c8c14625fd3bb26bde97c313cdc Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Fri, 19 Oct 2018 12:22:02 +0200 Subject: [PATCH 2/3] fix path --- .../Functions/FIRHTTPSCallable+Rx.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename FIRHTTPSCallable+Rx.swift => Sources/Functions/FIRHTTPSCallable+Rx.swift (100%) diff --git a/FIRHTTPSCallable+Rx.swift b/Sources/Functions/FIRHTTPSCallable+Rx.swift similarity index 100% rename from FIRHTTPSCallable+Rx.swift rename to Sources/Functions/FIRHTTPSCallable+Rx.swift From d6e6654a680afc629dfbbd5522661384b455c945 Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Tue, 23 Oct 2018 11:15:06 +0200 Subject: [PATCH 3/3] add functions documentation --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index e974213..8ba685c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ pod 'RxFirebase/RemoteConfig' pod 'RxFirebase/Database' pod 'RxFirebase/Storage' pod 'RxFirebase/Auth' +pod 'RxFirebase/Functions' ``` ## Usage @@ -35,6 +36,7 @@ import RxFirebase - [RemoteConfig](#remoteconfig) - [Storage](#storage) - [Auth](#auth) +- [Functions](#functions) ### Database @@ -438,6 +440,23 @@ reference.delete() ### Auth +### Functions + +```swift +let functions = Functions.functions() +let request = functions.httpsCallable("functionName").rx + +request + .call(["parameter": "value"]) + .subscribe(onNext: { result in + print("response:\(result)") + }, onError: { error in + print("error:\(error)") + }).disposed(by: disposeBag) + + // https://firebase.google.com/docs/functions/callable#call_the_function +``` + ## License This library belongs to _RxSwiftCommunity_.