├── .gitignore ├── .travis.yml ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── com │ └── github │ └── cellularprivacy │ └── ocidrestclient │ ├── OcidConverterFactory.java │ ├── OcidRestClient.java │ ├── client │ ├── CellClient.java │ ├── Client.java │ └── MeasureClient.java │ ├── dto │ ├── BoundingBox.java │ ├── CellInAreaInfo.java │ ├── CellInfo.java │ ├── Count.java │ ├── Measurement.java │ ├── MeasurementInfo.java │ ├── MeasurementList.java │ └── Status.java │ └── service │ ├── CellService.java │ ├── MeasureService.java │ └── OcidService.java └── test └── java └── com └── github └── cellularprivacy └── ocidrestclient ├── MeasureServiceTest.java ├── client └── MeasureClientTest.java └── service └── OcidServiceTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | ### Gradle ### 4 | .gradle 5 | build/ 6 | 7 | # Ignore Gradle GUI config 8 | gradle-app.setting 9 | 10 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 11 | !gradle-wrapper.jar 12 | 13 | # Cache of project 14 | .gradletasknamecache 15 | 16 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 17 | # gradle/wrapper/gradle-wrapper.properties 18 | 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk7 4 | - oraclejdk8 5 | - openjdk7 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCID REST Client 2 | [![Build Status](https://travis-ci.org/CellularPrivacy/ocid-rest-client.svg?branch=master)](https://travis-ci.org/CellularPrivacy/ocid-rest-client) 3 | [![](https://jitpack.io/v/CellularPrivacy/ocid-rest-client.svg)](https://jitpack.io/#CellularPrivacy/ocid-rest-client) 4 | 5 | Java client library for the OpenCellID API 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | maven { url "https://jitpack.io" } 5 | } 6 | dependencies { 7 | classpath 'io.freefair.gradle-plugins:git-version:2.0.0-beta5' 8 | } 9 | } 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | group = "com.github.cellularprivacy" 16 | 17 | apply plugin: 'io.freefair.git-version' 18 | apply plugin: 'java' 19 | apply plugin: 'maven' 20 | 21 | sourceCompatibility = JavaVersion.VERSION_1_7 22 | 23 | dependencies { 24 | compile 'com.squareup.retrofit2:retrofit:2.0.2' 25 | compile 'com.squareup.retrofit2:converter-gson:2.0.2' 26 | 27 | testCompile 'junit:junit:4.12' 28 | testCompile 'com.squareup.okhttp3:logging-interceptor:3.+' 29 | } 30 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CellularPrivacy/ocid-rest-client/8d3d13c017d01a6a098c8e91c86af0668d810dd3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 19 11:29:14 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was auto generated by the Gradle buildInit task 3 | * by 'larsgrefer' at '19.04.16 11:29' with Gradle 2.12 4 | * 5 | * The settings file is used to specify which projects to include in your build. 6 | * In a single project build this file can be empty or even removed. 7 | * 8 | * Detailed information about configuring a multi-project build in Gradle can be found 9 | * in the user guide at https://docs.gradle.org/2.12/userguide/multi_project_builds.html 10 | */ 11 | 12 | /* 13 | // To declare projects as part of a multi-project build use the 'include' method 14 | include 'shared' 15 | include 'api' 16 | include 'services:webservice' 17 | */ 18 | 19 | rootProject.name = 'ocid-rest-client' 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/OcidConverterFactory.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.dto.BoundingBox; 4 | import okhttp3.ResponseBody; 5 | import retrofit2.Converter; 6 | import retrofit2.Retrofit; 7 | 8 | import java.io.IOException; 9 | import java.lang.annotation.Annotation; 10 | import java.lang.reflect.Type; 11 | 12 | /** 13 | * Special {@link retrofit2.Converter.Factory} for the ocid api 14 | */ 15 | public class OcidConverterFactory extends Converter.Factory { 16 | 17 | @Override 18 | public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 19 | if (String.class.equals(type)) { 20 | return new ResponseBodyStringConverter(); 21 | } 22 | 23 | return super.responseBodyConverter(type, annotations, retrofit); 24 | } 25 | 26 | @Override 27 | public Converter stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 28 | if (BoundingBox.class.equals(type)) 29 | return new BoundingBoxStringConverter(); 30 | 31 | return super.stringConverter(type, annotations, retrofit); 32 | } 33 | 34 | private static class ResponseBodyStringConverter implements Converter { 35 | @Override 36 | public String convert(ResponseBody value) throws IOException { 37 | return value.string(); 38 | } 39 | } 40 | 41 | private class BoundingBoxStringConverter implements Converter { 42 | 43 | @Override 44 | public String convert(BoundingBox value) throws IOException { 45 | return value.toString(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/OcidRestClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.client.CellClient; 4 | import com.github.cellularprivacy.ocidrestclient.client.MeasureClient; 5 | import com.github.cellularprivacy.ocidrestclient.service.CellService; 6 | import com.github.cellularprivacy.ocidrestclient.service.MeasureService; 7 | import com.github.cellularprivacy.ocidrestclient.service.OcidService; 8 | import okhttp3.OkHttpClient; 9 | import retrofit2.Retrofit; 10 | import retrofit2.converter.gson.GsonConverterFactory; 11 | 12 | import java.lang.ref.WeakReference; 13 | 14 | public class OcidRestClient { 15 | 16 | private final String apiKey; 17 | private final Retrofit retrofit; 18 | 19 | public OcidRestClient(String apiKey) { 20 | this(new Retrofit.Builder(), apiKey); 21 | } 22 | 23 | public OcidRestClient(OkHttpClient okHttpClient, String apiKey) { 24 | this(new Retrofit.Builder().client(okHttpClient), apiKey); 25 | } 26 | 27 | public OcidRestClient(Retrofit.Builder builder, String apiKey) { 28 | retrofit = builder.baseUrl("http://www.opencellid.org/") 29 | .addConverterFactory(new OcidConverterFactory()) 30 | .addConverterFactory(GsonConverterFactory.create()) 31 | .build(); 32 | this.apiKey = apiKey; 33 | } 34 | 35 | public String getApiKey() { 36 | return apiKey; 37 | } 38 | 39 | WeakReference cellClient; 40 | 41 | public CellClient getCellClient() { 42 | if (cellClient == null || cellClient.get() == null) { 43 | cellClient = new WeakReference<>(new CellClient(this, retrofit.create(CellService.class))); 44 | } 45 | 46 | return cellClient.get(); 47 | } 48 | 49 | WeakReference measureClient; 50 | 51 | public MeasureClient getMeasureClient() { 52 | if (measureClient == null || measureClient.get() == null) { 53 | measureClient = new WeakReference<>(new MeasureClient(this, retrofit.create(MeasureService.class))); 54 | } 55 | 56 | return measureClient.get(); 57 | } 58 | 59 | public OcidService getOcidService() { 60 | return retrofit.create(OcidService.class); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/client/CellClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.client; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.OcidRestClient; 4 | import com.github.cellularprivacy.ocidrestclient.dto.*; 5 | import com.github.cellularprivacy.ocidrestclient.service.CellService; 6 | import retrofit2.Call; 7 | 8 | public class CellClient extends Client { 9 | 10 | public CellClient(OcidRestClient ocidRestClient, CellService service) { 11 | super(ocidRestClient, service); 12 | } 13 | 14 | public Call get( 15 | int mobileCountryCode, 16 | int mobileNetworkCode, 17 | int locationAreaCode, 18 | int cellId, 19 | String radio 20 | ) { 21 | return service.get(ocidRestClient.getApiKey(), mobileCountryCode, mobileNetworkCode, locationAreaCode, cellId, radio); 22 | } 23 | 24 | public Call getMeasuresSize( 25 | int mobileCountryCode, 26 | int mobileNetworkCode, 27 | int locationAreaCode, 28 | int cellId, 29 | String radio 30 | ) { 31 | return service.getMeasuresSize(ocidRestClient.getApiKey(), mobileCountryCode, mobileNetworkCode, locationAreaCode, cellId, radio); 32 | } 33 | 34 | public Call getMeasures( 35 | int mobileCountryCode, 36 | int mobileNetworkCode, 37 | int locationAreaCode, 38 | int cellId, 39 | String radio 40 | ) { 41 | return getMeasures(mobileCountryCode, mobileNetworkCode, locationAreaCode, cellId, radio, null, null); 42 | } 43 | 44 | public Call getMeasures( 45 | int mobileCountryCode, 46 | int mobileNetworkCode, 47 | int locationAreaCode, 48 | int cellId, 49 | String radio, 50 | Integer limit, 51 | Integer offset 52 | ) { 53 | return service.getMeasures(ocidRestClient.getApiKey(), mobileCountryCode, mobileNetworkCode, locationAreaCode, cellId, radio, limit, offset); 54 | } 55 | 56 | public Call getInAreaSize( 57 | BoundingBox boundingBox, 58 | Integer mobileCountryCode, 59 | Integer mobileNetworkCode, 60 | Integer locationAreaCode, 61 | String radio 62 | ) { 63 | return service.getInAreaSize(ocidRestClient.getApiKey(), boundingBox, mobileCountryCode, mobileNetworkCode, locationAreaCode, radio); 64 | } 65 | 66 | public Call getInArea( 67 | BoundingBox boundingBox, 68 | Integer mobileCountryCode, 69 | Integer mobileNetworkCode, 70 | Integer locationAreaCode, 71 | String radio 72 | ) { 73 | return getInArea(boundingBox, mobileCountryCode, mobileNetworkCode, locationAreaCode, radio, null, null); 74 | } 75 | 76 | public Call getInArea( 77 | BoundingBox boundingBox, 78 | Integer mobileCountryCode, 79 | Integer mobileNetworkCode, 80 | Integer locationAreaCode, 81 | String radio, 82 | Integer limit, 83 | Integer offset 84 | ) { 85 | return service.getInArea(ocidRestClient.getApiKey(), boundingBox, mobileCountryCode, mobileNetworkCode, locationAreaCode, radio, limit, offset); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/client/Client.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.client; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.OcidRestClient; 4 | 5 | abstract class Client { 6 | protected OcidRestClient ocidRestClient; 7 | protected S service; 8 | 9 | public Client(OcidRestClient ocidRestClient, S service) { 10 | this.ocidRestClient = ocidRestClient; 11 | this.service = service; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/client/MeasureClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.client; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.OcidRestClient; 4 | import com.github.cellularprivacy.ocidrestclient.dto.Count; 5 | import com.github.cellularprivacy.ocidrestclient.dto.MeasurementList; 6 | import com.github.cellularprivacy.ocidrestclient.dto.Status; 7 | import com.github.cellularprivacy.ocidrestclient.service.MeasureService; 8 | import okhttp3.MediaType; 9 | import okhttp3.MultipartBody; 10 | import okhttp3.RequestBody; 11 | import retrofit2.Call; 12 | 13 | import java.io.File; 14 | import java.util.Date; 15 | 16 | public class MeasureClient extends Client { 17 | 18 | public MeasureClient(OcidRestClient ocidRestClient, MeasureService service) { 19 | super(ocidRestClient, service); 20 | } 21 | 22 | public Call uploadCsv(String csv) { 23 | return service.uploadCsv( 24 | ocidRestClient.getApiKey(), 25 | MultipartBody.Part.createFormData( 26 | "datafile", 27 | "data.csv", 28 | RequestBody.create( 29 | MediaType.parse("text/csv"), 30 | csv 31 | ) 32 | ) 33 | ); 34 | } 35 | 36 | public Call uploadCsv(File csvFile) { 37 | return service.uploadCsv( 38 | ocidRestClient.getApiKey(), 39 | MultipartBody.Part.createFormData( 40 | "datafile", 41 | csvFile.getName(), 42 | RequestBody.create( 43 | MediaType.parse("text/csv"), 44 | csvFile 45 | ) 46 | ) 47 | ); 48 | } 49 | 50 | public Call uploadJson(String json) { 51 | return service.uploadJson( 52 | ocidRestClient.getApiKey(), 53 | MultipartBody.Part.createFormData( 54 | "datafile", 55 | "data.json", 56 | RequestBody.create( 57 | MediaType.parse("application/json"), 58 | json 59 | ) 60 | ) 61 | ); 62 | } 63 | 64 | public Call uploadJson(File jsonFile) { 65 | return service.uploadJson( 66 | ocidRestClient.getApiKey(), 67 | MultipartBody.Part.createFormData( 68 | "datafile", 69 | jsonFile.getName(), 70 | RequestBody.create( 71 | MediaType.parse("application/json"), 72 | jsonFile 73 | ) 74 | ) 75 | ); 76 | } 77 | 78 | public Call listSize() { 79 | return service.listSize(ocidRestClient.getApiKey()); 80 | } 81 | 82 | public Call list() { 83 | return list(null, null); 84 | } 85 | 86 | public Call list(Integer limit, Integer offset) { 87 | return service.list(ocidRestClient.getApiKey(), limit, offset); 88 | } 89 | 90 | public Call delete(String measureId) { 91 | return service.delete(ocidRestClient.getApiKey(), measureId); 92 | } 93 | 94 | public Call add( 95 | double latitude, 96 | double longitude, 97 | Integer mobileCountryCode, 98 | Integer mobileNetworkCode, 99 | Integer locationAreaCode, 100 | Integer cellId, 101 | Integer signal, 102 | Date measured_at, 103 | Double rating, 104 | Double speed, 105 | Double direction, 106 | String act, 107 | Integer ta, 108 | Integer psc, 109 | Integer tac, 110 | Integer pci, 111 | Integer sid, 112 | Integer nid, 113 | Integer bid, 114 | String devn, 115 | Integer txp, 116 | Integer tsrf 117 | ) { 118 | return service.add(ocidRestClient.getApiKey(), latitude, longitude, mobileCountryCode, mobileNetworkCode, locationAreaCode, cellId, signal, measured_at, rating, speed, direction, act, ta, psc, tac, pci, sid, nid, bid, devn, txp, tsrf); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/BoundingBox.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | /** 4 | * ,,, 5 | * 6 | * @see http://wiki.opencellid.org/wiki/API#Getting_the_list_of_cells_in_a_specified_area 7 | */ 8 | public class BoundingBox { 9 | 10 | /** 11 | * Minimal bounding latitude 12 | */ 13 | private double latmin; 14 | 15 | /** 16 | * Minimal bounding longitude 17 | */ 18 | private double lonmin; 19 | 20 | /** 21 | * Maximal bounding latitude 22 | */ 23 | private double latmax; 24 | 25 | /** 26 | * Maximal bounding longitude 27 | */ 28 | private double lonmax; 29 | 30 | /** 31 | * @param latmin Minimal bounding latitude 32 | * @param lonmin Minimal bounding longitude 33 | * @param latmax Maximal bounding latitude 34 | * @param lonmax Maximal bounding longitude 35 | */ 36 | public BoundingBox(double latmin, double lonmin, double latmax, double lonmax) { 37 | this.latmin = latmin; 38 | this.lonmin = lonmin; 39 | this.latmax = latmax; 40 | this.lonmax = lonmax; 41 | } 42 | 43 | public double getLatmin() { 44 | return latmin; 45 | } 46 | 47 | public void setLatmin(double latmin) { 48 | this.latmin = latmin; 49 | } 50 | 51 | public double getLonmin() { 52 | return lonmin; 53 | } 54 | 55 | public void setLonmin(double lonmin) { 56 | this.lonmin = lonmin; 57 | } 58 | 59 | public double getLatmax() { 60 | return latmax; 61 | } 62 | 63 | public void setLatmax(double latmax) { 64 | this.latmax = latmax; 65 | } 66 | 67 | public double getLonmax() { 68 | return lonmax; 69 | } 70 | 71 | public void setLonmax(double lonmax) { 72 | this.lonmax = lonmax; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return String.format("%f,%f,%f,%f", latmin, lonmin, latmax, lonmax); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/CellInAreaInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | import java.util.List; 4 | 5 | public class CellInAreaInfo extends Count { 6 | private List cells; 7 | 8 | public List getCells() { 9 | return cells; 10 | } 11 | 12 | public void setCells(List cells) { 13 | this.cells = cells; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/CellInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | public class CellInfo { 4 | 5 | private double lon, lat; 6 | private int averageSignalStrength, range, samples; 7 | private boolean changeable; 8 | private String radio; 9 | private int mcc, mnc, lac, cellid; 10 | private int rnc,cid,tac,sid,nid,bid; 11 | 12 | public double getLon() { 13 | return lon; 14 | } 15 | 16 | public void setLon(double lon) { 17 | this.lon = lon; 18 | } 19 | 20 | public double getLat() { 21 | return lat; 22 | } 23 | 24 | public void setLat(double lat) { 25 | this.lat = lat; 26 | } 27 | 28 | public int getAverageSignalStrength() { 29 | return averageSignalStrength; 30 | } 31 | 32 | public void setAverageSignalStrength(int averageSignalStrength) { 33 | this.averageSignalStrength = averageSignalStrength; 34 | } 35 | 36 | public int getRange() { 37 | return range; 38 | } 39 | 40 | public void setRange(int range) { 41 | this.range = range; 42 | } 43 | 44 | public int getSamples() { 45 | return samples; 46 | } 47 | 48 | public void setSamples(int samples) { 49 | this.samples = samples; 50 | } 51 | 52 | public boolean isChangeable() { 53 | return changeable; 54 | } 55 | 56 | public void setChangeable(boolean changeable) { 57 | this.changeable = changeable; 58 | } 59 | 60 | public String getRadio() { 61 | return radio; 62 | } 63 | 64 | public void setRadio(String radio) { 65 | this.radio = radio; 66 | } 67 | 68 | public int getMcc() { 69 | return mcc; 70 | } 71 | 72 | public void setMcc(int mcc) { 73 | this.mcc = mcc; 74 | } 75 | 76 | public int getMnc() { 77 | return mnc; 78 | } 79 | 80 | public void setMnc(int mnc) { 81 | this.mnc = mnc; 82 | } 83 | 84 | public int getLac() { 85 | return lac; 86 | } 87 | 88 | public void setLac(int lac) { 89 | this.lac = lac; 90 | } 91 | 92 | public int getCellid() { 93 | return cellid; 94 | } 95 | 96 | public void setCellid(int cellid) { 97 | this.cellid = cellid; 98 | } 99 | 100 | public int getSid() { 101 | return sid; 102 | } 103 | 104 | public void setSid(int sid) { 105 | this.sid = sid; 106 | } 107 | 108 | public int getNid() { 109 | return nid; 110 | } 111 | 112 | public void setNid(int nid) { 113 | this.nid = nid; 114 | } 115 | 116 | public int getBid() { 117 | return bid; 118 | } 119 | 120 | public void setBid(int bid) { 121 | this.bid = bid; 122 | } 123 | 124 | public int getRnc() { 125 | return rnc; 126 | } 127 | 128 | public void setRnc(int rnc) { 129 | this.rnc = rnc; 130 | } 131 | 132 | public int getCid() { 133 | return cid; 134 | } 135 | 136 | public void setCid(int cid) { 137 | this.cid = cid; 138 | } 139 | 140 | public int getTac() { 141 | return tac; 142 | } 143 | 144 | public void setTac(int tac) { 145 | this.tac = tac; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/Count.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | public class Count { 4 | private int count; 5 | 6 | public int getCount() { 7 | return count; 8 | } 9 | 10 | public void setCount(int count) { 11 | this.count = count; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/Measurement.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | import java.util.Date; 4 | 5 | public class Measurement { 6 | 7 | private String id; 8 | private double lon, lat; 9 | private int mcc, mnc, lac, cellid; 10 | private Date created_at, measured_at; 11 | private int signal; 12 | private double rating, speed, direction; 13 | private String radio; 14 | private int ta,rnc,cid,psc,tac,pci,sid,nid,bid; 15 | 16 | public String getId() { 17 | return id; 18 | } 19 | 20 | public void setId(String id) { 21 | this.id = id; 22 | } 23 | 24 | public double getLon() { 25 | return lon; 26 | } 27 | 28 | public void setLon(double lon) { 29 | this.lon = lon; 30 | } 31 | 32 | public double getLat() { 33 | return lat; 34 | } 35 | 36 | public void setLat(double lat) { 37 | this.lat = lat; 38 | } 39 | 40 | public int getMcc() { 41 | return mcc; 42 | } 43 | 44 | public void setMcc(int mcc) { 45 | this.mcc = mcc; 46 | } 47 | 48 | public int getMnc() { 49 | return mnc; 50 | } 51 | 52 | public void setMnc(int mnc) { 53 | this.mnc = mnc; 54 | } 55 | 56 | public int getLac() { 57 | return lac; 58 | } 59 | 60 | public void setLac(int lac) { 61 | this.lac = lac; 62 | } 63 | 64 | public int getCellid() { 65 | return cellid; 66 | } 67 | 68 | public void setCellid(int cellid) { 69 | this.cellid = cellid; 70 | } 71 | 72 | public Date getCreated_at() { 73 | return created_at; 74 | } 75 | 76 | public void setCreated_at(Date created_at) { 77 | this.created_at = created_at; 78 | } 79 | 80 | public Date getMeasured_at() { 81 | return measured_at; 82 | } 83 | 84 | public void setMeasured_at(Date measured_at) { 85 | this.measured_at = measured_at; 86 | } 87 | 88 | public int getSignal() { 89 | return signal; 90 | } 91 | 92 | public void setSignal(int signal) { 93 | this.signal = signal; 94 | } 95 | 96 | public double getRating() { 97 | return rating; 98 | } 99 | 100 | public void setRating(double rating) { 101 | this.rating = rating; 102 | } 103 | 104 | public double getSpeed() { 105 | return speed; 106 | } 107 | 108 | public void setSpeed(double speed) { 109 | this.speed = speed; 110 | } 111 | 112 | public double getDirection() { 113 | return direction; 114 | } 115 | 116 | public void setDirection(double direction) { 117 | this.direction = direction; 118 | } 119 | 120 | public String getRadio() { 121 | return radio; 122 | } 123 | 124 | public void setRadio(String radio) { 125 | this.radio = radio; 126 | } 127 | 128 | public int getTa() { 129 | return ta; 130 | } 131 | 132 | public void setTa(int ta) { 133 | this.ta = ta; 134 | } 135 | 136 | public int getRnc() { 137 | return rnc; 138 | } 139 | 140 | public void setRnc(int rnc) { 141 | this.rnc = rnc; 142 | } 143 | 144 | public int getCid() { 145 | return cid; 146 | } 147 | 148 | public void setCid(int cid) { 149 | this.cid = cid; 150 | } 151 | 152 | public int getPsc() { 153 | return psc; 154 | } 155 | 156 | public void setPsc(int psc) { 157 | this.psc = psc; 158 | } 159 | 160 | public int getTac() { 161 | return tac; 162 | } 163 | 164 | public void setTac(int tac) { 165 | this.tac = tac; 166 | } 167 | 168 | public int getPci() { 169 | return pci; 170 | } 171 | 172 | public void setPci(int pci) { 173 | this.pci = pci; 174 | } 175 | 176 | public int getSid() { 177 | return sid; 178 | } 179 | 180 | public void setSid(int sid) { 181 | this.sid = sid; 182 | } 183 | 184 | public int getNid() { 185 | return nid; 186 | } 187 | 188 | public void setNid(int nid) { 189 | this.nid = nid; 190 | } 191 | 192 | public int getBid() { 193 | return bid; 194 | } 195 | 196 | public void setBid(int bid) { 197 | this.bid = bid; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/MeasurementInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | import java.util.List; 4 | 5 | public class MeasurementInfo extends CellInfo { 6 | 7 | private List measurements; 8 | 9 | public List getMeasurements() { 10 | return measurements; 11 | } 12 | 13 | public void setMeasurements(List measurements) { 14 | this.measurements = measurements; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/MeasurementList.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | import java.util.List; 4 | 5 | public class MeasurementList extends Count { 6 | 7 | private List measurements; 8 | 9 | public List getMeasurements() { 10 | return measurements; 11 | } 12 | 13 | public void setMeasurements(List measurements) { 14 | this.measurements = measurements; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/dto/Status.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.dto; 2 | 3 | public class Status { 4 | 5 | private int code; 6 | private String status; 7 | 8 | public int getCode() { 9 | return code; 10 | } 11 | 12 | public void setCode(int code) { 13 | this.code = code; 14 | } 15 | 16 | public String getStatus() { 17 | return status; 18 | } 19 | 20 | public void setStatus(String status) { 21 | this.status = status; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/service/CellService.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.service; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.dto.*; 4 | import retrofit2.Call; 5 | import retrofit2.http.*; 6 | 7 | public interface CellService { 8 | 9 | /** 10 | * @param apiKey API key assigned to the user 11 | * @param mobileCountryCode Mobile country code 12 | * @param mobileNetworkCode Mobile network code or system identifier 13 | * @param locationAreaCode Local area code, tracking area code or network id 14 | * @param cellId Cell id or base station id 15 | * @param radio You can specifiy GSM, UMTS, LTE or CDMA as the radio of returned cell. Otherwise first matched cell will be returned. 16 | * @return 17 | */ 18 | @POST("cell/get?format=json") 19 | @FormUrlEncoded 20 | Call get( 21 | @Field("key") String apiKey, 22 | @Field("mcc") int mobileCountryCode, 23 | @Field("mnc") int mobileNetworkCode, 24 | @Field("lac") int locationAreaCode, 25 | @Field("cellid") int cellId, 26 | @Field("radio") String radio 27 | ); 28 | 29 | @POST("cell/getMeasures?format=json") 30 | @FormUrlEncoded 31 | Call getMeasures( 32 | @Field("key") String apiKey, 33 | @Field("mcc") int mobileCountryCode, 34 | @Field("mnc") int mobileNetworkCode, 35 | @Field("lac") int locationAreaCode, 36 | @Field("cellid") int cellId, 37 | @Field("radio") String radio, 38 | @Field("limit") Integer limit, 39 | @Field("offset") Integer offset 40 | ); 41 | 42 | /** 43 | * Getting the number of all measures used to compute the position of a cell 44 | * 45 | * @param apiKey API key assigned to the user 46 | * @param mobileCountryCode Mobile country code 47 | * @param mobileNetworkCode Mobile network code or system identifier 48 | * @param locationAreaCode Local area code, tracking area code or network id 49 | * @param cellId Cell id or base station id 50 | * @param radio You can specifiy GSM, UMTS, LTE or CDMA as the radio of returned data. Otherwise first matched cell will be returned with its measurements. 51 | * @return Upon successful request, HTTP 200 is returned 52 | */ 53 | @POST("cell/getMeasuresSize?format=json") 54 | @FormUrlEncoded 55 | Call getMeasuresSize( 56 | @Field("key") String apiKey, 57 | @Field("mcc") int mobileCountryCode, 58 | @Field("mnc") int mobileNetworkCode, 59 | @Field("lac") int locationAreaCode, 60 | @Field("cellid") int cellId, 61 | @Field("radio") String radio 62 | ); 63 | 64 | /** 65 | * Getting the list of cells in a specified area 66 | * 67 | * @param apiKey API key assigned to the user 68 | * @param boundingBox 69 | * @param mobileCountryCode Mobile country code; If you want to restrict the result to a specific country 70 | * @param mobileNetworkCode Mobile network code or system identifier; If you want to restrict the result 71 | * @param locationAreaCode Local area code, tracking area code or network id; If you want to restrict the result 72 | * @param radio You can specifiy GSM, UMTS, LTE or CDMA as the radio of returned cells. Otherwise cells with any radios will be returned. 73 | * @param limit A number defining maximum size of the returned list. Default and maximum value is 1000. 74 | * @param offset The field says to skip that many cells before beginning to return cells. Default is 0. 75 | * @return Upon successful request, HTTP 200 is returned 76 | */ 77 | @GET("cell/getInArea?format=json") 78 | Call getInArea( 79 | @Query("key") String apiKey, 80 | @Query("BBOX") BoundingBox boundingBox, 81 | @Query("mcc") Integer mobileCountryCode, 82 | @Query("mnc") Integer mobileNetworkCode, 83 | @Query("lac") Integer locationAreaCode, 84 | @Query("radio") String radio, 85 | @Query("limit") Integer limit, 86 | @Query("offset") Integer offset 87 | ); 88 | 89 | /** 90 | * 91 | * @param apiKey API key assigned to the user 92 | * @param boundingBox 93 | * @param mobileCountryCode Mobile country code; If you want to restrict the result to a specific country 94 | * @param mobileNetworkCode Mobile network code or system identifier; If you want to restrict the result 95 | * @param locationAreaCode Local area code, tracking area code or network id; If you want to restrict the result 96 | * @param radio You can specifiy GSM, UMTS, LTE or CDMA as the radio of returned data. Otherwise any cells will be returned. 97 | * @return Upon successful request, HTTP 200 is returned 98 | */ 99 | @GET("cell/getInAreaSize?format=json") 100 | Call getInAreaSize( 101 | @Query("key") String apiKey, 102 | @Query("BBOX") BoundingBox boundingBox, 103 | @Query("mcc") Integer mobileCountryCode, 104 | @Query("mnc") Integer mobileNetworkCode, 105 | @Query("lac") Integer locationAreaCode, 106 | @Query("radio") String radio 107 | ); 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/service/MeasureService.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.service; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.dto.Count; 4 | import com.github.cellularprivacy.ocidrestclient.dto.MeasurementList; 5 | import com.github.cellularprivacy.ocidrestclient.dto.Status; 6 | import okhttp3.MultipartBody; 7 | import retrofit2.Call; 8 | import retrofit2.http.*; 9 | 10 | import java.util.Date; 11 | 12 | public interface MeasureService { 13 | 14 | /** 15 | * @param apiKey API key assigned to the user submitting the measurement 16 | * @param latitude Latitude 17 | * @param longitude Longitude 18 | * @param mobileCountryCode Mobile country code 19 | * @param mobileNetworkCode Mobile network code or system identifier 20 | * @param locationAreaCode Local area code, tracking area code or network id 21 | * @param cellId Cell tower id or base station id 22 | * @param signal Signal level: either in dBm or as defined in TS 27.007 8.5; both is accepted. 23 | * @param measured_at When the measurement was measured. 24 | * @param rating GPS quality/accuracy information (metres) 25 | * @param speed Speed when creating the measurement, in metres/second 26 | * @param direction Heading direction when creating the measurement (0=north, 90=east) 27 | * @param act Network access type; currently supported: 1xRTT, CDMA, eHRPD, IS95A, IS95B, EVDO_0, EVDO_A, EVDO_B, UMTS, HSPA+, HSDPA, HSUPA, HSPA, LTE, EDGE, GPRS, GSM 28 | * @param ta Timing advance; only for GSM and LTE 29 | * @param psc Primary scrambling code; only for UMTS 30 | * @param tac Tracking area code; only for LTE 31 | * @param pci Physical cell Id; only for LTE 32 | * @param sid System identifier; only for CDMA 33 | * @param nid Network id; only for CDMA 34 | * @param bid Base station id; only for CDMA 35 | * @param devn Device name as concatenated strings with the manufacturer and the model name; max 50 characters 36 | * @param txp TX power in dBm 37 | * @param tsrf Temperature in the RF module; in degrees Celsius; only with parameter 38 | * @return Upon successful insert, HTTP 200 is returned with the string "Your measurement has been inserted." 39 | */ 40 | @POST("measure/add") 41 | Call add( 42 | @Field("key") String apiKey, 43 | @Field("lat") double latitude, 44 | @Field("lon") double longitude, 45 | @Field("mcc") Integer mobileCountryCode, 46 | @Field("mnc") Integer mobileNetworkCode, 47 | @Field("lac") Integer locationAreaCode, 48 | @Field("cellid") Integer cellId, 49 | @Field("signal") Integer signal, 50 | @Field("measured_at") Date measured_at, 51 | @Field("rating") Double rating, 52 | @Field("speed") Double speed, 53 | @Field("direction") Double direction, 54 | @Field("act") String act, 55 | @Field("ta") Integer ta, 56 | @Field("psc") Integer psc, 57 | @Field("tac") Integer tac, 58 | @Field("pci") Integer pci, 59 | @Field("sid") Integer sid, 60 | @Field("nid") Integer nid, 61 | @Field("bid") Integer bid, 62 | @Field("devn") String devn, 63 | @Field("txp") Integer txp, 64 | @Field("tsrf") Integer tsrf 65 | ); 66 | 67 | /** 68 | * Column names recognised: 69 | * mcc, mnc, lac, cellid, lat, lon, signal, measured_at, rating, speed, direction, act, ta, psc, tac, pci, sid, nid, bid 70 | *

71 | * Maximum file size: 72 | * 2 MB; upload multiple files if you want to upload more data. 73 | * 74 | * @param apiKey the user's API key. 75 | * @param csvFile 76 | * @return Upon successful insert, HTTP 200 is returned with the string "0,OK". 77 | * @see http://wiki.opencellid.org/wiki/API#Uploading_measurements_from_a_CSV_file 78 | */ 79 | @POST("measure/uploadCsv") 80 | @Multipart 81 | Call uploadCsv( 82 | @Part("key") String apiKey, 83 | @Part MultipartBody.Part csvFile 84 | ); 85 | 86 | /** 87 | * Field names recognised: 88 | * mcc, mnc, lac, cellid, lat, lon, signal, measured_at, rating, speed, direction, act, ta, psc, tac, pci, sid, nid, bid 89 | *

90 | * Maximum file size: 91 | * 2 MB; upload multiple files if you want to upload more data. 92 | * 93 | * @param apiKey the user's API key. 94 | * @param jsonFile JSON file (send in datafile parameter) 95 | * @return Upon successful insert, HTTP 200 is returned with application/json content type and following json document as a content: {"code":0,"status":"OK"} 96 | * @see http://wiki.opencellid.org/wiki/API#Uploading_measurements_from_a_JSON_file 97 | */ 98 | @POST("measure/uploadJson") 99 | @Multipart 100 | Call uploadJson( 101 | @Part("key") String apiKey, 102 | @Part MultipartBody.Part jsonFile 103 | ); 104 | 105 | /** 106 | * @param apiKey the user's API key 107 | * @param clfFile CLF version 3.0 file (to be sent in datafile parameter) 108 | * Columns are semicolon separated and have the following strict order: 109 | * mcc+mnc, lac, cellid, rnc, lat, lon, ratio, data, rfu 110 | *

111 | * There is no header in CLF3 files. Therefore the columns must be provided in the order given above and all values must be there. 112 | *

113 | * You can add comments to CLF3 files. 114 | * Comments in CLF3 start with // and extend to the end of the physical line. 115 | *

116 | * Maximum file size: 117 | * 2 MB; upload multiple files if you want to upload more data. 118 | * @return On successful insert return HTTP 200 with the string "0,OK". 119 | * @see http://wiki.opencellid.org/wiki/API#Uploading_measurements_from_CLF3_file 120 | */ 121 | @POST("measure/uploadClf") 122 | @Multipart 123 | Call uploadClf( 124 | @Part("key") String apiKey, 125 | @Part MultipartBody.Part clfFile 126 | ); 127 | 128 | /** 129 | * @param apiKey API key assigned to the user 130 | * @param measureId ID of the measure to delete 131 | * @return Upon successful deletion, HTTP 200 is returned with the string "Measurement with id= has been deleted." 132 | */ 133 | @POST("measure/delete") 134 | @FormUrlEncoded 135 | Call delete( 136 | @Field("key") String apiKey, 137 | @Field("id") String measureId 138 | ); 139 | 140 | /** 141 | * Listing a user's measurements 142 | * 143 | * @param apiKey API key assigned to the user 144 | * @param limit A number defining maximum size of the returned list. 145 | * Default and maximum value is 1000. 146 | * @param offset The field says to skip that many measurements before beginning to return measurements. 147 | * Default is 0. 148 | * @return Upon successful request, HTTP 200 is returned, oldest entries first 149 | */ 150 | @GET("measure/list?format=json") 151 | Call list( 152 | @Query("key") String apiKey, 153 | @Query("limit") Integer limit, 154 | @Query("offset") Integer offset 155 | ); 156 | 157 | /** 158 | * Getting the number of measurements from a user 159 | * 160 | * @param apiKey API key assigned to the user 161 | * @return Upon successful request, HTTP 200 is returned 162 | */ 163 | @GET("measure/listSize?format=json") 164 | Call listSize( 165 | @Query("key") String apiKey 166 | ); 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/com/github/cellularprivacy/ocidrestclient/service/OcidService.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.service; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.dto.Status; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | 7 | /** 8 | * @see http://wiki.opencellid.org/wiki/API 9 | */ 10 | @SuppressWarnings("unused") 11 | public interface OcidService { 12 | 13 | /** 14 | * Check the online status of OpenCellID 15 | * 16 | * @return Upon successful request, HTTP 200 is returned with JSON in the following format {@code {"status":"ok"}} 17 | */ 18 | @GET("ocid/status") 19 | Call getStatus(); 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/github/cellularprivacy/ocidrestclient/MeasureServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.service.MeasureService; 4 | import okhttp3.*; 5 | import okhttp3.logging.HttpLoggingInterceptor; 6 | import retrofit2.Call; 7 | import retrofit2.Converter; 8 | import retrofit2.Retrofit; 9 | 10 | import java.io.IOException; 11 | import java.lang.annotation.Annotation; 12 | import java.lang.reflect.Type; 13 | 14 | /** 15 | * Created by larsgrefer on 20.04.16. 16 | */ 17 | public class MeasureServiceTest { 18 | 19 | @org.junit.Test 20 | public void testUploadCsv() throws Exception { 21 | Retrofit build = new Retrofit.Builder() 22 | .baseUrl("http://example.com/") 23 | .client( new OkHttpClient.Builder() 24 | .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) 25 | .build()) 26 | .addConverterFactory(new Converter.Factory() { 27 | @Override 28 | public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 29 | if (type == String.class) 30 | return new Converter() { 31 | @Override 32 | public String convert(ResponseBody value) throws IOException { 33 | try { 34 | return value.string(); 35 | } finally { 36 | value.close(); 37 | } 38 | } 39 | }; 40 | return super.responseBodyConverter(type, annotations, retrofit); 41 | } 42 | 43 | @Override 44 | public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { 45 | if(type == String.class) 46 | return new Converter() { 47 | @Override 48 | public RequestBody convert(String value) throws IOException { 49 | return RequestBody.create(MediaType.parse("text/plain"), value); 50 | } 51 | }; 52 | return super.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); 53 | } 54 | 55 | @Override 56 | public Converter stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 57 | return super.stringConverter(type, annotations, retrofit); 58 | } 59 | }) 60 | .build(); 61 | 62 | MeasureService measureService = build.create(MeasureService.class); 63 | 64 | Call responseBodyCall = measureService.uploadCsv( 65 | "hallo", 66 | MultipartBody.Part.createFormData( 67 | "datafile", 68 | "test.csv", 69 | RequestBody.create( 70 | MediaType.parse("string/csv"), "Hallo Welt" 71 | ) 72 | ) 73 | ); 74 | 75 | responseBodyCall.execute(); 76 | } 77 | } -------------------------------------------------------------------------------- /src/test/java/com/github/cellularprivacy/ocidrestclient/client/MeasureClientTest.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.client; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.OcidRestClient; 4 | import com.github.cellularprivacy.ocidrestclient.dto.Count; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import retrofit2.Call; 8 | import retrofit2.Response; 9 | import retrofit2.Retrofit; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Created by larsgrefer on 25.04.16. 15 | */ 16 | public class MeasureClientTest { 17 | 18 | MeasureClient measureClient; 19 | 20 | @Before 21 | public void setUp() throws Exception { 22 | measureClient = new OcidRestClient(new Retrofit.Builder(), "xxx").getMeasureClient(); 23 | } 24 | 25 | @Test 26 | public void testListSize() throws Exception { 27 | Call countCall = measureClient.listSize(); 28 | assertNotNull(countCall); 29 | 30 | Response countResponse = countCall.execute(); 31 | assertNotNull(countResponse); 32 | 33 | assertEquals(403, countResponse.code()); 34 | } 35 | 36 | @Test 37 | public void testList() throws Exception { 38 | 39 | } 40 | 41 | @Test 42 | public void testList1() throws Exception { 43 | 44 | } 45 | 46 | @Test 47 | public void testDelete() throws Exception { 48 | Call stringCall = measureClient.delete("foo"); 49 | assertNotNull(stringCall); 50 | 51 | Response stringResponse = stringCall.execute(); 52 | assertNotNull(stringResponse); 53 | } 54 | 55 | @Test 56 | public void testAdd() throws Exception { 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/java/com/github/cellularprivacy/ocidrestclient/service/OcidServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.cellularprivacy.ocidrestclient.service; 2 | 3 | import com.github.cellularprivacy.ocidrestclient.OcidRestClient; 4 | import com.github.cellularprivacy.ocidrestclient.dto.Status; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import retrofit2.Call; 8 | import retrofit2.Response; 9 | import retrofit2.Retrofit; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | public class OcidServiceTest { 14 | 15 | OcidRestClient ocidRestClient; 16 | 17 | @Before 18 | public void setUp() throws Exception { 19 | ocidRestClient = new OcidRestClient(new Retrofit.Builder(), "xxx"); 20 | } 21 | 22 | @Test 23 | public void testGetStatus() throws Exception { 24 | Call status = ocidRestClient.getOcidService().getStatus(); 25 | 26 | assertNotNull(status); 27 | 28 | Response response = status.execute(); 29 | 30 | assertNotNull(response); 31 | assertTrue(response.isSuccessful()); 32 | assertEquals(200, response.code()); 33 | 34 | Status body = response.body(); 35 | 36 | assertNotNull(body); 37 | } 38 | } --------------------------------------------------------------------------------