本文整理汇总了Java中retrofit.client.Request.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getMethod方法的具体用法?Java Request.getMethod怎么用?Java Request.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retrofit.client.Request
的用法示例。
在下文中一共展示了Request.getMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
try {
List<Header> headers = new LinkedList<Header>(request.getHeaders());
// if logged in add auth header
Optional<Account> account = loginManager.getAccount();
if (account.isPresent()) {
String token = loginManager.getToken(account.get());
Header authHeader = new Header("Authorization", "Bearer " + token);
headers.add(authHeader);
}
Request signedRequest = new Request(
request.getMethod(),
request.getUrl(),
headers,
request.getBody());
return super.execute(signedRequest);
} catch (GoogleAuthException gae) {
throw new IOException(gae);
}
}
示例2: prepareHttpRequest
import retrofit.client.Request; //导入方法依赖的package包/类
public static HttpRequest prepareHttpRequest(final Request request) throws IOException {
// Extract details from incoming request from Retrofit
final String requestUrl = request.getUrl();
final String requestMethod = request.getMethod();
final List<Header> requestHeaders = request.getHeaders();
// URL and Method
final HttpRequest httpRequest = new HttpRequest(requestUrl, requestMethod);
// Headers
for (Header header: requestHeaders) {
httpRequest.header(header.getName(), header.getValue());
}
return httpRequest;
}
示例3: execute
import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
Response response = super.execute(request);
if (response.getStatus() == 401) {
// Unauthorized, attempt to refresh access token
String refreshToken = mAuthModel.getRefreshToken();
if (refreshToken == null) {
return response;
}
mAuthModel = sAuthService.refreshToken(refreshToken);
mAuthModel.setContext(mContext);
mAuthModel.saveTokens();
// Switch out auth token in request
List<Header> headers = new ArrayList<Header>();
for (Header header : request.getHeaders()) {
if (header.getName().equals("Authorization")) {
headers.add(new Header("Authorization", "Bearer " + mAuthModel.getUserToken()));
} else {
headers.add(header);
}
}
// Retry request
Request updatedRequest = new Request(request.getMethod(), request.getUrl(), headers, request.getBody());
return super.execute(updatedRequest);
} else {
return response;
}
}
示例4: sign
import retrofit.client.Request; //导入方法依赖的package包/类
/**
* internal sign function of the request.
*
* @param request the request
* @return the request
*/
private Request sign(final Request request) {
if (request != null && request.getHeaders() != null) {
try {
List<Header> modifiedHeaders = new ArrayList<Header>();
// duplicate the headers if there is already something
if (request.getHeaders().isEmpty()) {
for (int i = 0; i < request.getHeaders().size(); i++) {
Header header = request.getHeaders().get(i);
// avoid duplication otherwise it will repeted forever
if (!modifiedHeaders.contains(header)) {
modifiedHeaders.add(header);
}
}
}
// signing thing
modifiedHeaders.add(new Header("X-Ovh-Application", applicationKey));
modifiedHeaders.add(new Header("Content-type", "application/json"));
return new Request(request.getMethod(), request.getUrl(), modifiedHeaders, request.getBody());
} catch (Exception e) {
exceptionHandler.handleException(e);
}
}
return request;
}
示例5: sendBody
import retrofit.client.Request; //导入方法依赖的package包/类
public static void sendBody(final Request request, final HttpRequest httpRequest) throws IOException {
final String requestMethod = request.getMethod();
final TypedOutput requestBody = request.getBody();
// Only POST and PUT has body as far as I know
if ((METHOD_POST.equals(requestMethod)) || METHOD_PUT.equals(requestMethod)) {
if (requestBody != null) {
// Content-Type
httpRequest.contentType(requestBody.mimeType());
// Payload
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestBody.writeTo(outputBytes);
byte[] dataBytes = outputBytes.toByteArray();
try {
httpRequest.send(dataBytes);
} catch (HttpRequest.HttpRequestException hre) {
// Throw original IOException since Retrofit handles this
throw hre.getCause();
}
}
}
}
示例6: execute
import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute( Request request ) throws IOException
{
if ( !isUserLoggedIn() )
{
throw new IOException( "User not logged in" );
}
// First, sign the request
OAuthRequest oAuthRequest = new OAuthRequest( getVerbForMethod( request.getMethod() ), request.getUrl() );
signingService.signRequest( getAccessToken(), oAuthRequest );
// Then switch the old headers with signed headers
Map<String, String> signedHeadersMap = oAuthRequest.getHeaders();
List<Header> signedHeaders = new ArrayList<Header>( signedHeadersMap.size() );
for ( Map.Entry<String, String> header : signedHeadersMap.entrySet() )
{
signedHeaders.add( new Header( header.getKey(), header.getValue() ) );
}
// Switch old url with new url
String signedUrl = oAuthRequest.getCompleteUrl();
Helper.debug( signedUrl );
// Make new request with signed headers and url
Request signedRequest = new Request( request.getMethod(), signedUrl, signedHeaders, request.getBody() );
// We need to check status of response in case it failed due to access token expiry
Response response = super.execute( signedRequest );
// 401 most likely indicates that access token has expired.
// Time to refresh and resend the request
if ( response.getStatus() == 401 && accessTokenCanExpire() )
{
// Do ensure that updateAccessToken() stores the value
// of the updated access token in AccountPrefs.
updateAccessToken();
return execute( request );
}
return response;
}
示例7: featureValueOf
import retrofit.client.Request; //导入方法依赖的package包/类
@Override
protected String featureValueOf(Request request) {
return request.getMethod();
}
示例8: execute
import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
URI uri = URI.create(request.getUrl());
String method = request.getMethod();
String responseString = "{}";
if (uri.getPath().equals("/v1/estimates/time") && "GET".equals(method)) {
/**
* {@link com.victorsima.uber.UberService#getTimeEstimates(double, double, String, String)}
**/
responseString = "{\"times\":[{\"localized_display_name\":\"uberX\",\"estimate\":140,\"display_name\":\"uberX\",\"product_id\":\"b8e5c464-5de2-4539-a35a-986d6e58f186\"},{\"localized_display_name\":\"uberXL\",\"estimate\":571,\"display_name\":\"uberXL\",\"product_id\":\"1e0ce2df-4a1e-4333-86dd-dc0c67aaabe1\"},{\"localized_display_name\":\"UberBLACK\",\"estimate\":224,\"display_name\":\"UberBLACK\",\"product_id\":\"0e9d8dd3-ffec-4c2b-9714-537e6174bb88\"},{\"localized_display_name\":\"UberSUV\",\"estimate\":224,\"display_name\":\"UberSUV\",\"product_id\":\"56487469-0d3d-4f19-b662-234b7576a562\"},{\"localized_display_name\":\"uberT\",\"estimate\":40,\"display_name\":\"uberT\",\"product_id\":\"ebe413ab-cf49-465f-8564-a71119bfa449\"}]}";
} else if (uri.getPath().equals("/v1/estimates/price") && "GET".equals(method)) {
/**
* {@link com.victorsima.uber.UberService#getPriceEstimates(double, double, double, double)}
*/
responseString = "{\"prices\":[{\"localized_display_name\":\"uberX\",\"duration\":1730,\"low_estimate\":\"31\",\"display_name\":\"uberX\",\"product_id\":\"b8e5c464-5de2-4539-a35a-986d6e58f186\",\"distance\":9.5,\"surge_multiplier\":1.0,\"estimate\":\"$31-42\",\"high_estimate\":\"42\",\"currency_code\":\"USD\"},{\"localized_display_name\":\"uberXL\",\"duration\":1730,\"low_estimate\":\"47\",\"display_name\":\"uberXL\",\"product_id\":\"1e0ce2df-4a1e-4333-86dd-dc0c67aaabe1\",\"distance\":9.5,\"surge_multiplier\":1.0,\"estimate\":\"$47-63\",\"high_estimate\":\"63\",\"currency_code\":\"USD\"},{\"localized_display_name\":\"UberBLACK\",\"duration\":1730,\"low_estimate\":\"55\",\"display_name\":\"UberBLACK\",\"product_id\":\"0e9d8dd3-ffec-4c2b-9714-537e6174bb88\",\"distance\":9.5,\"surge_multiplier\":1.0,\"estimate\":\"$55-72\",\"high_estimate\":\"72\",\"currency_code\":\"USD\"},{\"localized_display_name\":\"UberSUV\",\"duration\":1730,\"low_estimate\":\"73\",\"display_name\":\"UberSUV\",\"product_id\":\"56487469-0d3d-4f19-b662-234b7576a562\",\"distance\":9.5,\"surge_multiplier\":1.0,\"estimate\":\"$73-92\",\"high_estimate\":\"92\",\"currency_code\":\"USD\"},{\"localized_display_name\":\"uberT\",\"duration\":1730,\"low_estimate\":null,\"display_name\":\"uberT\",\"product_id\":\"ebe413ab-cf49-465f-8564-a71119bfa449\",\"distance\":9.5,\"surge_multiplier\":1.0,\"estimate\":\"Metered\",\"high_estimate\":null,\"currency_code\":null}]}";
} else if (uri.getPath().equals("/v1/products") && "GET".equals(method)) {
/**
* {@link com.victorsima.uber.UberService#getProducts(double, double)}
*/
responseString = "{\"products\":[{\"capacity\":4,\"image\":\"http:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/car-types\\/mono\\/mono-uberx.png\",\"display_name\":\"uberX\",\"product_id\":\"b8e5c464-5de2-4539-a35a-986d6e58f186\",\"description\":\"The Low Cost Uber\"},{\"capacity\":6,\"image\":\"http:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/car-types\\/mono\\/mono-uberxl2.png\",\"display_name\":\"uberXL\",\"product_id\":\"1e0ce2df-4a1e-4333-86dd-dc0c67aaabe1\",\"description\":\"low-cost rides for large groups\"},{\"capacity\":4,\"image\":\"http:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/car-types\\/mono\\/mono-black.png\",\"display_name\":\"UberBLACK\",\"product_id\":\"0e9d8dd3-ffec-4c2b-9714-537e6174bb88\",\"description\":\"The original Uber\"},{\"capacity\":6,\"image\":\"http:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/car-types\\/mono\\/mono-suv.png\",\"display_name\":\"UberSUV\",\"product_id\":\"56487469-0d3d-4f19-b662-234b7576a562\",\"description\":\"Room for everyone\"},{\"capacity\":1,\"image\":\"http:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/car-types\\/mono\\/mono-nytaxi4.png\",\"display_name\":\"uberT\",\"product_id\":\"ebe413ab-cf49-465f-8564-a71119bfa449\",\"description\":\"Taxi and Boro-Taxi without the hassle\"}]}";
} else if (uri.getPath().equals("/v1/promotions") && "GET".equals(method)) {
/**
* {@link com.victorsima.uber.UberService#getPromotions(double, double, double, double)}
*/
responseString = "{\"display_text\":\"Free ride up to $30\",\"localized_value\":\"$30\",\"type\":\"trip_credit\"}";
} else if (uri.getPath().equals("/v1/me") && "GET".equals(method)) {
responseString = "{\n" +
" \"first_name\": \"Uber\",\n" +
" \"last_name\": \"Developer\",\n" +
" \"email\": \"[email protected]\",\n" +
" \"picture\": \"https://...\",\n" +
" \"promo_code\": \"teypo\",\n" +
" \"uuid\": \"91d81273-45c2-4b57-8124-d0165f8240c0\"\n" +
"}";
} else if (uri.getPath().equals("/v1/requests") && "POST".equals(method)) {
responseString = "{\n" +
" \"request_id\": \"852b8fdd-4369-4659-9628-e122662ad257\",\n" +
" \"status\": \"processing\",\n" +
" \"vehicle\": {\n" +
" \"make\":\"Bugatti\",\n" +
" \"model\":\"Veyron\",\n" +
" \"license_plate\":\"I<3Uber\",\n" +
" \"picture_url\":\"https:\\/\\/d1w2poirtb3as9.cloudfront.net\\/car.jpeg\"\n" +
" }," +
" \"driver\": {\n" +
" \"phone_number\":\"(555)555-5555\",\n" +
" \"rating\":5,\n" +
" \"picture_url\":\"https:\\/\\/d1w2poirtb3as9.cloudfront.net\\/img.jpeg\",\n" +
" \"name\":\"Bob\"\n" +
" }," +
" \"location\": {\n" +
" \"latitude\":37.776033,\n" +
" \"longitude\":-122.418143\n" +
" }," +
" \"eta\": 5,\n" +
" \"surge_multiplier\": 1.0\n" +
"}";
}
return new Response(uri.toString(), 200, "OK", new ArrayList<Header>(), new TypedByteArray("application/json", responseString.getBytes()));
}