List of usage examples for com.squareup.okhttp OkHttpClient newCall
public Call newCall(Request request)
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareGetPostList(OkHttpClient okHttpClient, String id, int page) { String url = ACUrl.getPostListUrl(id, page); Log.d(TAG, url);//from ww w . j ava 2 s. c om Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareGetPost(OkHttpClient okHttpClient, String id, int page) { String url = ACUrl.getPostUrl(id, page); Log.d(TAG, url);/*from w w w. j a va2 s . co m*/ Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareGetReference(OkHttpClient okHttpClient, String id) { String url = ACUrl.getReferenceUrl(id); Log.d(TAG, url);/*www . java2 s .co m*/ Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareReply(OkHttpClient okHttpClient, ACReplyStruct struct) throws Exception { MultipartBuilder builder = new MultipartBuilder(); builder.type(MultipartBuilder.FORM); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"name\""), RequestBody.create(null, StringUtils.avoidNull(struct.name))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"email\""), RequestBody.create(null, StringUtils.avoidNull(struct.email))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"title\""), RequestBody.create(null, StringUtils.avoidNull(struct.title))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"content\""), RequestBody.create(null, StringUtils.avoidNull(struct.content))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"resto\""), RequestBody.create(null, StringUtils.avoidNull(struct.resto))); if (struct.water) { builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"water\""), RequestBody.create(null, "true")); }/*from www . jav a2 s . c o m*/ InputStreamPipe isPipe = struct.image; if (isPipe != null) { String filename; MediaType mediaType; byte[] bytes; File file = compressBitmap(isPipe, struct.imageType); if (file == null) { String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(struct.imageType); if (TextUtils.isEmpty(extension)) { extension = "jpg"; } filename = "a." + extension; mediaType = MediaType.parse(struct.imageType); if (mediaType == null) { mediaType = MEDIA_TYPE_IMAGE_ALL; } try { isPipe.obtain(); bytes = IOUtils.getAllByte(isPipe.open()); } finally { isPipe.close(); isPipe.release(); } } else { filename = "a.jpg"; mediaType = MEDIA_TYPE_IMAGE_JPEG; InputStream is = null; try { is = new FileInputStream(file); bytes = IOUtils.getAllByte(is); } finally { IOUtils.closeQuietly(is); file.delete(); } } builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"image\"; filename=\"" + filename + "\""), RequestBody.create(mediaType, bytes)); } String url = ACUrl.API_REPLY; Log.d(TAG, url); Request request = new GoodRequestBuilder(url).post(builder.build()).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareGetFeed(OkHttpClient okHttpClient, String uuid, int page) { String url = ACUrl.getFeedUrl(uuid, page); Log.d(TAG, url);//from www. j a va 2 s . c o m Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareAddFeed(OkHttpClient okHttpClient, String uuid, String tid) { String url = ACUrl.getAddFeedUrl(uuid, tid); Log.d(TAG, url);//from ww w. java 2 s .c o m Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareDelFeed(OkHttpClient okHttpClient, String uuid, String tid) { String url = ACUrl.getDelFeedUrl(uuid, tid); Log.d(TAG, url);//from ww w.j a va 2s. c om Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareCreatePost(OkHttpClient okHttpClient, ACPostStruct struct) throws Exception { MultipartBuilder builder = new MultipartBuilder(); builder.type(MultipartBuilder.FORM); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"name\""), RequestBody.create(null, StringUtils.avoidNull(struct.name))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"email\""), RequestBody.create(null, StringUtils.avoidNull(struct.email))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"title\""), RequestBody.create(null, StringUtils.avoidNull(struct.title))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"content\""), RequestBody.create(null, StringUtils.avoidNull(struct.content))); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fid\""), RequestBody.create(null, StringUtils.avoidNull(struct.fid))); if (struct.water) { builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"water\""), RequestBody.create(null, "true")); }// ww w .j a v a 2s.c o m InputStreamPipe isPipe = struct.image; if (isPipe != null) { String filename; MediaType mediaType; byte[] bytes; File file = compressBitmap(isPipe, struct.imageType); if (file == null) { String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(struct.imageType); if (TextUtils.isEmpty(extension)) { extension = "jpg"; } filename = "a." + extension; mediaType = MediaType.parse(struct.imageType); if (mediaType == null) { mediaType = MEDIA_TYPE_IMAGE_ALL; } try { isPipe.obtain(); bytes = IOUtils.getAllByte(isPipe.open()); } finally { isPipe.close(); isPipe.release(); } } else { filename = "a.jpg"; mediaType = MEDIA_TYPE_IMAGE_JPEG; InputStream is = null; try { is = new FileInputStream(file); bytes = IOUtils.getAllByte(is); } finally { IOUtils.closeQuietly(is); file.delete(); } } builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"image\"; filename=\"" + filename + "\""), RequestBody.create(mediaType, bytes)); } String url = ACUrl.API_CREATE_POST; Log.d(TAG, url); Request request = new GoodRequestBuilder(url).post(builder.build()).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ac.ACEngine.java
License:Apache License
public static Call prepareSearch(OkHttpClient okHttpClient, String keyword, int page) throws UnsupportedEncodingException { String url = ACUrl.getSearchUrl(keyword, page); Log.d(TAG, url);//from w ww . java2 s . c o m Request request = new GoodRequestBuilder(url).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.ConvertEngine.java
License:Apache License
public static Call prepareConvert(OkHttpClient okHttpClient, String config, String content) { RequestBody formBody = new FormEncodingBuilder().add("config", config).add("content", content).build(); String url = URL;// w ww .jav a 2s .c o m Log.d(TAG, url); Request request = new GoodRequestBuilder(url).post(formBody).build(); return okHttpClient.newCall(request); }