Search in sources :

Example 6 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.

the class ProcessorProvidersBehaviour method getDataFromLoader.

private Observable<Reply> getDataFromLoader(final io.rx_cache2.ConfigProvider configProvider, final Record record) {
    return configProvider.getLoaderObservable().map(new Function<Object, Reply>() {

        @Override
        public Reply apply(Object data) throws Exception {
            boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
            if (data == null && useExpiredData && record != null) {
                return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
            }
            clearKeyIfNeeded(configProvider);
            if (data == null) {
                throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey());
            }
            twoLayersCache.save(configProvider.getProviderKey(), configProvider.getDynamicKey(), configProvider.getDynamicKeyGroup(), data, configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
            return new Reply(data, Source.CLOUD, configProvider.isEncrypted());
        }
    }).onErrorReturn(new Function<Object, Object>() {

        @Override
        public Object apply(Object o) throws Exception {
            clearKeyIfNeeded(configProvider);
            boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
            if (useExpiredData && record != null) {
                return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
            }
            throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey(), (Throwable) o);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) Reply(io.rx_cache2.Reply)

Example 7 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.

the class ProvidersRxCacheTest method _10_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_List_Then_Object_Preserves_Initial_State.

@Test
public void _10_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_List_Then_Object_Preserves_Initial_State() {
    initProviders(false);
    TestObserver<Reply<List<io.rx_cache2.internal.Mock>>> subscriber;
    subscriber = new TestObserver<>();
    providersRxCache.getMocksWithDetailResponse(createObservableMocks(SIZE)).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    Reply<List<io.rx_cache2.internal.Mock>> reply = subscriber.values().get(0);
    Type type = new TypeToken<Reply<List<io.rx_cache2.internal.Mock>>>() {
    }.getType();
    Reply<List<io.rx_cache2.internal.Mock>> replyOriginal = (Reply<List<io.rx_cache2.internal.Mock>>) deepCopy(reply, type);
    assertThat(compare(reply, replyOriginal, type), is(true));
    reply.getData().get(0).setMessage("modified");
    assertThat(compare(reply, replyOriginal, type), is(false));
    subscriber = new TestObserver<>();
    providersRxCache.getMocksWithDetailResponse(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader()).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    assertThat(subscriber.errors().size(), is(0));
    assertThat(subscriber.values().size(), is(1));
    reply = subscriber.values().get(0);
    type = new TypeToken<List<io.rx_cache2.internal.Mock>>() {
    }.getType();
    assertThat(compare(reply.getData(), replyOriginal.getData(), type), is(true));
}
Also used : Type(java.lang.reflect.Type) TypeToken(com.google.gson.reflect.TypeToken) Reply(io.rx_cache2.Reply) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPorn91VideoUrl.

@Override
public Observable<VideoResult> loadPorn91VideoUrl(String viewKey) {
    String ip = addressHelper.getRandomIPAddress();
    Observable<String> stringObservable = noLimit91PornServiceApi.getVideoPlayPage(viewKey, ip, HeaderUtils.getIndexHeader(addressHelper));
    return cacheProviders.getVideoPlayPage(stringObservable, new DynamicKey(viewKey), new EvictDynamicKey(false)).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBodyReply) throws Exception {
            switch(responseBodyReply.getSource()) {
                case CLOUD:
                    Logger.t(TAG).d("数据来自:网络");
                    break;
                case MEMORY:
                    Logger.t(TAG).d("数据来自:内存");
                    break;
                case PERSISTENCE:
                    Logger.t(TAG).d("数据来自:磁盘缓存");
                    break;
                default:
                    break;
            }
            return responseBodyReply.getData();
        }
    }).map(new Function<String, VideoResult>() {

        @Override
        public VideoResult apply(String s) throws Exception {
            return Parse91PronVideo.parseVideoPlayUrl(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) VideoResult(com.dante.data.model.VideoResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) DynamicKey(io.rx_cache2.DynamicKey) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 9 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPorn91VideoRecentUpdates.

@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91VideoRecentUpdates(String next, int page, boolean cleanCache, boolean isLoadMoreCleanCache) {
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(next, page);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache || isLoadMoreCleanCache);
    Observable<String> categoryPage = noLimit91PornServiceApi.recentUpdates(next, page, HeaderUtils.getIndexHeader(addressHelper));
    return cacheProviders.getRecentUpdates(categoryPage, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBody) throws Exception {
            return responseBody.getData();
        }
    }).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {

        @Override
        public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
            return Parse91PronVideo.parseHot(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 10 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPorn91VideoByCategory.

@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91VideoByCategory(String category, String viewType, int page, String m, boolean cleanCache, boolean isLoadMoreCleanCache) {
    // RxCache条件区别
    String condition;
    if (TextUtils.isEmpty(m)) {
        condition = category;
    } else {
        condition = category + m;
    }
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(condition, page);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache || isLoadMoreCleanCache);
    Observable<String> categoryPage = noLimit91PornServiceApi.getCategoryPage(category, viewType, page, m, HeaderUtils.getIndexHeader(addressHelper));
    return cacheProviders.getCategoryPage(categoryPage, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBody) throws Exception {
            return responseBody.getData();
        }
    }).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {

        @Override
        public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
            return Parse91PronVideo.parseHot(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Aggregations

Reply (io.rx_cache2.Reply)16 Function (io.reactivex.functions.Function)9 FavoriteException (com.dante.exception.FavoriteException)7 MessageException (com.dante.exception.MessageException)7 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)7 Test (org.junit.Test)7 BaseResult (com.dante.data.model.BaseResult)6 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)6 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)6 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)4 TypeToken (com.google.gson.reflect.TypeToken)3 TestObserver (io.reactivex.observers.TestObserver)3 DynamicKey (io.rx_cache2.DynamicKey)3 BaseTest (io.rx_cache2.internal.common.BaseTest)3 Type (java.lang.reflect.Type)3 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)2 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)2 MeiZiTu (com.dante.data.model.MeiZiTu)1 Mm99 (com.dante.data.model.Mm99)1 PigAvVideo (com.dante.data.model.PigAvVideo)1