mirror of
https://github.com/caoer/RxFirebase.git
synced 2026-04-30 13:42:44 +08:00
Merge branch 'feature/functions' into develop
# Conflicts: # README.md
This commit is contained in:
1
Podfile
1
Podfile
@@ -7,6 +7,7 @@ target 'RxFirebase_Example' do
|
|||||||
pod 'RxFirebase/Database', :path => './'
|
pod 'RxFirebase/Database', :path => './'
|
||||||
pod 'RxFirebase/Storage', :path => './'
|
pod 'RxFirebase/Storage', :path => './'
|
||||||
pod 'RxFirebase/Auth', :path => './'
|
pod 'RxFirebase/Auth', :path => './'
|
||||||
|
pod 'RxFirebase/Functions', :path => './'
|
||||||
|
|
||||||
target 'RxFirebase_Tests' do
|
target 'RxFirebase_Tests' do
|
||||||
inherit! :search_paths
|
inherit! :search_paths
|
||||||
|
|||||||
24
Podfile.lock
24
Podfile.lock
@@ -43,6 +43,9 @@ PODS:
|
|||||||
- leveldb-library (~> 1.18)
|
- leveldb-library (~> 1.18)
|
||||||
- nanopb (~> 0.3.8)
|
- nanopb (~> 0.3.8)
|
||||||
- Protobuf (~> 3.1)
|
- Protobuf (~> 3.1)
|
||||||
|
- FirebaseFunctions (2.1.1):
|
||||||
|
- FirebaseCore (~> 5.0)
|
||||||
|
- GTMSessionFetcher/Core (~> 1.1)
|
||||||
- FirebaseInstanceID (3.2.1):
|
- FirebaseInstanceID (3.2.1):
|
||||||
- FirebaseCore (~> 5.1)
|
- FirebaseCore (~> 5.1)
|
||||||
- GoogleUtilities/Environment (~> 5.2)
|
- GoogleUtilities/Environment (~> 5.2)
|
||||||
@@ -110,24 +113,28 @@ PODS:
|
|||||||
- Protobuf (3.6.1)
|
- Protobuf (3.6.1)
|
||||||
- RxCocoa (4.2.0):
|
- RxCocoa (4.2.0):
|
||||||
- RxSwift (~> 4.0)
|
- RxSwift (~> 4.0)
|
||||||
- RxFirebase/Auth (0.2.2):
|
- RxFirebase/Auth (0.2.4):
|
||||||
- FirebaseAuth (~> 5)
|
- FirebaseAuth (~> 5)
|
||||||
- FirebaseCore (~> 5.1)
|
- FirebaseCore (~> 5.1)
|
||||||
- RxCocoa (~> 4)
|
- RxCocoa (~> 4)
|
||||||
- RxSwift (~> 4)
|
- RxSwift (~> 4)
|
||||||
- RxFirebase/Database (0.2.2):
|
- RxFirebase/Database (0.2.4):
|
||||||
- FirebaseDatabase (~> 5)
|
- FirebaseDatabase (~> 5)
|
||||||
- RxCocoa (~> 4)
|
- RxCocoa (~> 4)
|
||||||
- RxSwift (~> 4)
|
- RxSwift (~> 4)
|
||||||
- RxFirebase/Firestore (0.2.2):
|
- RxFirebase/Firestore (0.2.4):
|
||||||
- FirebaseFirestore (~> 0.12)
|
- FirebaseFirestore (~> 0.12)
|
||||||
- RxCocoa (~> 4)
|
- RxCocoa (~> 4)
|
||||||
- RxSwift (~> 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)
|
- FirebaseRemoteConfig (~> 3)
|
||||||
- RxCocoa (~> 4)
|
- RxCocoa (~> 4)
|
||||||
- RxSwift (~> 4)
|
- RxSwift (~> 4)
|
||||||
- RxFirebase/Storage (0.2.2):
|
- RxFirebase/Storage (0.2.4):
|
||||||
- FirebaseStorage (~> 3)
|
- FirebaseStorage (~> 3)
|
||||||
- RxCocoa (~> 4)
|
- RxCocoa (~> 4)
|
||||||
- RxSwift (~> 4)
|
- RxSwift (~> 4)
|
||||||
@@ -137,6 +144,7 @@ DEPENDENCIES:
|
|||||||
- RxFirebase/Auth (from `./`)
|
- RxFirebase/Auth (from `./`)
|
||||||
- RxFirebase/Database (from `./`)
|
- RxFirebase/Database (from `./`)
|
||||||
- RxFirebase/Firestore (from `./`)
|
- RxFirebase/Firestore (from `./`)
|
||||||
|
- RxFirebase/Functions (from `./`)
|
||||||
- RxFirebase/RemoteConfig (from `./`)
|
- RxFirebase/RemoteConfig (from `./`)
|
||||||
- RxFirebase/Storage (from `./`)
|
- RxFirebase/Storage (from `./`)
|
||||||
|
|
||||||
@@ -150,6 +158,7 @@ SPEC REPOS:
|
|||||||
- FirebaseCore
|
- FirebaseCore
|
||||||
- FirebaseDatabase
|
- FirebaseDatabase
|
||||||
- FirebaseFirestore
|
- FirebaseFirestore
|
||||||
|
- FirebaseFunctions
|
||||||
- FirebaseInstanceID
|
- FirebaseInstanceID
|
||||||
- FirebaseRemoteConfig
|
- FirebaseRemoteConfig
|
||||||
- FirebaseStorage
|
- FirebaseStorage
|
||||||
@@ -179,6 +188,7 @@ SPEC CHECKSUMS:
|
|||||||
FirebaseCore: 3a97432acb324b439fbed338e642f9cbb516a63d
|
FirebaseCore: 3a97432acb324b439fbed338e642f9cbb516a63d
|
||||||
FirebaseDatabase: 27be5ac5bc75e0b17537b2bbfada8258addcc8cd
|
FirebaseDatabase: 27be5ac5bc75e0b17537b2bbfada8258addcc8cd
|
||||||
FirebaseFirestore: 7eec93809ad61e7ebe303089c5cc5efa63424b72
|
FirebaseFirestore: 7eec93809ad61e7ebe303089c5cc5efa63424b72
|
||||||
|
FirebaseFunctions: 6c03d7c5d62520be4678dc3fb7957654aab82b4f
|
||||||
FirebaseInstanceID: ea5af6920d0a4a29b40459d055bebe4a6c1333c4
|
FirebaseInstanceID: ea5af6920d0a4a29b40459d055bebe4a6c1333c4
|
||||||
FirebaseRemoteConfig: 7b6d675dfb11f0e0e638caee00908b06af150d56
|
FirebaseRemoteConfig: 7b6d675dfb11f0e0e638caee00908b06af150d56
|
||||||
FirebaseStorage: 43f823b96b72a08539eba21a7de043348a69d4c6
|
FirebaseStorage: 43f823b96b72a08539eba21a7de043348a69d4c6
|
||||||
@@ -193,9 +203,9 @@ SPEC CHECKSUMS:
|
|||||||
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
|
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
|
||||||
Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5
|
Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5
|
||||||
RxCocoa: 0b54909c902e1e581212a03e690bbd94032d8baa
|
RxCocoa: 0b54909c902e1e581212a03e690bbd94032d8baa
|
||||||
RxFirebase: 8fa5c30d4ad3645f3be7cc0e780a0dc6083430ad
|
RxFirebase: 223375f163b3e5ed7db665e3fc596851840131be
|
||||||
RxSwift: 99e10317ddfcc7fbe01356aafd118fde4a0be104
|
RxSwift: 99e10317ddfcc7fbe01356aafd118fde4a0be104
|
||||||
|
|
||||||
PODFILE CHECKSUM: 65fe2926d5235467f5da97e2c5e400ae4db298cf
|
PODFILE CHECKSUM: db4e0a593103ec732f32da4bf8e8163883660ceb
|
||||||
|
|
||||||
COCOAPODS: 1.5.3
|
COCOAPODS: 1.5.3
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -22,6 +22,7 @@ pod 'RxFirebase/RemoteConfig'
|
|||||||
pod 'RxFirebase/Database'
|
pod 'RxFirebase/Database'
|
||||||
pod 'RxFirebase/Storage'
|
pod 'RxFirebase/Storage'
|
||||||
pod 'RxFirebase/Auth'
|
pod 'RxFirebase/Auth'
|
||||||
|
pod 'RxFirebase/Functions'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -35,6 +36,7 @@ import RxFirebase
|
|||||||
- [RemoteConfig](#remoteconfig)
|
- [RemoteConfig](#remoteconfig)
|
||||||
- [Storage](#storage)
|
- [Storage](#storage)
|
||||||
- [Auth](#auth)
|
- [Auth](#auth)
|
||||||
|
- [Functions](#functions)
|
||||||
|
|
||||||
### Database
|
### Database
|
||||||
|
|
||||||
@@ -341,7 +343,7 @@ let fileURL: URL // Upload file
|
|||||||
let uploadTask = reference.putFile(from: fileURL)
|
let uploadTask = reference.putFile(from: fileURL)
|
||||||
|
|
||||||
// Listen for state changes
|
// Listen for state changes
|
||||||
task.rx.observe(.progress)
|
uploadTask.rx.observe(.progress)
|
||||||
.subscribe(onNext: { snapshot in
|
.subscribe(onNext: { snapshot in
|
||||||
// Upload reported progress
|
// Upload reported progress
|
||||||
let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
|
let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
|
||||||
@@ -504,7 +506,22 @@ let user = Auth.auth().currentUser?
|
|||||||
// https://firebase.google.com/docs/auth/ios/manage-users
|
// https://firebase.google.com/docs/auth/ios/manage-users
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 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
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ Pod::Spec.new do |s|
|
|||||||
storage.source_files = 'Sources/Storage/**/*'
|
storage.source_files = 'Sources/Storage/**/*'
|
||||||
storage.dependency 'FirebaseStorage', '~> 3'
|
storage.dependency 'FirebaseStorage', '~> 3'
|
||||||
end
|
end
|
||||||
|
s.subspec 'Functions' do |functions|
|
||||||
|
functions.source_files = 'Sources/Functions/**/*'
|
||||||
|
functions.dependency 'FirebaseFunctions', '~> 2'
|
||||||
|
end
|
||||||
s.subspec 'Auth' do |auth|
|
s.subspec 'Auth' do |auth|
|
||||||
auth.source_files = 'Sources/Auth/**/*'
|
auth.source_files = 'Sources/Auth/**/*'
|
||||||
auth.dependency 'FirebaseAuth', '~> 5'
|
auth.dependency 'FirebaseAuth', '~> 5'
|
||||||
|
|||||||
74
Sources/Functions/FIRHTTPSCallable+Rx.swift
Normal file
74
Sources/Functions/FIRHTTPSCallable+Rx.swift
Normal file
@@ -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<HTTPSCallableResult> {
|
||||||
|
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<id>, where the contained objects are also one of these types.
|
||||||
|
* * NSDictionary<NSString, id>, 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<HTTPSCallableResult> {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user