RxFacebook


Source link: https://github.com/saantiaguilera/android-api-RxFacebook

RxFacebook

A reactive extension over the facebook SDK.

Requirements

RxFacebook can be included in any Android application.

RxFacebook supports Android ApiLevel 14 and later.

RxJava and RxAndroid arent added as dependencies, but expects you to have them. It supports both 1.X and 2.X

Description

This library simply wraps the GraphRequest and LoginManager facebook provides in its SDK and moves them to a stream based logic

Relevant notes

  • Instead of using [4,5) for the facebook dependency version. We are statically adding 4.5.0 since its the last one to give support to api 14. If you plan on using a newer one, please bear in mind that your minimum api level wont be this one
  • RxJava and RxAndroid are used as provided dependencies, so you should add them to your project. This project supports both Rx 1.X and 2.X, use whichever you prefer :)

Usage

Adding it to your project

Add in your build.gradle:

dependencies {

// If you have Rx1
compile "com.saantiaguilera.rx:rxfacebook:<latest_version>"
// If you have Rx2
compile "com.saantiaguilera.rx:rx2facebook:<latest_version>" 
}

Getting started

Create a RxFacebook instance and configure it as you like. There are built-in methods provided out of the box (the same that GraphRequest provides)

RxFacebook.create()
.accessToken(token)
.params(bundle)
.graphPath(path)
.httpMethod(HttpMethod.GET)
.request() // From this point onwards, we are using a Observable<GraphResponse>
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.immediate())
.map(new Func1() {

  @Override
  public SomeDto call(final GraphResponse response) {

 // This library is agnostic to your parsing method, use whichever you want to.

 // Here im using gson as example

 return gson.parse(response.getJSONObject(), SomeDto.class);

  
}

}
)
.subscribe(...);

You can configure the following properties of a facebook request:

RxFacebook.create()

 // Create a instance
.accessToken(token)
  // Set an access token if the request is authenticated
.params(bundle)

// Set a bundle with field params for the request
.tag(object)

// Set a tag as id of the request (in the response you

// can get it with response.getRequest().getTag())
.version(string)

  // Version of the graph api to use
.httpMethod(method)
  // Method of HTTP to use, if request doesnt include it
.skipClientToken(bool)  // If it should skip the auth
.graphPath(string)

// Path of the endpoint to hit (eg /users/me)
.graphObject(JSONObj)
// Body of a post 

And you can call the following methods to build a request:

RxFacebook.create()

 // Create a instance
.request()

// Perform a request with the HttpMethod/GraphPath/etc setted
.requestMe()

 // Perform a request to fetch the authorized user
.requestMyFriends()

// Perform a request to fetch the authorized user friends
.requestUploadPhotos()

// Perform a request to upload a picture on the user account
.requestPlacesSearch()

// Perform a request to search for places with some given params
.request(GraphRequest req)
  // Perform a request for the given GraphRequest
.post()

// Perform a POST with the GraphPath/GraphObject/etc setted
.get()

 // Perform a GET with the GraphPath/params/etc setted
.delete()

 // Perform a DELETE with the GraphPath/params/etc setted
.loginWithReadPermissions()
 // Perform a login with read permissions.
.loginWithPublishPermissions() // Perform a login with publish permissions
.logout()

 // Perform a logout

Note that if using loginXXXX() methods, it will start a facebook activity and you should override the onActivityResult of the context passed as param. You should call in your onActivityResult the following method:

// Returns a boolean telling if the activity result was processed or not // Since it can be of another requestCode and not of a facebook login. RxFacebook.postLoginActivityResult(requestCode, resultCode, data);

This should be called if login is used so that we can know how the operation finished and handle its result (the returned stream of the login method used will be used for broadcasting how it went).

Notes

This library doesnt add any dependency for parsing the facebook responses nor it handles graphRequest errors as stream errors (it will be outputed as a onNext(GraphResponse) always).

This is done like this so that the user has control over all the facebook variables (pagination, error status, connection status, rawResponse, tags, etc) and can use whichever JSON parser wants.

Its up to you to parse the response with Gson/ Jackson/ whatever parser you use into the DTO/Model/Entity you requested.

Its up to you to check the graphResponse.getError() != null, since the onError() of the stream is used for internal errors (malformed requests for example, or a login activity performed incorrectly)

This shouldnt impose any restriction since we are using Rx. It should be as easy as this:

RxFacebook.create()
... // Customize
.request()
.observeOn(somewhere)
.subscribeOn(somewhereElse)
.filter(new Func1<GraphResponse, Boolean>() {

  @Override
  public Boolean call(final GraphResponse graphResponse) {

 return graphResponse.getError == null; // Filter only the ones without error

 // Or handle the error? This is just an example so its up to you...
  
}

}
)
.map(new Func1<GraphResponse, MyDto>() {

  @Override
  public MyDto call(final GraphResponse graphResponse) {

 return yourParserOfChoice.parse(graphResponse.getJSONObject(), MyDto.class);

  
}

}
)
.subscribe(...);

Resources

Crash fast library for Android.

Simple precondition library for crashing in case you find unexpected values. For example: After you login against a certain API, you have to get back your user. It's completely necessary to have a no null user, so you can checkNotNull(receivedUser).

A menu layout view with FloatingActionButton, which means you still can use the features of FAB like auto hide while scrolling.

Pan

A light weight MV* framework to build android reusable UI components.

rog

Rog is an object generator designed for android test. It can create objects and set random values to their fields.

Spark is a simple Android library that takes a series of x,y points at any scale and draws them as a sparkline chart.

It's a framework for building Android UI in Kotlin code by using the concept of virtual views and reactive data flow, the goal is to reduce boilerplate while retaining the same Android layout constructs.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes