增加 PassportService.getCaptcha 的快捷调用

This commit is contained in:
czp 2018-02-11 09:38:24 +08:00
parent 33c8c8ad6f
commit 6720bf3798
3 changed files with 25 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package com.hiczp.bilibili.api.live; package com.hiczp.bilibili.api.live;
import com.hiczp.bilibili.api.BilibiliClientProperties;
import com.hiczp.bilibili.api.live.entity.*; import com.hiczp.bilibili.api.live.entity.*;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.*; import retrofit2.http.*;
@ -63,7 +64,7 @@ public interface LiveService {
Call<SendOnlineHeartResponseEntity> sendOnlineHeart(@Field("room_id") long roomId, @Field("scale") String scale); Call<SendOnlineHeartResponseEntity> sendOnlineHeart(@Field("room_id") long roomId, @Field("scale") String scale);
default Call<SendOnlineHeartResponseEntity> sendOnlineHeart(long roomId) { default Call<SendOnlineHeartResponseEntity> sendOnlineHeart(long roomId) {
return sendOnlineHeart(roomId, "xxhdpi"); return sendOnlineHeart(roomId, BilibiliClientProperties.defaultSetting().getScale());
} }
@POST("api/sendmsg") @POST("api/sendmsg")

View File

@ -17,8 +17,12 @@ import javax.annotation.Nullable;
public interface PassportService { public interface PassportService {
//获取验证码 //获取验证码
default okhttp3.Call getCaptcha(@Nonnull String cookies) { default okhttp3.Call getCaptcha(@Nonnull String cookies) {
return getCaptcha(cookies, HttpLoggingInterceptor.Level.BASIC);
}
default okhttp3.Call getCaptcha(@Nonnull String cookies, @Nonnull HttpLoggingInterceptor.Level logLevel) {
return new OkHttpClient.Builder() return new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)) .addInterceptor(new HttpLoggingInterceptor().setLevel(logLevel))
.build() .build()
.newCall( .newCall(
new Request.Builder() new Request.Builder()

View File

@ -26,20 +26,24 @@ public class RuleSuite {
public static ExternalResource externalResource = new ExternalResource() { public static ExternalResource externalResource = new ExternalResource() {
@Override @Override
protected void before() throws Throwable { protected void before() throws Throwable {
//初始化 slf4j init();
BasicConfigurator.configure();
//读取配置文件
try {
Config.setConfig(
new Gson().fromJson(
new BufferedReader(new InputStreamReader(Config.class.getResourceAsStream("/config.json"))),
Config.class
)
);
} catch (NullPointerException e) {
//抛出异常就可以取消测试
throw new RuntimeException("Please create config file before tests");
}
} }
}; };
public static void init() {
//初始化 slf4j
BasicConfigurator.configure();
//读取配置文件
try {
Config.setConfig(
new Gson().fromJson(
new BufferedReader(new InputStreamReader(Config.class.getResourceAsStream("/config.json"))),
Config.class
)
);
} catch (NullPointerException e) {
//抛出异常就可以取消测试
throw new RuntimeException("Please create config file before tests");
}
}
} }