本文整理汇总了Java中com.squareup.okhttp.HttpUrl.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUrl.Builder方法的具体用法?Java HttpUrl.Builder怎么用?Java HttpUrl.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.HttpUrl
的用法示例。
在下文中一共展示了HttpUrl.Builder方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
final PackageInfo packageInfo = application.packageInfo();
final int versionNameSplit = packageInfo.versionName.indexOf('-');
final HttpUrl.Builder url = HttpUrl
.parse(Constants.VERSION_URL
+ (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : ""))
.newBuilder();
url.addEncodedQueryParameter("package", packageInfo.packageName);
url.addQueryParameter("current", Integer.toString(packageInfo.versionCode));
versionUrl = url.build();
}
示例2: generateGET
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
String generateGET(Transaction transaction) {
// Validate merchantId
if (merchantId == null || merchantId.isEmpty()) {
// The merchantId is required
throw new Error("The merchantId is required", Error.ERROR_MISSING_MERCHANT_ID, null);
}
HttpUrl.Builder builder = new HttpUrl.Builder()
.scheme(secure ? "https" : "http")
.host(SERVER)
.addPathSegment("merchants")
.addPathSegment(merchantId);
// Serialize query
transaction.serialize(builder);
Log.d(TAG, builder.build().query());
return builder.build().url().toString();
}
示例3: get
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
public <ResultType extends ResultAdapter>ResultType get(Class<ResultType> resultType) throws IOException, WebException {
HttpUrl.Builder builder = HttpUrl.parse(getFullUrl()).newBuilder();
String[] keys = getParamKeys();
for (String key : keys) {
builder.addEncodedQueryParameter(key, param.get(key));
}
HttpUrl httpUrl = builder.build();
Request.Builder reqestBuilder = new Request.Builder().url(httpUrl);
addHeaderAll(reqestBuilder);
Request request = reqestBuilder.build();
debugRequest("GET", paramString);
clearAllParams();
call = client.newCall(request);
Response response = call.execute();
ResultType result = getResult(response, resultType);
debugResponse(result.getBody(), response);
unexpectedCode(response, result.getBody());
return result;
}
示例4: getUserTips
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Returns tips from a user.
*
* @param userId Identity of the user to get tips from. Pass self to get tips of the acting
* user.
* @param limit Number of results to return, up to 200.
* @param offset The number of results to skip. Used to page through results.
* @param llBounds optional Restricts the returned results to the input bounding box.
* @param categoryId optional Restricts the returned results to venues matching the input
* category id.
* @param sort optional Sorts the list items. Possible values are recent and nearby. recent
* sorts the list items by the date added to the list. nearby sorts the list items by the
* distance from the center of the provided llBounds.
* @return a List of tips
*/
public Result<List> getUserTips(String userId, Integer limit, Integer offset,
String llBounds, String categoryId, String sort) {
HttpUrl.Builder urlBuilder = newApiUrlBuilder()
.addPathSegment("lists")
.addPathSegment(userId)
.addPathSegment("tips");
if (limit != null) urlBuilder.addQueryParameter("limit", String.valueOf(limit));
if (offset != null) urlBuilder.addQueryParameter("offset", String.valueOf(offset));
if (llBounds != null) urlBuilder.addQueryParameter("llBounds", llBounds);
if (categoryId != null) urlBuilder.addQueryParameter("categoryId", categoryId);
if (sort != null) urlBuilder.addQueryParameter("sort", sort);
String json = newRequest(urlBuilder.toString());
LOGGER.debug("Response ---> {}", json);
return Parser.parse(json, "list", List.class);
}
示例5: getUserVenueLikes
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Returns a list of venues liked by the specified user.
*
* @param userId User ID or self.
* @param beforeTimestamp Seconds since epoch..
* @param afterTimestamp Seconds since epoch.
* @param categoryId Limits returned venues to those in this category. If specifying a top-level
* category, all sub-categories will also match the query.
* @param limit Number of results to return.
* @param offset Used to page through results.
* @return a Group of Venues wrapped in a Result object.
*/
public Result<Group<Venue>> getUserVenueLikes(String userId, Long beforeTimestamp,
Long afterTimestamp, String categoryId, Integer limit, Integer offset) {
HttpUrl.Builder urlBuilder = newApiUrlBuilder()
.addPathSegment("users")
.addPathSegment(userId)
.addPathSegment("venuelikes");
if (beforeTimestamp != null) urlBuilder.addQueryParameter("beforeTimestamp", String.valueOf(beforeTimestamp));
if (afterTimestamp != null) urlBuilder.addQueryParameter("afterTimestamp", String.valueOf(afterTimestamp));
if (categoryId != null) urlBuilder.addQueryParameter("categoryId", categoryId);
if (limit != null) urlBuilder.addQueryParameter("limit", String.valueOf(limit));
if (offset != null) urlBuilder.addQueryParameter("offset", String.valueOf(offset));
String json = newRequest(urlBuilder.toString());
LOGGER.debug("Response ---> {}", json);
return Parser.parse(json, "venues", new TypeToken<Group<Venue>>(){});
}
示例6: getMartianUrl
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Returns a canonicalized URL as a string that can be used for Martian system requests. These
* URLs will be of the form http://martian.proxy/{path}. The provided path should contian a
* leading slash. Any forward slashes in the provided path will be handled as path delimeters.
*
* @param path Path portion of the Martian system request URL
**/
public String getMartianUrl(String path) {
HttpUrl.Builder urlBuilder = new HttpUrl.Builder().scheme("http").host(this.proxyHost);
String[] parts = path.split("/");
for (String part : parts) {
urlBuilder.addPathSegment(part);
}
return urlBuilder.build().toString();
}
示例7: formatUrl
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
HttpUrl formatUrl(String template, Map<String, String> pathParams,
Map<String, Object> queryParams) {
String path = template;
for (Map.Entry<String, String> entry : pathParams.entrySet()) {
path = path.replace(":" + entry.getKey(), entry.getValue());
}
HttpUrl.Builder builder = baseUrl.resolve(path).newBuilder();
for (Map.Entry<String, Object> param : queryParams.entrySet()) {
builder.addQueryParameter(param.getKey(), param.getValue().toString());
}
return builder.build();
}
示例8: getAccessToken
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Retrieves the access token from Foursquare when using native authentication in clients.
*
* @param redirectUri your registered redirect uri. Pass {@code null} if you got the code from a
* native app (iOS or Android).
* @param code the authorization code.
* @return a AccessTokenResponse.
*/
public AccessTokenResponse getAccessToken(String redirectUri, String code) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(authUrl()).newBuilder()
.addQueryParameter("client_id", clientId)
.addQueryParameter("client_secret", clientSecret)
.addQueryParameter("grant_type", "authorization_code")
.addQueryParameter("code", code);
if (redirectUri != null) urlBuilder.addQueryParameter("redirect_uri", redirectUri);
String json = newRequest(urlBuilder.toString());
LOGGER.debug("Response ---> {}", json);
return new AccessTokenResponse(json);
}
示例9: getUserFriends
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Returns an array of a user's friends.
*
* @param userId Identity of the user to get friends of. Pass self to get friends of the acting
* user.
* @param limit Number of results to return, up to 500.
* @param offset Used to page through results.
* @return a Group of Users wrapped in a Result object.
*/
public Result<Group<User>> getUserFriends(String userId, Integer limit, Integer offset) {
HttpUrl.Builder urlBuilder = newApiUrlBuilder()
.addPathSegment("users")
.addPathSegment(userId)
.addPathSegment("friends");
if (limit != null) urlBuilder.addQueryParameter("limit", String.valueOf(limit));
if (offset != null) urlBuilder.addQueryParameter("offset", String.valueOf(offset));
String json = newRequest(urlBuilder.toString());
LOGGER.debug("Response ---> {}", json);
return Parser.parse(json, "friends", new TypeToken<Group<User>>(){});
}
示例10: newApiUrlBuilder
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
* Builds a new HttpUrl.Builder preinitialized with the Foursquare API url parameters.
*
* @return a new HttpUrl.Builder.
*/
private HttpUrl.Builder newApiUrlBuilder() {
HttpUrl.Builder urlBuilder = HttpUrl.parse(apiUrl()).newBuilder()
.addQueryParameter("v", VERSION);
if (accessToken != null) urlBuilder.addQueryParameter("oauth_token", accessToken);
else {
urlBuilder.addQueryParameter("client_id", clientId)
.addQueryParameter("client_secret", clientSecret);
}
return urlBuilder;
}
示例11: resolve
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
public HttpUrl resolve(HttpUrl base) {
HttpUrl.Builder builder = base.newBuilder();
for (String path : mPaths) {
builder.addPathSegment(path);
}
return builder.build();
}
示例12: buildQuery
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Override
void buildQuery(HttpUrl.Builder urlBuilder) {
urlBuilder.addQueryParameter("ca", toString());
}
示例13: getDefaultUrlBuilder
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
protected HttpUrl.Builder getDefaultUrlBuilder() {
return new HttpUrl.Builder()
.scheme(ApiConfig.DEFAULT_SCHEME)
.host(ApiConfig.DEFAULT_HOST)
.addEncodedPathSegment(ApiConfig.DEFAULT_PREFIX_PATH_SEGMENT);
}