android media.data,GitHub - wikimedia/wikimedia-android-data-client: Android library for communicati...

Wikimedia Android数据客户端是一个用于与Wikimedia项目通信的库,它提供了Retrofit和RxJava的高级绑定,简化了客户端集成。该库包含用于处理MediaWiki API返回的模型结构、常见实用方法,并支持自定义API调用。要使用该库,你需要创建一个继承自AppAdapter的类并实现其方法,然后通过ServiceFactory获取服务接口进行API调用。此外,库中还内置了缓存逻辑,提高了效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Wikimedia Android data client

An Android library for communicating with Wikimedia projects, with Rx bindings and other utilities.

Motivation and philosophy

Here are the purposes for creating this library:

Encapsulate the various model structures that are returned by MediaWiki APIs,

as well as by REST APIs provided by Wikimedia services.

Provide high-level bindings for Retrofit and RxJava for executing calls to MediaWiki APIs to

further simplify client integration, while also allowing customization and extension.

Provide numerous common utility methods, so that they don't need to be duplicated.

Integration with your app

Add the dependency to your Gradle file as usual:

implementation "com.dmitrybrant:wikimedia-android-data-client:0.0.18"

The only nontrivial point of integration with the library is the AppAdapter class: You

need to create a class that inherits from AppAdapter and implement its methods. The

methods are mostly self-explanatory, and deal with user account management, cookie storage,

and a few other customizations.

Once you create this class (suppose it's called MyAppAdapter), you should pass it into

the AppAdapter singleton when your app starts:

@Override

public void onCreate() {

...

AppAdapter.set(new MyAppAdapter());

...

}

Making calls to APIs

Notice that there is an interface called Service that contains a number of API definitions

for talking with a MediaWiki server. To use any of the functions in the interface, you should

use the ServiceFactory class. For example:

WikiSite wiki = new WikiSite("en.wikipedia.org");

Observable observable = ServiceFactory.get(wiki).fullTextSearch("foo");

That's it! Notice that most of the API calls return an Observable response which you can

feed into an Rx subscription.

Note: the ServiceFactory class contains automatic caching logic, so that multiple calls to

get() the service for the same WikiSite will be very efficient.

Custom API calls

The ServiceFactory class also allows you to provide a service interface with custom

API functions. Suppose you create your own service interface that looks like this:

public interface MyInterface {

@GET("action=myawesomeaction")

Observable myAwesomeApiCall(@Query("parameter1") parameter);

}

You can then use it with ServiceFactory this way:

WikiSite wiki = new WikiSite("my.awesome.wiki");

Observable observable = ServiceFactory.get(wiki, "https://my.awesome.wiki/", MyInterface.class)

.myAwesomeApiCall("foo");

Utility methods

The library contains a potpourri of utility methods found under the util package. Feel free

to browse through them and use them as necessary.

License

Copyright 2019 Wikimedia Foundation

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值