This repository has been archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fac3d4
commit a1a3313
Showing
5 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
voiceandroid/src/main/java/mobtexting/com/voiceandroid/Interface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package mobtexting.com.voiceandroid; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.Field; | ||
import retrofit2.http.FormUrlEncoded; | ||
import retrofit2.http.POST; | ||
|
||
public interface Interface { | ||
@FormUrlEncoded | ||
@POST("/v1/sms/") | ||
Call<ServerResponse> post( | ||
@Field("api_key") String api_key, | ||
@Field("method") String method, | ||
@Field("pilot_number") String pilot_number, | ||
@Field("caller") String caller, | ||
@Field("receiver") String receiver | ||
); | ||
} |
95 changes: 95 additions & 0 deletions
95
voiceandroid/src/main/java/mobtexting/com/voiceandroid/Mobtexting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package mobtexting.com.voiceandroid; | ||
|
||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import java.io.IOException; | ||
import java.lang.annotation.Annotation; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.ResponseBody; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Converter; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
public class Mobtexting { | ||
private static final String TAG = "Communicator"; | ||
private static final String SERVER_URL = "http://api.mobtexting.in"; | ||
private Retrofit retrofit; | ||
private Context context; | ||
private String api_key; | ||
|
||
/** | ||
* @param context | ||
*/ | ||
public Mobtexting(Context context) { | ||
this.context = context; | ||
} | ||
|
||
/** | ||
* click to call | ||
* @param pilot_number | ||
* @param caller | ||
* @param receiver | ||
* @param mobtextingInterface | ||
*/ | ||
public void clickToCall(String pilot_number,String caller,String receiver,final MobtextingInterface mobtextingInterface) { | ||
try { | ||
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); | ||
Bundle bundle = ai.metaData; | ||
api_key = bundle.getString("mobtexting.api_key"); | ||
} catch (Exception e) { | ||
mobtextingInterface.onError(new ServerResponse("Dear developer. Don't forget to configure <meta-data android:name=\"mobtexting.api_key\" android:value=\"testValue\"/> in your AndroidManifest.xml file.", false,100 )); | ||
return; | ||
} | ||
if (api_key != null && !api_key.equals("")) { | ||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); | ||
logging.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); | ||
httpClient.addInterceptor(logging); | ||
|
||
retrofit = new Retrofit.Builder() | ||
.client(httpClient.build()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.baseUrl(SERVER_URL) | ||
.build(); | ||
|
||
Interface service = retrofit.create(Interface.class); | ||
|
||
Call<ServerResponse> call = service.post(api_key, "click2call", pilot_number, caller,receiver); | ||
|
||
call.enqueue(new Callback<ServerResponse>() { | ||
@Override | ||
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) { | ||
// response.isSuccessful() is true if the response code is 2xx | ||
if (response.isSuccessful()) { | ||
Log.e(TAG, response.body().toString()); | ||
mobtextingInterface.onResponse(response.body()); | ||
} else { | ||
try { | ||
Converter<ResponseBody, ServerResponse> errorConverter = retrofit.responseBodyConverter(ServerResponse.class, new Annotation[0]); | ||
ServerResponse error = errorConverter.convert(response.errorBody()); | ||
mobtextingInterface.onError(error); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
mobtextingInterface.onError(new ServerResponse("Check your internet connection!/parsing Json exception", false,500 )); | ||
} | ||
} | ||
} | ||
@Override | ||
public void onFailure(Call<ServerResponse> call, Throwable t) { | ||
mobtextingInterface.onError(new ServerResponse("Check your internet connection!/parsing Json exception", false,500 )); | ||
} | ||
}); | ||
} else { | ||
mobtextingInterface.onError(new ServerResponse("Dear developer. Don't forget to configure <meta-data android:name=\"mobtexting.api_key\" android:value=\"testValue\"/> in your AndroidManifest.xml file.", false,100 )); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
voiceandroid/src/main/java/mobtexting/com/voiceandroid/MobtextingInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package mobtexting.com.voiceandroid; | ||
|
||
public interface MobtextingInterface { | ||
void onResponse(ServerResponse response); | ||
void onError(ServerResponse modelError); | ||
} |
43 changes: 43 additions & 0 deletions
43
voiceandroid/src/main/java/mobtexting/com/voiceandroid/ServerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mobtexting.com.voiceandroid; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class ServerResponse { | ||
|
||
@SerializedName("message") | ||
private String message; | ||
@SerializedName("status") | ||
private boolean status; | ||
@SerializedName("response_code") | ||
private int responseCode; | ||
|
||
public ServerResponse(String message, boolean status, int responseCode) { | ||
this.message = message; | ||
this.status = status; | ||
this.responseCode = responseCode; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public boolean getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(boolean status) { | ||
this.status = status; | ||
} | ||
|
||
public int getResponseCode() { | ||
return responseCode; | ||
} | ||
|
||
public void setResponseCode(int responseCode) { | ||
this.responseCode = responseCode; | ||
} | ||
} |