/app/src/main/java/com/newtejasrecharge/utils/RestService.java
Java | 507 lines | 414 code | 86 blank | 7 comment | 18 complexity | 6c06a9540aabd0c16c81515efd1047e5 MD5 | raw file
- package com.newtejasrecharge.utils; /**
- * Created by Administrator on 22/01/2016.
- */
- import android.util.Log;
- import com.squareup.okhttp.OkHttpClient;
- import com.newtejasrecharge.money_transfer_spaisa.pojo.bank_list.BankBranchByCityList;
- import com.newtejasrecharge.pojo.balance.GetBalance;
- import com.newtejasrecharge.pojo.check_jio_bill.CheckJioBIll;
- import com.newtejasrecharge.pojo.creditanddebit.credittsummary.CreditReport;
- import com.newtejasrecharge.pojo.creditanddebit.debit_summary_report.DebitReport;
- import com.newtejasrecharge.pojo.giftcard_pojo.gift_card_category_list.GetGiftCategoryList;
- import com.newtejasrecharge.pojo.giftcard_pojo.gift_card_product.GiftCardProduct;
- import com.newtejasrecharge.pojo.giftcard_pojo.giftcard_placeorder.GetPlaceOrder;
- import com.newtejasrecharge.pojo.giftcard_pojo.giftcatd_product_details.ProductDetails;
- import com.newtejasrecharge.pojo.login_otp.LoginOTPVerifuy;
- import com.newtejasrecharge.pojo.news.NewsLine;
- import com.newtejasrecharge.pojo.operator.OperatorListServer;
- import com.newtejasrecharge.pojo.recharge_history.RechargeHistory;
- import com.newtejasrecharge.pojo.recharge_response.RechargeResponse;
- import com.newtejasrecharge.pojo.scheme_add_user.Schemes;
- import com.newtejasrecharge.pojo.userchildelist.UserChild;
- import com.newtejasrecharge.pojo.utility_bill.CheckUtilityBIll;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import retrofit.Callback;
- import retrofit.RestAdapter;
- import retrofit.RetrofitError;
- import retrofit.client.OkClient;
- import retrofit.client.Response;
- import retrofit.http.Field;
- import retrofit.http.FormUrlEncoded;
- import retrofit.http.POST;
- /**
- * Created by Belal on 11/3/2015.
- */
- public class RestService {
- private static final String TAG = "RestService";
- private static RestInterface restInterface;
- private List<MyCallback> callbacks = new ArrayList<>();
- public RestService() {
- final OkHttpClient okHttpClient = new OkHttpClient();
- okHttpClient.setReadTimeout(120, TimeUnit.SECONDS);
- okHttpClient.setConnectTimeout(120, TimeUnit.SECONDS);
- RestAdapter restAdapter = new RestAdapter.Builder()
- .setEndpoint(ApplicationConstant.WEBSERVICEURL)
- .setClient(new OkClient(okHttpClient))
- .setLogLevel(RestAdapter.LogLevel.FULL)
- .build();
- restInterface = restAdapter.create(RestInterface.class);
- }
- public void getnewsline(String userName, String password, RestCallback<NewsLine> restCallback) {
- restInterface.getNews(userName, password, new MyCallback<NewsLine, NewsLine>(restCallback) {
- @Override
- protected NewsLine processResponse(NewsLine utilitySubService) {
- return utilitySubService;
- }
- });
- }
- public void submitElectricityRequest(String userId, String password, String amount, String Number, String opcode,
- String CircleCode, String Mode, String params1, String params2, String Param3, String Param4, String Param5, String Param6,
- RestCallback<RechargeResponse> callback) {
- restInterface.submitElectricityRequest(userId, password, amount, Number, opcode, CircleCode, Mode, params1, params2,
- Param3, Param4, Param5, Param6, new MyCallback<RechargeResponse, RechargeResponse>(callback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse rechargePlansByOperatorResponse) {
- return rechargePlansByOperatorResponse;
- }
- });
- }
- public void doRecharge(String circle, String opcode, String amount, String number, String remark, String userId, String serviceType, String password, String acType, String acNumber, RestCallback<RechargeResponse> restCallback) {
- restInterface.doRecharge(userId, password, amount, number, opcode, circle, acType, acNumber, new MyCallback<RechargeResponse, RechargeResponse>(restCallback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse login) {
- return login;
- }
- });
- }
- public void getLoginInfo(String userName, String password,String imie, RestCallback<LoginOTPVerifuy> restCallback) {
- restInterface.getMainLoginUserInfo(userName, password,imie, new MyCallback<LoginOTPVerifuy, LoginOTPVerifuy>(restCallback) {
- @Override
- protected LoginOTPVerifuy processResponse(LoginOTPVerifuy moneyLoginCheck) {
- return moneyLoginCheck;
- }
- });
- }
- public void verifyOTP(String userName, String password,String imie,String otp, RestCallback<LoginOTPVerifuy> restCallback) {
- restInterface.verifyLoginOTP(userName, password,imie,otp, new MyCallback<LoginOTPVerifuy, LoginOTPVerifuy>(restCallback) {
- @Override
- protected LoginOTPVerifuy processResponse(LoginOTPVerifuy moneyLoginCheck) {
- return moneyLoginCheck;
- }
- });
- }
- public void loginresebtotp(String username, String password, RestCallback<LoginOTPVerifuy> restCallback) {
- restInterface.resendotplogin(username, password, new MyCallback<LoginOTPVerifuy, LoginOTPVerifuy>(restCallback) {
- @Override
- protected LoginOTPVerifuy processResponse(LoginOTPVerifuy moneyLoginCheck) {
- return moneyLoginCheck;
- }
- });
- }
- public void getUserBalance(String userId, String password, RestCallback<GetBalance> restCallback) {
- restInterface.getBalance(userId, password,
- new MyCallback<GetBalance, GetBalance>(restCallback) {
- @Override
- protected GetBalance processResponse(GetBalance getBalance) {
- return getBalance;
- }
- });
- }
- public void getRechargeHistory(String hpUserId, String password, String fromDate, String toDate, RestCallback<RechargeHistory> restCallback) {
- restInterface.getOrderHistory(hpUserId, password, fromDate, toDate, new MyCallback<RechargeHistory, RechargeHistory>(restCallback) {
- @Override
- protected RechargeHistory processResponse(RechargeHistory rechargeHistory) {
- return rechargeHistory;
- }
- });
- }
- public void changePassword(String hpUserId, String oldPw, String newPw, RestCallback<RechargeResponse> restCallback) {
- restInterface.changePassword(hpUserId, oldPw, newPw, new MyCallback<RechargeResponse, RechargeResponse>(restCallback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse exchangeRate) {
- return exchangeRate;
- }
- });
- }
- public void getRechargeHistoryById(String userName, String password, String transId, RestCallback<RechargeHistory> restCallback) {
- restInterface.getOrderHistoryById(userName, password, transId, new MyCallback<RechargeHistory, RechargeHistory>(restCallback) {
- @Override
- protected RechargeHistory processResponse(RechargeHistory rechargeHistory) {
- return rechargeHistory;
- }
- });
- }
- public void getUserScheme(String userName, String password, RestCallback<Schemes> restCallback) {
- restInterface.getUserScheme(userName, password, new MyCallback<Schemes, Schemes>(restCallback) {
- @Override
- protected Schemes processResponse(Schemes schemes) {
- return schemes;
- }
- });
- }
- public void addUser(String userName, String password, String name, String parentName, String mobileNumber, String pan, String farmName, String area, String address, String schemeId, String schemeAmount, String schemeType, RestCallback<RechargeResponse> restCallback) {
- restInterface.addUser(userName, password, name, name, parentName, mobileNumber, pan, farmName, area, address, schemeId, schemeAmount, schemeType, new MyCallback<RechargeResponse, RechargeResponse>(restCallback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse rechargeResponse) {
- return rechargeResponse;
- }
- });
- }
- public void transferBalace(String userName, String password, String name, String amount, String remarks, RestCallback<RechargeResponse> restCallback) {
- restInterface.transferBalace(userName, password, name, amount, remarks, new MyCallback<RechargeResponse, RechargeResponse>(restCallback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse rechargeResponse) {
- return rechargeResponse;
- }
- });
- }
- public void forgetPassword(String userName, RestCallback<RechargeResponse> restCallback) {
- restInterface.forgetPassword(userName, new MyCallback<RechargeResponse, RechargeResponse>(restCallback) {
- @Override
- protected RechargeResponse processResponse(RechargeResponse rechargeResponse) {
- return rechargeResponse;
- }
- });
- }
- public void getBankBranchName(String bankId, String bankCity, RestCallback<BankBranchByCityList> restCallback) {
- restInterface.getBankBranchName(bankId, bankCity, new MyCallback<BankBranchByCityList, BankBranchByCityList>(restCallback) {
- @Override
- protected BankBranchByCityList processResponse(BankBranchByCityList bankBranchesInState) {
- return bankBranchesInState;
- }
- });
- }
- public void validateUtilityBill(String userName, String password, String opcode, String subScriberId, String billingUnit, String cycleNumber, RestCallback<CheckUtilityBIll> restCallback) {
- restInterface.validateUtilityBill(userName, password, opcode, subScriberId, billingUnit, cycleNumber,
- new MyCallback<CheckUtilityBIll, CheckUtilityBIll>(restCallback) {
- @Override
- protected CheckUtilityBIll processResponse(CheckUtilityBIll checkUtilityBIll) {
- return checkUtilityBIll;
- }
- });
- }
- public void userChild(String userName, String password, RestCallback<UserChild> restCallback) {
- restInterface.userchildList(userName, password, new MyCallback<UserChild, UserChild>(restCallback) {
- @Override
- protected UserChild processResponse(UserChild rechargeResponse) {
- return rechargeResponse;
- }
- });
- }
- public void getDebitHistory(String hpUserId, String password, String fromDate, String toDate, RestCallback<DebitReport> restCallback) {
- restInterface.debitHistory(hpUserId, password, fromDate, toDate, new MyCallback<DebitReport, DebitReport>(restCallback) {
- @Override
- protected DebitReport processResponse(DebitReport rechargeHistory) {
- return rechargeHistory;
- }
- });
- }
- public void getCreditHistory(String hpUserId, String password, String fromDate, String toDate, RestCallback<CreditReport> restCallback) {
- restInterface.CreditHistory(hpUserId, password, fromDate, toDate, new MyCallback<CreditReport, CreditReport>(restCallback) {
- @Override
- protected CreditReport processResponse(CreditReport rechargeHistory) {
- return rechargeHistory;
- }
- });
- }
- public void getOperator(String serviceID, RestCallback<OperatorListServer> restCallback) {
- restInterface.getOperator(serviceID,
- new MyCallback<OperatorListServer, OperatorListServer>(restCallback) {
- @Override
- protected OperatorListServer processResponse(OperatorListServer operatorListServer) {
- return operatorListServer;
- }
- });
- }
- public void validateJioBill(String userName, String password, String opcode, String subScriberId, String billingUnit, String cycleNumber, RestCallback<CheckJioBIll> restCallback) {
- restInterface.validateJioBill(userName, password, opcode, subScriberId, billingUnit, cycleNumber,
- new MyCallback<CheckJioBIll, CheckJioBIll>(restCallback) {
- @Override
- protected CheckJioBIll processResponse(CheckJioBIll checkUtilityBIll) {
- return checkUtilityBIll;
- }
- });
- }
- // giftCard URL by Amol
- public void getGiftCardList(String userName, String password, RestCallback<GetGiftCategoryList> callback) {
- restInterface.giftcard(userName, password, new MyCallback<GetGiftCategoryList, GetGiftCategoryList>(callback) {
- @Override
- protected GetGiftCategoryList processResponse(GetGiftCategoryList getGiftCategoryList) {
- return getGiftCategoryList;
- }
- });
- }
- public void PurchadeOrder(String userName, String password, String p_ID, String Price, String Quantity, String Amount, String Sfname, String Slname, String Semailid, String Snumber, String Rfname, String Rlname, String Remailid, String Rnumber, String RechargeMode,
- RestCallback<GetPlaceOrder> callback) {
- restInterface.productPurchaseOrder(userName, password, p_ID,
- Price, Quantity, Amount, Sfname, Slname, Semailid, Snumber, Rfname, Rlname, Remailid, Rnumber, RechargeMode,
- new MyCallback<GetPlaceOrder, GetPlaceOrder>(callback) {
- @Override
- protected GetPlaceOrder processResponse(GetPlaceOrder getGiftCategoryList) {
- return getGiftCategoryList;
- }
- });
- }
- public void getproduct(String userName, String password, String category, RestCallback<GiftCardProduct> callback) {
- restInterface.giftProduct(userName, password, category, new MyCallback<GiftCardProduct, GiftCardProduct>(callback) {
- @Override
- protected GiftCardProduct processResponse(GiftCardProduct getGiftCategoryList) {
- return getGiftCategoryList;
- }
- });
- }
- public void getproductDet(String userName, String password, String p_ID, RestCallback<ProductDetails> callback) {
- restInterface.giftProductDetails(userName, password, p_ID, new MyCallback<ProductDetails, ProductDetails>(callback) {
- @Override
- protected ProductDetails processResponse(ProductDetails getGiftCategoryList) {
- return getGiftCategoryList;
- }
- });
- }
- private interface RestInterface {
- @FormUrlEncoded
- @POST("/Recharge/GetAllRecharge")
- void doRecharge(@Field("UserName") String userId, @Field("Password") String password, @Field("Amount") String amount,
- @Field("MobileNumber") String number, @Field("OPTID") String opcode, @Field("Circle") String circle,
- @Field("Type") String acType,
- @Field("AccountNo") String acNumber, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/Recharge/GetUtilityBillPay")
- void submitElectricityRequest(@Field("UserName") String userId,
- @Field("Password") String password,
- @Field("Amount") String amount,
- @Field("Number") String consumerId,
- @Field("OperatorCode") String opcode,
- @Field("CircleCode") String circleCode,
- @Field("Mode") String Mode,
- @Field("Param1") String CycleOrBillingUnit,
- @Field("Param2") String param2,
- @Field("Param3") String contactNumber,
- @Field("Param4") String param4,
- @Field("Param5") String Param5,
- @Field("Param6") String Param6, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetLoginDetailsNew")
- void getMainLoginUserInfo(@Field("UserName") String userName, @Field("Password") String password,@Field("IMEINO") String IMEINO, MyCallback<LoginOTPVerifuy, LoginOTPVerifuy> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetLoginOTPVerify")
- void verifyLoginOTP(@Field("UserName") String userName,
- @Field("Password") String passWord,
- @Field("IMEINO") String imeiNo,
- @Field("OTP") String otp, MyCallback<LoginOTPVerifuy, LoginOTPVerifuy> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetLoginReSendOTP")
- void resendotplogin(@Field("UserName") String userName,
- @Field("Password") String passWord,
- MyCallback<LoginOTPVerifuy, LoginOTPVerifuy> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetUserBalance")
- void getBalance(@Field("UserName") String userName, @Field("Password") String password, MyCallback<GetBalance, GetBalance> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetLastTransaction")
- void getOrderHistory(@Field("UserName") String hpUserId, @Field("Password") String password, @Field("FromDate") String fromDate, @Field("ToDate") String toDate, MyCallback<RechargeHistory, RechargeHistory> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetTransactionByMobileNo")
- void getOrderHistoryById(@Field("UserName") String userName, @Field("Password") String password, @Field("MobileNo") String transId, MyCallback<RechargeHistory, RechargeHistory> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetUtilityBillPayValidate")
- void validateJioBill(@Field("UserName") String userId, @Field("Password") String password, @Field("OperatorCode") String opcode, @Field("Number") String subScriberId,
- @Field("BillUnit") String billingUnit, @Field("CycleNo") String cycleNumber, MyCallback<CheckJioBIll, CheckJioBIll> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetChangePassword")
- void changePassword(@Field("UserName") String hpUserId, @Field("Password") String oldPw, @Field("NewPassword") String newPw, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/UserService/GetUserSchemes")
- void getUserScheme(@Field("UserName") String userName, @Field("Password") String password, MyCallback<Schemes, Schemes> myCallback);
- @FormUrlEncoded
- @POST("/UserService/AddNewUser")
- void addUser(@Field("UserName") String userName, @Field("Password") String password, @Field("CurrentUserName") String name,
- @Field("CurrentUserId") String currentUserId, @Field("OwnerName") String parentName,
- @Field("MobileNo") String mobileNumber, @Field("PanCard") String pan, @Field("FirmName") String farmName,
- @Field("Area") String area, @Field("Address") String address, @Field("SchemeId") String schemeId,
- @Field("SchemeAmount") String schemeAmount, @Field("UserType") String schemeType, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/UserService/GetWallettowalletcr")
- void transferBalace(@Field("UserName") String userName, @Field("Password") String password, @Field("CrUserName") String name,
- @Field("Amount") String amount, @Field("Remarks") String remarks, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetForgotPassword")
- void forgetPassword(@Field("UserName") String userName, MyCallback<RechargeResponse, RechargeResponse> myCallback);
- @FormUrlEncoded
- @POST("/MoneycbNew/GetBranchName")
- void getBankBranchName(@Field("bankid") String bankId, @Field("city") String bankCity, MyCallback<BankBranchByCityList, BankBranchByCityList> myCallback);
- @FormUrlEncoded
- @POST("/RGUSER/GetUtilityBillPayValidate")
- void validateUtilityBill(@Field("username") String userId, @Field("password") String password, @Field("OperatorCode") String opcode, @Field("Number") String subScriberId,
- @Field("BillUnit") String billingUnit, @Field("CycleNo") String cycleNumber, MyCallback<CheckUtilityBIll, CheckUtilityBIll> myCallback);
- @FormUrlEncoded
- @POST("/UserService/GetUserNews")
- void getNews(@Field("UserName") String userName, @Field("Password") String password, MyCallback<NewsLine, NewsLine> myCallback);
- @FormUrlEncoded
- @POST("/operatorServices/GetOperatorName")
- void getOperator(@Field("ServiceId") String serviceID, MyCallback<OperatorListServer, OperatorListServer> myCallback);
- @FormUrlEncoded
- @POST("/UserService/GetUserAllChild")
- void userchildList(@Field("UserName") String userName, @Field("Password") String password,
- MyCallback<UserChild, UserChild> myCallback);
- @FormUrlEncoded
- @POST("/ReportsServices/GetPaymentDebitReport")
- void debitHistory(@Field("UserName") String hpUserId, @Field("Password") String password, @Field("FromDate") String fromDate, @Field("ToDate") String toDate, MyCallback<DebitReport, DebitReport> myCallback);
- @FormUrlEncoded
- @POST("/ReportsServices/GetPaymentCreditReport")
- void CreditHistory(@Field("UserName") String hpUserId, @Field("Password") String password, @Field("FromDate") String fromDate, @Field("ToDate") String toDate, MyCallback<CreditReport, CreditReport> myCallback);
- // giftCard Services by am
- @FormUrlEncoded
- @POST("/GiftcardCServices/GetGiftCategoryList")
- void giftcard(@Field("UserName") String userId, @Field("Password") String password, MyCallback<GetGiftCategoryList, GetGiftCategoryList> myCallback);
- @FormUrlEncoded
- @POST("/GiftcardCServices/GetPlaceorder")
- void productPurchaseOrder(@Field("UserName") String userId, @Field("Password") String password, @Field("Productid") String productid, @Field("Price") String price, @Field("Quantity") String quantity, @Field("Amount") String amount, @Field("Sfname") String sfname, @Field("Slname") String slname, @Field("Semailid") String semailid, @Field("Snumber") String snumber, @Field("Rfname") String rfname, @Field("Rlname") String rlname, @Field("Remailid") String remailid, @Field("Rnumber") String rnumber,
- @Field("RechargeMode") String rechargeMode,
- MyCallback<GetPlaceOrder, GetPlaceOrder> myCallback);
- @FormUrlEncoded
- @POST("/GiftcardCServices/GetGiftProductList")
- void giftProduct(@Field("UserName") String userId, @Field("Password") String password, @Field("category") String category, MyCallback<GiftCardProduct, GiftCardProduct> myCallback);
- @FormUrlEncoded
- @POST("/GiftcardCServices/GetProductAndBrand")
- void giftProductDetails(@Field("UserName") String userId, @Field("Password") String password, @Field("Productid") String prod_id, MyCallback<ProductDetails, ProductDetails> myCallback);
- }
- private abstract class MyCallback<M, N> implements Callback<N> {
- private RestCallback<M> restCallback;
- private boolean isCanceled;
- protected MyCallback(RestCallback<M> restCallback) {
- this.restCallback = restCallback;
- callbacks.add(this);
- }
- final void cancel() {
- isCanceled = true;
- }
- @Override
- public final void success(N n, Response response) {
- if (!isCanceled && restCallback != null) {
- try {
- M m = processResponse(n);
- if (m != null) {
- Log.d(TAG, "success");
- restCallback.success(m);
- } else {
- Log.d(TAG, "invalid");
- restCallback.invalid();
- }
- } catch (Exception e) {
- Log.d(TAG, "parse failure");
- String errorMessage = e.getMessage();
- if (errorMessage != null && errorMessage.length() > 0) {
- Log.e(TAG, e.getMessage());
- } else {
- e.printStackTrace();
- }
- restCallback.invalid();
- }
- }
- }
- @Override
- public final void failure(RetrofitError error) {
- if (!isCanceled && restCallback != null) {
- Log.d(TAG, "failure");
- String errorMessage = error.getMessage();
- if (errorMessage != null && errorMessage.length() > 0) {
- Log.d(TAG, errorMessage);
- }
- if (error.getKind() == RetrofitError.Kind.NETWORK) {
- errorMessage = "Network is down! Try Again...";
- }
- restCallback.failure(errorMessage);
- }
- }
- protected abstract M processResponse(N n);
- }
- }