Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
sdk implemetation
Browse files Browse the repository at this point in the history
  • Loading branch information
dkgupta2501 committed May 8, 2018
1 parent 7fac3d4 commit a1a3313
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .idea/DtonatorPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
);
}
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 ));
}
}
}
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);
}
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;
}
}

0 comments on commit a1a3313

Please sign in to comment.