mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Move new Http query together with other ApacheHttpRequests
This commit is contained in:
		
							parent
							
								
									3b17d96bae
								
							
						
					
					
						commit
						6412e15f20
					
				
					 4 changed files with 29 additions and 31 deletions
				
			
		|  | @ -17,6 +17,7 @@ import org.apache.http.impl.client.DefaultHttpClient; | |||
| import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; | ||||
| import org.apache.http.params.BasicHttpParams; | ||||
| import org.apache.http.params.CoreProtocolPNames; | ||||
| import org.apache.http.util.EntityUtils; | ||||
| import org.mediawiki.api.ApiResult; | ||||
| import org.mediawiki.api.MWApi; | ||||
| 
 | ||||
|  | @ -27,10 +28,13 @@ import java.util.ArrayList; | |||
| import java.util.Collections; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| import fr.free.nrw.commons.BuildConfig; | ||||
| import fr.free.nrw.commons.PageTitle; | ||||
| import fr.free.nrw.commons.Utils; | ||||
| import in.yuvi.http.fluent.Http; | ||||
| import io.reactivex.Single; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| /** | ||||
|  | @ -366,4 +370,22 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { | |||
|             return new UploadResult(resultStatus, dateUploaded, canonicalFilename, imageUrl); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     @NonNull | ||||
|     public Single<Integer> getUploadCount(String userName) { | ||||
|         final String UPLOAD_COUNT_URL_TEMPLATE = | ||||
|                 "https://tools.wmflabs.org/urbanecmbot/uploadsbyuser/uploadsbyuser.py?user=%s"; | ||||
| 
 | ||||
|         return Single.fromCallable(() -> { | ||||
|             String url = String.format( | ||||
|                     Locale.ENGLISH, | ||||
|                     UPLOAD_COUNT_URL_TEMPLATE, | ||||
|                     new PageTitle(userName).getText()); | ||||
|             HttpResponse response = Http.get(url).use(httpClient).asResponse(); | ||||
|             String uploadCount = EntityUtils.toString(response.getEntity()).trim(); | ||||
|             return Integer.parseInt(uploadCount); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -7,6 +7,8 @@ import java.io.IOException; | |||
| import java.io.InputStream; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import io.reactivex.Single; | ||||
| 
 | ||||
| public interface MediaWikiApi { | ||||
|     String getAuthCookie(); | ||||
| 
 | ||||
|  | @ -52,6 +54,9 @@ public interface MediaWikiApi { | |||
|     @NonNull | ||||
|     LogEventResult logEvents(String user, String lastModified, String queryContinue, int limit) throws IOException; | ||||
| 
 | ||||
|     @NonNull | ||||
|     Single<Integer> getUploadCount(String userName); | ||||
| 
 | ||||
|     interface ProgressListener { | ||||
|         void onProgress(long transferred, long total); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mikel
						Mikel