Class RestAPI
java.lang.Object
edu.sustech.search.engine.github.API.RestAPI
- Direct Known Subclasses:
ContentAPI,FileAPI,GitHubAPI,RateAPI,RepositoryAPI,SearchAPI,UserAPI
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic <T> TConvert the object using the internal objectMapper created at instantiation.getHttpResponse(URI uri) getHttpResponse(URI uri, String acceptSchema) getHttpResponseLoopFetching(URI rawUri, int targetPageCount) Get the response in a loop-fetching style.getHttpResponseLoopFetching(URI rawUri, int targetPageCount, long timeIntervalMillis) Get the response in a loop-fetching stylegetHttpResponseLoopFetching(URI rawUri, String acceptSchema, int targetPageCount) Get the response in a loop-fetching style.getHttpResponseLoopFetching(URI rawUri, String acceptSchema, int targetPageCount, long timeIntervalMillis) Get the response in a loop-fetching stylegetHttpResponseRaw(URI uri) getHttpResponseRaw(URI uri, String acceptSchema) getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount) getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount, long timeIntervalMillis) getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount) getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount, long timeIntervalMillis) intstatic intparseEndPageCount(HttpResponse<String> response) This method parse the end page count from the response header.voidprintRateLimit(HttpResponse<String> response) voidsetSuppressRateError(boolean isErrorSuppressed) If set totrue, error messages for rate limit exceeding in the response will be hidden.voidsetSuppressResponseError(boolean isErrorSuppressed) If set totrue, error messages for tries in the response will be hidden.voidsetTokenCursor(int newPosition)
-
Field Details
-
TIME_OUT_DURATION
-
-
Constructor Details
-
RestAPI
Initialize this API with multiple tokens for querying.- Parameters:
OAuthTokens- Array containing OAuthTokens.
-
RestAPI
Initialize this API with multiple tokens for querying.- Parameters:
OAuthTokens- List containing OAuthTokens.
-
RestAPI
public RestAPI()
-
-
Method Details
-
getHttpResponseRaw
- Throws:
IOExceptionInterruptedException
-
getHttpResponseRaw
public String getHttpResponseRaw(URI uri, String acceptSchema) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
getHttpResponseLoopFetching
public List<HttpResponse<String>> getHttpResponseLoopFetching(URI rawUri, int targetPageCount) throws IOException, InterruptedException Get the response in a loop-fetching style. The default time interval between each request will be used.- Parameters:
rawUri- Raw uri without per_page settings and page numberstargetPageCount- Target page count- Throws:
IOExceptionInterruptedException
-
getHttpResponseLoopFetching
public List<HttpResponse<String>> getHttpResponseLoopFetching(URI rawUri, String acceptSchema, int targetPageCount) throws IOException, InterruptedException Get the response in a loop-fetching style. The default time interval between each request will be used.- Parameters:
rawUri- Raw uri without per_page settings and page numbersacceptSchema- Accept schematargetPageCount- Target page count- Throws:
IOExceptionInterruptedException
-
getHttpResponseLoopFetching
public List<HttpResponse<String>> getHttpResponseLoopFetching(URI rawUri, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException Get the response in a loop-fetching style- Parameters:
rawUri- Raw uri without per_page settings and page numberstargetPageCount- Target page counttimeIntervalMillis- Time interval between each request made- Throws:
IOExceptionInterruptedException
-
getHttpResponseLoopFetching
public List<HttpResponse<String>> getHttpResponseLoopFetching(URI rawUri, String acceptSchema, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException Get the response in a loop-fetching style- Parameters:
rawUri- Raw uri without per_page settings and page numbersacceptSchema- Accept schematargetPageCount- Target page counttimeIntervalMillis- Time interval between each request made- Throws:
IOExceptionInterruptedException
-
getHttpResponse
- Throws:
IOExceptionInterruptedException
-
getHttpResponse
public HttpResponse<String> getHttpResponse(URI uri, String acceptSchema) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
setSuppressResponseError
public void setSuppressResponseError(boolean isErrorSuppressed) If set totrue, error messages for tries in the response will be hidden. This is usually used in loop fetching.- Parameters:
isErrorSuppressed-
-
setSuppressRateError
public void setSuppressRateError(boolean isErrorSuppressed) If set totrue, error messages for rate limit exceeding in the response will be hidden. This is usually used insearchAPI.- Parameters:
isErrorSuppressed-
-
printRateLimit
-
getRateLimit
- Throws:
IOExceptionInterruptedException
-
addToken
-
getNextToken
-
getTokenCursor
public int getTokenCursor() -
setTokenCursor
public void setTokenCursor(int newPosition) -
convert
Convert the object using the internal objectMapper created at instantiation.- Parameters:
jsonContent- JsonContentclazz- Target class- Returns:
- An instance of the target class parsed from the json content provided.
-
parseEndPageCount
This method parse the end page count from the response header.- Parameters:
response- Response to parse- Returns:
- The end page count.
Integer.MAX_VALUEwill be assigned if not found.
-