forked from PingPlusPlus/pingpp-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingpp.java
More file actions
136 lines (116 loc) · 3.28 KB
/
Pingpp.java
File metadata and controls
136 lines (116 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.pingplusplus;
/**
* Ping++ Base class
*/
public abstract class Pingpp {
/**
* Ping++ API BASE URL
*/
public static final String LIVE_API_BASE = "https://api.pingxx.com";
/**
* version
*/
public static final String VERSION = "2.4.0";
/**
* api key
*/
public static volatile String apiKey;
public static volatile String appId;
public static String acceptLanguage = "zh-CN";
private static volatile String apiBase = LIVE_API_BASE;
public static volatile String privateKey;
public static volatile String privateKeyPath;
public static Boolean DEBUG = false;
public static final int DEFAULT_CONNECT_TIMEOUT = 30 * 1000;
public static final int DEFAULT_READ_TIMEOUT = 80 * 1000;
private static volatile int connectTimeout = -1;
private static volatile int readTimeout = -1;
private static volatile int maxNetworkRetries = 1;
/**
* (FOR TESTING ONLY)
* If you'd like your API requests to hit your own (mocked) server,
* you can set this up here by overriding the base api URL.
* @param overriddenApiBase API 地址
*/
public static void overrideApiBase(final String overriddenApiBase) {
apiBase = overriddenApiBase;
}
/**
* get api url
*
* @return String api url
*/
public static String getApiBase() {
return apiBase;
}
/**
* set api url
*
* @param apiBase apiBase API 地址
*/
public static void setApiBase(String apiBase) {
Pingpp.apiBase = apiBase;
}
/**
* 网络连接超时时间
*
* @return timeout value in milliseconds
*/
public static int getConnectTimeout() {
if (connectTimeout == -1) {
return DEFAULT_CONNECT_TIMEOUT;
}
return connectTimeout;
}
/**
* 设置网络连接超时时间 (毫秒)
*
* @param timeout timeout value in milliseconds
*/
public static void setConnectTimeout(final int timeout) {
connectTimeout = timeout;
}
/**
* 数据读取超时时间
*
* @return timeout value in milliseconds
*/
public static int getReadTimeout() {
if (readTimeout == -1) {
return DEFAULT_READ_TIMEOUT;
}
return readTimeout;
}
/**
* 设置数据读取超时时间 (毫秒)
*
* 不同接口的耗时时间不一样,部分接口的耗时可能比较长。
*
* @param timeout timeout value in milliseconds
*/
public static void setReadTimeout(final int timeout) {
readTimeout = timeout;
}
/**
* 连接失败时的最大重试次数
*
* @return the maximum number of times requests will be retried
*/
public static int getMaxNetworkRetries() {
return maxNetworkRetries;
}
/**
* 设置连接失败时的最大重试次数
*
* @param numRetries the maximum number of times requests will be retried
*/
public static void setMaxNetworkRetries(final int numRetries) {
maxNetworkRetries = numRetries;
}
public static String getAcceptLanguage() {
return acceptLanguage;
}
public static void setAcceptLanguage(String acceptLanguage) {
Pingpp.acceptLanguage = acceptLanguage;
}
}