RxPeople Documentation

repository·master·Indexed 19 days ago

https://github.com/cesarferreira/rxpeople

An Android library providing a fluent API to generate random user data as RxJava Observables. It allows specifying the number of users, nationality, and gender, and provides a FakeUser class that can be mapped to custom domain models.

Tokens
698
Snippets
3
Records
3
Agent score
15%

What's inside RxPeople

  1. Generate random user data with RxPeople

    master

    RxPeople provides a fluent API to generate random user data using RxJava Observables. You can specify the number of users, nationality, and gender.

    Important Threading Note: To guarantee which thread the request runs on, you must explicitly set both .subscribeOn() and .observeOn().

    // Getting 100 random women and men from random countries
    RxPeople.with(context)
             .amount(100)
             .intoObservable()
             .subscribeOn(Schedulers.io())
             .observeOn(AndroidSchedulers.mainThread())
             .subscribe(users -> {
                // handle users
             });
    
    // Being specific: Getting 50 women from Brazil
    RxPeople.with(context)
             .amount(50)
             .nationality(Nationality.BR)
             .gender(Gender.FEMALE)
             .intoObservable()
             .subscribeOn(Schedulers.io())
             .observeOn(AndroidSchedulers.mainThread())
             .subscribe(users -> {
                // handle users
             });
  2. Transform FakeUser into a custom User class

    master

    If you want to map the library's FakeUser class into your own domain model (e.g., UserClass), use the RxJava flatMap operator to transform the data before subscribing to the Observer.

    RxPeople.with(context)
             .amount(50)
             .intoObservable()
             .flatMap(fakeUser -> {
                // Transform FakeUser to your UserClass
                return Observable.just(new UserClass(fakeUser.getName(), ...));
             })
             .subscribe(yourUserClass -> {
                // todo: what you please
             });