RxFacebook 0.4.0

RxFacebook 0.4.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2018
SPMSupports SPM

Maintained by Sourav Chandra.



 
Depends on:
RxSwift>= 3.0
FacebookLogin>= 0.2.0
FacebookCore>= 0.2.0
 

  • By
  • sauravexodus

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

import FacebookLogin
import FacebookCore

class Example {
	let loginManager = LoginManager()

	func signIn() {
			loginManager.rx.logIn(with: [.publicProfile]).flatMap { [weak self] (loginResult) -> Observable<EmailResult> in
							guard let strongSelf = self else { return .just((nil, "Something went wrong")) }
							switch loginResult {
							case .cancelled: return .just((nil, "User cancelled the result"))
							case let .failed(error): return .just((nil, error.localizedDescription))
							// Extract the facebook login result here and chain it with your graph request
							case let .success(acceptedPermissions, declinedPermissions, accessToken): return strongSelf.fetchEmail()
							}
					}
					.subscribe(onNext: { email, error in
							if let `email` = email {
									print(email)
							} else if let `error` = error {
									print(error)
							}
					})
					.disposed(by: disposeBag)
	}

	func fetchEmail() -> Observable<EmailResult> {
			let graphRequest  = GraphRequest(graphPath: "/me")
			return graphRequest.rx.getResponse().map { result in
					switch result {
					case let .success(response):
							guard let objectMap = response.dictionaryValue, let email = objectMap["email"] as? String else { return (nil, "Couldn't find email") }
							return (email, nil)
					case let .failed(error):
							return (nil, error.localizedDescription)
					}
			}
	}
}

Requirements

pod 'RxSwift'
pod 'FacebookCore'
pod 'FacebookLogin'

Installation

RxFacebook is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxFacebook'

Author

Sourav Chandra RxSwift Enthusiast [email protected]

License

RxFacebook is available under the MIT license. See the LICENSE file for more info.