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 TypeMethodDescriptionvoid
static <T> T
Convert 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) int
static int
parseEndPageCount
(HttpResponse<String> response) This method parse the end page count from the response header.void
printRateLimit
(HttpResponse<String> response) void
setSuppressRateError
(boolean isErrorSuppressed) If set totrue
, error messages for rate limit exceeding in the response will be hidden.void
setSuppressResponseError
(boolean isErrorSuppressed) If set totrue
, error messages for tries in the response will be hidden.void
setTokenCursor
(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:
IOException
InterruptedException
-
getHttpResponseRaw
public String getHttpResponseRaw(URI uri, String acceptSchema) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getHttpResponseRawLoopFetching
public List<String> getHttpResponseRawLoopFetching(URI rawUri, String acceptSchema, int targetPageCount, long timeIntervalMillis) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
getHttpResponse
- Throws:
IOException
InterruptedException
-
getHttpResponse
public HttpResponse<String> getHttpResponse(URI uri, String acceptSchema) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
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_VALUE
will be assigned if not found.
-