11
11
import javax .crypto .Mac ;
12
12
import javax .crypto .spec .SecretKeySpec ;
13
13
import lombok .Getter ;
14
+ import lombok .extern .slf4j .Slf4j ;
14
15
import okhttp3 .Response ;
15
- import org .slf4j .Logger ;
16
- import org .slf4j .LoggerFactory ;
17
16
18
17
/** */
18
+ @ Slf4j
19
19
@ Getter
20
20
public class SwitchBotApi {
21
- private static final Logger logger = LoggerFactory .getLogger (SwitchBotApi .class );
22
21
protected static final String baseUrl = "https://api.switch-bot.com/" ;
23
22
24
23
private static SwitchBotApi instance ;
@@ -38,7 +37,7 @@ private SwitchBotApi(String token, String secret) {
38
37
39
38
public static SwitchBotApi getInstance (String token , String secret ) {
40
39
if (token == null || secret == null ) {
41
- logger .error ("need to define token and secret values." );
40
+ log .error ("need to define token and secret values." );
42
41
throw new RuntimeException ("need to define token and secret values." );
43
42
}
44
43
return Optional .ofNullable (instance ).orElseGet (() -> {
@@ -67,7 +66,7 @@ protected RequestBuilderCallback addAuth() {
67
66
.addHeader ("nonce" , nonce )
68
67
.addHeader ("t" , time );
69
68
} catch (NoSuchAlgorithmException | InvalidKeyException e ) {
70
- logger .warn ("exception with auth: " , e );
69
+ log .warn ("exception with auth: " , e );
71
70
}
72
71
return builder ;
73
72
};
@@ -83,13 +82,13 @@ protected boolean checkForError(Response response, Optional<IApiResponse> apiRes
83
82
return apiResponse
84
83
.map (api -> {
85
84
if (api .getStatusCode () != 100 ) {
86
- logger .error ("error code: " + api .getStatusCode () + " : " + api .getMessage ());
85
+ log .error ("error code: " + api .getStatusCode () + " : " + api .getMessage ());
87
86
return false ;
88
87
}
89
88
return true ;
90
89
})
91
90
.orElseGet (() -> {
92
- logger .error ("Error calling switchbot api: " + response .code () + " " + response .message ());
91
+ log .error ("Error calling switchbot api: " + response .code () + " " + response .message ());
93
92
return false ;
94
93
});
95
94
}
0 commit comments