From e78e10f3591979f27f861febc090c5e3874c4843 Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Tue, 3 Apr 2018 12:01:35 +0200 Subject: [PATCH] 1.0.1 --- .gitignore | 3 +- Example/Podfile | 2 +- Example/Podfile.lock | 28 +++++++--- .../contents.xcworkspacedata | 10 ---- Example/RxFirebase/ViewController.swift | 9 +-- README.md | 29 ++++++++-- RxFirebase.podspec | 14 ++--- .../RemoteConfig/RemoteConfig+Rx.swift | 55 +++++++++++++++++++ 8 files changed, 113 insertions(+), 37 deletions(-) delete mode 100644 Example/RxFirebase.xcworkspace/contents.xcworkspacedata create mode 100644 RxFirebase/Classes/RemoteConfig/RemoteConfig+Rx.swift diff --git a/.gitignore b/.gitignore index 5df313e..e60889c 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ Carthage/Build # `pod install` in .travis.yml # # Pods/ -/Example/RxFirebase.xcworkspace/xcshareddata +/Example/RxFirebase.xcworkspace +/Example/Pods diff --git a/Example/Podfile b/Example/Podfile index 9834301..17af653 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -2,7 +2,7 @@ use_frameworks! target 'RxFirebase_Example' do pod 'RxFirebase/Firestore', :path => '../' - pod 'RxFirebase/Core', :path => '../' + pod 'RxFirebase/RemoteConfig', :path => '../' target 'RxFirebase_Tests' do inherit! :search_paths diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 9f4c16a..0b83433 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -5,6 +5,9 @@ PODS: - BoringSSL/Implementation (10.0): - BoringSSL/Interface (= 10.0) - BoringSSL/Interface (10.0) + - FirebaseABTesting (1.0.0): + - FirebaseCore (~> 4.0) + - Protobuf (~> 3.1) - FirebaseAnalytics (4.1.0): - FirebaseCore (~> 4.0) - FirebaseInstanceID (~> 2.0) @@ -20,6 +23,13 @@ PODS: - Protobuf (~> 3.5) - FirebaseInstanceID (2.0.10): - FirebaseCore (~> 4.0) + - FirebaseRemoteConfig (2.1.2): + - FirebaseABTesting (~> 1.0) + - FirebaseAnalytics (~> 4.0) + - FirebaseCore (~> 4.0) + - FirebaseInstanceID (~> 2.0) + - GoogleToolboxForMac/NSData+zlib (~> 2.1) + - Protobuf (~> 3.1) - GoogleToolboxForMac/Defines (2.1.3) - GoogleToolboxForMac/NSData+zlib (2.1.3): - GoogleToolboxForMac/Defines (= 2.1.3) @@ -51,19 +61,21 @@ PODS: - Protobuf (3.5.0) - RxCocoa (4.1.2): - RxSwift (~> 4.0) - - RxFirebase/Core (0.1.0): - - FirebaseCore + - RxFirebase/Firestore (0.1.0): + - FirebaseCore (~> 4) + - FirebaseFirestore (~> 0) - RxCocoa (~> 4) - RxSwift (~> 4) - - RxFirebase/Firestore (0.1.0): - - FirebaseFirestore + - RxFirebase/RemoteConfig (0.1.0): + - FirebaseCore (~> 4) + - FirebaseRemoteConfig (~> 2) - RxCocoa (~> 4) - RxSwift (~> 4) - RxSwift (4.1.2) DEPENDENCIES: - - RxFirebase/Core (from `../`) - RxFirebase/Firestore (from `../`) + - RxFirebase/RemoteConfig (from `../`) EXTERNAL SOURCES: RxFirebase: @@ -71,10 +83,12 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BoringSSL: 32764dbaf5f5888cf51fbaa172a010126b41bcd4 + FirebaseABTesting: d07d0ee833b842d5153549e4c7e2e2cb1c23a3f9 FirebaseAnalytics: 3dfae28d4a5e06f86c4fae830efc2ad3fadb19bc FirebaseCore: b981f47e5254cbcfdeb483355300d743f6fcab2c FirebaseFirestore: 796df79c29cf8ecf806564f4d347665bdafa6ef0 FirebaseInstanceID: 8d20d890d65c917f9f7d9950b6e10a760ad34321 + FirebaseRemoteConfig: df64ce784a45e9b9d4988030a59da6baede8bdb0 GoogleToolboxForMac: 2501e2ad72a52eb3dfe7bd9aee7dad11b858bd20 gRPC: f54f0e6d603052b4562447da442ce2ff30bcdacc gRPC-Core: a030b1678ded49c88ec5ba7c90ee8ee5f47ec6e1 @@ -84,9 +98,9 @@ SPEC CHECKSUMS: nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03 RxCocoa: d88ba0f1f6abf040011a9eb4b539324fc426843a - RxFirebase: 3bc3bbc1e7599c2f3aaedde9debde5537c1d9c1a + RxFirebase: fa49a55c75f8d501b69cb6bde368449c0b27ebf7 RxSwift: e49536837d9901277638493ea537394d4b55f570 -PODFILE CHECKSUM: bcea1d407c8677e9d6cda7c19588a1bc242c4f14 +PODFILE CHECKSUM: a5b068a211fcbb54a7281d0b2f5acde20991d4e1 COCOAPODS: 1.4.0 diff --git a/Example/RxFirebase.xcworkspace/contents.xcworkspacedata b/Example/RxFirebase.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 8899434..0000000 --- a/Example/RxFirebase.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/Example/RxFirebase/ViewController.swift b/Example/RxFirebase/ViewController.swift index c5d6a9f..76ce0ea 100644 --- a/Example/RxFirebase/ViewController.swift +++ b/Example/RxFirebase/ViewController.swift @@ -7,18 +7,15 @@ // import UIKit +import RxFirebase +import FirebaseRemoteConfig class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. + } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - } diff --git a/README.md b/README.md index d4e4de1..42509d2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ it, simply add the following line to your Podfile: ```ruby pod 'RxFirebase/Firestore' +pod 'RxFirebase/RemoteConfig' ``` ## Usage @@ -76,7 +77,7 @@ db.collection("cities") // https://firebase.google.com/docs/firestore/manage-data/add-data ``` -Get a document +Get a document: ```swift let db = Firestore.firestore() @@ -97,7 +98,7 @@ db.collection("cities") // https://firebase.google.com/docs/firestore/query-data/get-data ``` -Get Realtime Updates +Get Realtime Updates: ```swift let db = Firestore.firestore() @@ -135,7 +136,7 @@ db.collection("cities") // https://firebase.google.com/docs/firestore/query-data/listen ``` -Batched writes +Batched writes: ```swift let db = Firestore.firestore() @@ -158,7 +159,7 @@ batch.rx // https://firebase.google.com/docs/firestore/manage-data/transactions ``` -Transactions +Transactions: ```swift let db = Firestore.firestore() let sfReference = db.collection("cities").document("SF") @@ -195,6 +196,26 @@ db.rx.runTransaction { transaction, errorPointer in // https://firebase.google.com/docs/firestore/manage-data/transactions ``` +### RemoteConfig + +Fetch: +```swift +// TimeInterval is set to expirationDuration here, indicating the next fetch request will use +// data fetched from the Remote Config service, rather than cached parameter values, if cached +// parameter values are more than expirationDuration seconds old. See Best Practices in the +// README for more information. +RemoteConfig.remoteConfig() + .rx + .fetch(withExpirationDuration: TimeInterval(expirationDuration), activateFetched: true) + .subscribe(onNext: { status in + print("Config fetched! with success:\(status == .success)") + }, onError: { error in + print("Error: \(error)") + }).disposed(by: disposeBag) + + // https://firebase.google.com/docs/remote-config/ios +``` + ## Author Arnaud Dorgans, arnaud.dorgans@gmail.com diff --git a/RxFirebase.podspec b/RxFirebase.podspec index 928fb32..ad60365 100644 --- a/RxFirebase.podspec +++ b/RxFirebase.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'RxFirebase' - s.version = '0.1.0' + s.version = '0.1.1' s.summary = 'RxSwift extensions for Firebase.' # This description is used to generate tags and improve search results. @@ -36,16 +36,14 @@ s.swift_version = '4.1' s.dependency 'RxCocoa', '~> 4' s.dependency 'FirebaseCore', '~> 4' -#s.subspec 'Core' do |core| -#core.source_files = 'RxFirebase/Classes/Core/**/*' -#end -#s.subspec 'Database' do |database| -#database.source_files = 'RxFirebase/Classes/Database/**/*' -#database.dependency 'FirebaseDatabase', '~> 4' -#end s.subspec 'Firestore' do |firestore| firestore.source_files = 'RxFirebase/Classes/Firestore/**/*' firestore.dependency 'FirebaseFirestore', '~> 0' end + s.subspec 'RemoteConfig' do |remote| + remote.source_files = 'RxFirebase/Classes/RemoteConfig/**/*' + remote.dependency 'FirebaseRemoteConfig', '~> 2' + end + end diff --git a/RxFirebase/Classes/RemoteConfig/RemoteConfig+Rx.swift b/RxFirebase/Classes/RemoteConfig/RemoteConfig+Rx.swift new file mode 100644 index 0000000..93835a1 --- /dev/null +++ b/RxFirebase/Classes/RemoteConfig/RemoteConfig+Rx.swift @@ -0,0 +1,55 @@ +// +// RemoteConfig+Rx.swift +// RxFirebase +// +// Created by Arnaud Dorgans on 03/04/2018. +// + +import UIKit +import RxSwift +import FirebaseRemoteConfig + +extension Reactive where Base: RemoteConfig { + + /// Fetches Remote Config data with a callback. Call activateFetched to make fetched data available + /// to your app. + /// @param completionHandler Fetch operation callback. + public func fetch(activateFetched: Bool = false) -> Observable { + return Observable.create { observer in + self.base.fetch { status, error in + guard let error = error else { + if activateFetched, status == .success { + self.base.activateFetched() + } + observer.onNext(status) + observer.onCompleted() + return + } + observer.onError(error) + } + return Disposables.create() + } + } + + /// Fetches Remote Config data and sets a duration that specifies how long config data lasts. + /// Call activateFetched to make fetched data available to your app. + /// @param expirationDuration Duration that defines how long fetched config data is available, in + /// seconds. When the config data expires, a new fetch is required. + /// @param completionHandler Fetch operation callback. + public func fetch(withExpirationDuration duration: TimeInterval, activateFetched: Bool = false) -> Observable { + return Observable.create { observer in + self.base.fetch(withExpirationDuration: duration) { status, error in + guard let error = error else { + if activateFetched, status == .success { + self.base.activateFetched() + } + observer.onNext(status) + observer.onCompleted() + return + } + observer.onError(error) + } + return Disposables.create() + } + } +}