initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
public class ApiConstants {
|
||||
public static final int API_READ_TIMEOUT = 30;
|
||||
public static final int API_CONNECT_TIMEOUT = 10;
|
||||
public static final String API_PATH = "http://pizza-leu.ch/";
|
||||
//public static final String API_PATH = "http://pizzaleu.ddns.net/";
|
||||
public static final String APP_TYPE_ID_ANDROID = "2";
|
||||
public static final int APP_ERROR_CODE_AUTHORIZATION = 1;
|
||||
|
||||
public static final int PRODUCT_ID_WUNSCHPIZZA = 56;
|
||||
public static final int PRODUCT_ID_ABEND_MENU = 733;
|
||||
public static final int PRODUCT_ID_MITTAGS_MENU = 732;
|
||||
|
||||
public static final String CAMPAIGN_CODE_PIZZAPASS = "PIZZAPASS";
|
||||
public static final String CAMPAIGN_CODE_KEBAPPASS = "KEBAPPASS";
|
||||
|
||||
public static final String PAYMENT_METHOD_CODE_CREDIT_DEBIT_CARD = "braintree"; // Credit / Debit Card
|
||||
public static final String PAYMENT_METHOD_CODE_BANK_CASH = "cod"; // Bar
|
||||
public static final String PAYMENT_METHOD_CODE_TRANSFER = "bank_transfer"; // Kreditkarten-Kartenzahlung
|
||||
public static final String PAYMENT_METHOD_CODE_TWINT = "twintcw_twint"; // TWINT
|
||||
public static final String PAYMENT_METHOD_CODE_PAYPAL = "pp_standard";
|
||||
public static final String PAYMENT_METHOD_CODE_POST_FINANCE_CARD = "postfinancecw_postfinancecard";
|
||||
public static final String PAYMENT_METHOD_CODE_ANDROID_PAY = "android_pay";
|
||||
public static final String PAYMENT_METHOD_CODE_APPLE_PAY = "apple_pay";
|
||||
|
||||
public static final String DATATRANS_MERCHANT_ID_TEST = "1100004450"; // Taken from Datatrans sample app
|
||||
//public static final String DATATRANS_MERCHANT_ID_TEST = "1100020808"; // taken from Datatrans sandbox Demo Pusula Media GmbH
|
||||
public static final String DATATRANS_REFERENCE_NUMBER_TEST = "968927"; // Taken from Datatrans sample app
|
||||
public static final String DATATRANS_SIGNATURE_TEST = "30916165706580013"; // Taken from Datatrans sample app
|
||||
|
||||
public static final String SHIPPING_METHOD_CODE_FREE_SHIPPING = "free.free";
|
||||
public static final String SHIPPING_METHOD_CODE_PICK_UP_FROM_STORE = "pickup.pickup";
|
||||
|
||||
public static final String CART_SUBTOTAL = "zwischensumme";
|
||||
public static final String CART_COMMISSION = "zahlungsgebühr";
|
||||
public static final String CART_TOTAL = "total";
|
||||
|
||||
public static final String OPTION_ID_ABEND_AND_MITTAGS_MENU_PIZZA_SELECTION = "73";
|
||||
|
||||
public static final String PRODUCT_OPTION_ID_ABEND_MENU_PIZZA_SELECTION = "869";
|
||||
public static final String PRODUCT_OPTION_ID_MITTAGS_MENU_OPTIONS = "872";
|
||||
|
||||
public static final String ONESIGNAL_NOTIFICATION_TAG_KEY = "notificationAllowed";
|
||||
public static final String ONESIGNAL_NOTIFICATION_TAG_VALUE = "true";
|
||||
|
||||
public static final String PAYMENT_WEBVIEW_URL_POSTFINANCE_TWINT = "https://pizza-cucina.ch/pizzacucina/index.php?route=mobile/service/postFinancePayment&order_id=";
|
||||
public static final String PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_SUCCESS = "postFinancePaymentIsSuccess";
|
||||
public static final String PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_FAIL = "postFinancePaymentIsFailed";
|
||||
public static final String PAYMENT_WEBVIEW_MAIN_PAGE_HTTP = "http://www.pizza-cucina.ch/";
|
||||
public static final String PAYMENT_WEBVIEW_MAIN_PAGE_HTTPS = "https://www.pizza-cucina.ch/";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
public class ApiEndPoints {
|
||||
|
||||
private static final String PREFIX = "/index.php?route=mobile/service/";
|
||||
private static final String SUFFIX = "&is_mobile=1";
|
||||
|
||||
public static final String API_GET_STORE_LIST = "pizza/servicemagazabelirle.php";
|
||||
public static final String API_GET_CAMPAIGN_BANNERS = "pizzacucia/" + PREFIX + "getCampaignBanners" + SUFFIX;
|
||||
|
||||
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories" + SUFFIX;
|
||||
public static final String API_GET_IGNORED_CATEGORY_IDS= PREFIX + "getIgnoredCategory" + SUFFIX;
|
||||
public static final String API_GET_PIZZA_CATEGORY_IDS= PREFIX + "getPizzaCategories" + SUFFIX;
|
||||
public static final String API_REGISTER = PREFIX + "signUp" + SUFFIX;
|
||||
public static final String API_LOGIN = PREFIX + "login" + SUFFIX;
|
||||
public static final String API_LOGOUT = PREFIX + "logout" + SUFFIX;
|
||||
public static final String API_GET_ORDER_HISTORY = PREFIX + "getOrders" + SUFFIX;
|
||||
public static final String API_GET_CLEAR_CART = PREFIX + "clearBasket" + SUFFIX;
|
||||
public static final String API_GET_PRODUCTS_BY_CATEGORY = PREFIX + "getProductsByCategory" + SUFFIX;
|
||||
public static final String API_GET_PRODUCT = PREFIX + "getProduct" + SUFFIX;
|
||||
public static final String API_GET_SHIPPING_METHODS = PREFIX + "getShippingMethods" + SUFFIX;
|
||||
public static final String API_GET_CUSTOMER_ADDRESSES = PREFIX + "getAddresses" + SUFFIX;
|
||||
public static final String API_GET_PAYMENT_METHODS = PREFIX + "getPaymentMethods" + SUFFIX;
|
||||
public static final String API_CHECK_UPDATE = PREFIX + "checkUpdate" + SUFFIX;
|
||||
public static final String API_FORGOT_PASSWORD = PREFIX + "forgotPassword" + SUFFIX;
|
||||
public static final String API_GET_CITY_LIST = PREFIX + "getCities" + SUFFIX;
|
||||
public static final String API_GET_COUNTRY_LIST = PREFIX + "getCountries" + SUFFIX;
|
||||
public static final String API_GET_ZONE_LIST = PREFIX + "getZones" + SUFFIX;
|
||||
public static final String API_GET_CUSTOMER_PROFILE = PREFIX + "getCustomerInfo" + SUFFIX;
|
||||
public static final String API_GET_STORE_INFO = PREFIX + "getStoreInfo" + SUFFIX;
|
||||
public static final String API_CHECK_CAMPAIGN_PIZZAPASS = PREFIX + "detectPizzaPassCampaign" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_CAMPAIGN_KEBAPPASS = PREFIX + "detectKebapPassCampaign" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_DELIVERY_TIME = PREFIX + "checkDeliveryTimeService" + SUFFIX;
|
||||
public static final String API_GET_DELIVERY_TIME_OF_STORE = PREFIX + "getDeliveryTimeForStore" + SUFFIX;
|
||||
|
||||
|
||||
public static final String API_GET_CART_PRODUCTS = PREFIX + "getBasketProducts" + SUFFIX + "&token=";
|
||||
//addProductsToBasketYeni
|
||||
public static final String API_ADD_PRODUCTS_TO_BASKET = PREFIX + "addProductsToBasket" + SUFFIX + "&token=";
|
||||
public static final String API_ADD_NEW_ADDRESS = PREFIX + "addAddress" + SUFFIX + "&token=";
|
||||
public static final String API_DELETE_ADDRESS = PREFIX + "deleteAddress" + SUFFIX + "&token=";
|
||||
public static final String API_CREATE_ORDER = PREFIX + "addOrder" + SUFFIX + "&token=";
|
||||
public static final String API_UPDATE_PASSWORD = PREFIX + "passwordUpdate" + SUFFIX + "&token=";
|
||||
public static final String API_UPDATE_PROFILE = PREFIX + "updateCustomerInfo" + SUFFIX + "&token=";
|
||||
public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token=";
|
||||
public static final String API_GET_ORDER_PRODUCT_LIST = PREFIX + "getOrderProducts" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token=";
|
||||
public static final String API_CREATE_BRAINTREE_PAYMENT = PREFIX + "checkBrainTreePayment" + SUFFIX + "&token=";
|
||||
public static final String API_REPEAT_ORDER = PREFIX + "reOrder" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_ORDER_PRICE = PREFIX + "checkOrderPrice" + SUFFIX + "&token=";
|
||||
public static final String API_CREATE_BRAINTREE_PAYMENT_TOKEN = PREFIX + "createPaymentToken" + SUFFIX + "&token=";
|
||||
public static final String API_GET_DATATRANS_INFO = PREFIX + "getDatatransInfo" + SUFFIX + "&token=";
|
||||
public static final String API_CREATE_DATATRANS_PAYMENT = PREFIX + "checkDatatransPayment" + SUFFIX + "&token=";
|
||||
|
||||
}
|
||||
43
app/src/main/java/ch/pizzacucia/android/api/ApiError.java
Normal file
43
app/src/main/java/ch/pizzacucia/android/api/ApiError.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
public class ApiError {
|
||||
|
||||
private boolean success;
|
||||
private int error_code;
|
||||
private String message;
|
||||
private int statusCode;
|
||||
|
||||
public ApiError() {}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getError_code() {
|
||||
return error_code;
|
||||
}
|
||||
|
||||
public void setError_code(int error_code) {
|
||||
this.error_code = error_code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import ch.pizzacucia.android.R;
|
||||
import ch.pizzacucia.android.activity.BaseActivity;
|
||||
import ch.pizzacucia.android.activity.LoginActivity;
|
||||
import ch.pizzacucia.android.helper.DialogHelper;
|
||||
import ch.pizzacucia.android.helper.SharedPrefsHelper;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ApiErrorUtils {
|
||||
|
||||
public static void parseError(Response<?> response) {
|
||||
Converter<ResponseBody, ApiError> converter = ApiService.retrofit.responseBodyConverter(ApiError.class, new Annotation[0]);
|
||||
ApiError error = new ApiError();
|
||||
error.setStatusCode(response.code());
|
||||
|
||||
BaseResponse baseResponse = (BaseResponse) response.body();
|
||||
|
||||
if(baseResponse != null){
|
||||
|
||||
if(baseResponse.getErrorCode() == ApiConstants.APP_ERROR_CODE_AUTHORIZATION){
|
||||
SharedPrefsHelper.clearCustomerInfo();
|
||||
SharedPrefsHelper.clearCustomerToken();
|
||||
SharedPrefsHelper.setCustomerLoggedIn(false);
|
||||
BaseActivity.currentActivity.startActivity(new Intent(BaseActivity.currentActivity, LoginActivity.class));
|
||||
BaseActivity.currentActivity.finishAffinity();
|
||||
return;
|
||||
}
|
||||
|
||||
if(baseResponse.getMessage() != null && !baseResponse.getMessage().isEmpty()){
|
||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity, baseResponse.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
error = converter.convert(response.errorBody());
|
||||
DialogHelper.showDialogWithPositiveButton(BaseActivity.currentActivity, error.getMessage());
|
||||
} catch (Exception e) {
|
||||
DialogHelper.showDialogWithPositiveButton(BaseActivity.currentActivity, BaseActivity.currentActivity.getString(R.string.something_went_wrong));
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseErrorWithoutAuthorizationErrorControl(Response<?> response) {
|
||||
Converter<ResponseBody, ApiError> converter = ApiService.retrofit.responseBodyConverter(ApiError.class, new Annotation[0]);
|
||||
ApiError error = new ApiError();
|
||||
error.setStatusCode(response.code());
|
||||
|
||||
BaseResponse baseResponse = (BaseResponse) response.body();
|
||||
|
||||
if (baseResponse != null && baseResponse.getMessage() != null && !baseResponse.getMessage().isEmpty()) {
|
||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity, baseResponse.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
error = converter.convert(response.errorBody());
|
||||
DialogHelper.showDialogWithPositiveButton(BaseActivity.currentActivity, error.getMessage());
|
||||
} catch (Exception e) {
|
||||
DialogHelper.showDialogWithPositiveButton(BaseActivity.currentActivity, BaseActivity.currentActivity.getString(R.string.something_went_wrong));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
393
app/src/main/java/ch/pizzacucia/android/api/ApiInterface.java
Normal file
393
app/src/main/java/ch/pizzacucia/android/api/ApiInterface.java
Normal file
@@ -0,0 +1,393 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import ch.pizzacucia.android.model.AddNewAddressResponseModel;
|
||||
import ch.pizzacucia.android.model.AddProductToBasketResponseModel;
|
||||
import ch.pizzacucia.android.model.AddressModel;
|
||||
import ch.pizzacucia.android.model.AppVersionModel;
|
||||
import ch.pizzacucia.android.model.CampaignBannerModel;
|
||||
import ch.pizzacucia.android.model.CampaignModel;
|
||||
import ch.pizzacucia.android.model.CheckCouponModel;
|
||||
import ch.pizzacucia.android.model.CountryModel;
|
||||
import ch.pizzacucia.android.model.DeleteAddressResponseModel;
|
||||
import ch.pizzacucia.android.model.PaymentMethodsResponseModel;
|
||||
import ch.pizzacucia.android.model.PaymentTokenModel;
|
||||
import ch.pizzacucia.android.model.RemoveProductFromCartResponseModel;
|
||||
import ch.pizzacucia.android.model.ShippingMethodModel;
|
||||
import ch.pizzacucia.android.model.StoreInfoModel;
|
||||
import ch.pizzacucia.android.model.CityModel;
|
||||
import ch.pizzacucia.android.model.StoreModel;
|
||||
import ch.pizzacucia.android.model.StoreShiftModel;
|
||||
import ch.pizzacucia.android.model.ZoneModel;
|
||||
import ch.pizzacucia.android.model.cart.CartInfoModel;
|
||||
import ch.pizzacucia.android.model.CategoryModel;
|
||||
import ch.pizzacucia.android.model.history.OrderHistoryModel;
|
||||
import ch.pizzacucia.android.model.UserModel;
|
||||
import ch.pizzacucia.android.model.history.OrderHistoryProductModel;
|
||||
import ch.pizzacucia.android.model.menu.MenuProductModel;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FieldMap;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 04/02/2017.
|
||||
*/
|
||||
|
||||
public interface ApiInterface {
|
||||
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_ALL_CATEGORIES)
|
||||
Call<ResponseArray<CategoryModel>> getAllCategories(@Path("storeName") String storeName);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_IGNORED_CATEGORY_IDS)
|
||||
Call<ResponseArray<Integer>> getIgnoredCategoryIds(@Path("storeName") String storeName);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_PIZZA_CATEGORY_IDS)
|
||||
Call<ResponseArray<Integer>> getPizzaCategoryIds(@Path("storeName") String storeName);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_REGISTER)
|
||||
Call<ResponseObject<UserModel>> register(@Path("storeName") String storeName,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_LOGIN)
|
||||
Call<ResponseObject<UserModel>> login(@Path("storeName") String storeName,
|
||||
@Field("email") String email,
|
||||
@Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_LOGOUT)
|
||||
Call<ResponseObject> logout(@Path("storeName") String storeName,
|
||||
@Field("token") String customerToken);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_ORDER_HISTORY)
|
||||
Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
/*
|
||||
// OK
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProducts(@Url String url);
|
||||
|
||||
// OK
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProductsForCommission(@Url String url,
|
||||
@Field("payment_method") String paymentMethodCode,
|
||||
@Field("shipping_method") String shippingMethodCode);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProductsWithCoupon(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
*/
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProducts(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_CLEAR_CART)
|
||||
Call<ResponseObject> clearCart(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_PRODUCTS_BY_CATEGORY)
|
||||
Call<ResponseArray<MenuProductModel>> getProductsByCategory(@Path("storeName") String storeName,
|
||||
@Query("category_id") String categoryId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_GET_PRODUCT)
|
||||
Call<ResponseArray<MenuProductModel>> getProductById(@Path("storeName") String storeName,
|
||||
@Field("product_id") int productId);
|
||||
|
||||
|
||||
// * Bu projedeki post servisler bizden form-data bekliyor. Bu serviste @FormUrlEncoded yapınca ve
|
||||
// * body'i @FieldMap HashMap<String, Object> body olarak verince, body içindeki alanlar
|
||||
// * encode ediliyor, mesela body içindeki "[" karakteri "%5D" ye falan dönüşüyor, dolayısı ile servis bunları okuyamıyor.
|
||||
// * Bu sebeple body olarak RequestBody verdim ve servisi çağırırken bod içindeki alanları FormBody olarak ekledim.
|
||||
// OK
|
||||
@POST
|
||||
Call<ResponseObject<AddProductToBasketResponseModel>> addProductsToBasket(@Url String url,
|
||||
@Body RequestBody body);
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_SHIPPING_METHODS)
|
||||
Call<ResponseArray<ShippingMethodModel>> getShippingMethods(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_CUSTOMER_ADDRESSES)
|
||||
Call<ResponseArray<AddressModel>> getCustomerAddresses(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<AddNewAddressResponseModel>> addNewAddress(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<DeleteAddressResponseModel>> deleteAddress(@Url String url,
|
||||
@Field("address_id") String addressId);
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_PAYMENT_METHODS)
|
||||
Call<ResponseObject<PaymentMethodsResponseModel>> getPaymentMethods(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<Integer>> createOrder(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_CHECK_UPDATE)
|
||||
Call<ResponseObject<AppVersionModel>> checkUpdate(@Path("storeName") String storeName,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_FORGOT_PASSWORD)
|
||||
Call<ResponseObject> forgotPassword(@Path("storeName") String storeName,
|
||||
@Field("email") String emailAddress);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_CITY_LIST)
|
||||
Call<ResponseArray<CityModel>> getCityList(@Path("storeName") String storeName);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_COUNTRY_LIST)
|
||||
Call<ResponseArray<CountryModel>> getCountryList(@Path("storeName") String storeName);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_GET_ZONE_LIST)
|
||||
Call<ResponseArray<ZoneModel>> getZoneList(@Path("storeName") String storeName,
|
||||
@Field("country_id") String countryId);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_CUSTOMER_PROFILE)
|
||||
Call<ResponseObject<UserModel>> getCustomerProfile(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> updatePassword(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<UserModel>> updateProfile(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<RemoveProductFromCartResponseModel>> removeProductFromCart(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_STORE_INFO)
|
||||
Call<ResponseObject<StoreInfoModel>> getStoreInfo(@Path("storeName") String storeName);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseArray<OrderHistoryProductModel>> getOrderProductList(@Url String url,
|
||||
@Field("order_id") String orderId);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CheckCouponModel>> checkCoupon(@Url String url,
|
||||
@Field("coupon") String couponCode);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_CHECK_CAMPAIGN_PIZZAPASS)
|
||||
Call<ResponseObject<CampaignModel>> checkPizzapassCampaign(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_CHECK_CAMPAIGN_KEBAPPASS)
|
||||
Call<ResponseObject<CampaignModel>> checkKebapPassCampaign(@Path("storeName") String storeName,
|
||||
@Query("token") String token);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_CHECK_DELIVERY_TIME)
|
||||
Call<ResponseObject<Boolean>> checkDeliveryTime(@Path("storeName") String storeName,
|
||||
@Query("shipping_method_code") String shippingMethodCode);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("{storeName}" + ApiEndPoints.API_CHECK_DELIVERY_TIME)
|
||||
Call<ResponseObject<Boolean>> checkDeliveryTimeWithDateAndTime(@Path("storeName") String storeName,
|
||||
@Field("delivery_date") String deliveryDateAndTime,
|
||||
@Field("shipping_method_code") String shippingMethodCode);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> createBraintreePayment(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> repeatOrder(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_STORE_LIST)
|
||||
Call<ResponseArray<StoreModel>> getStoreList();
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_GET_DELIVERY_TIME_OF_STORE)
|
||||
Call<ResponseObject<StoreShiftModel>> getDeliveryTimeOfStore(@Path("storeName") String storeName,
|
||||
@Query("shipping_method_code") String shippingMethodCode);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> checkOrderPrice(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@GET
|
||||
Call<ResponseObject<PaymentTokenModel>> createBraintreePaymentToken(@Url String url);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_CAMPAIGN_BANNERS)
|
||||
Call<ResponseArray<CampaignBannerModel>> getCampaignBanners();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@GET(ApiEndPoints.API_GET_ALL_CATEGORIES)
|
||||
Call<ResponseArray<CategoryModel>> getAllCategories(@Path("id") int id);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_IGNORED_CATEGORY_IDS)
|
||||
Call<ResponseArray<Integer>> getIgnoredCategoryIds();
|
||||
|
||||
@GET(ApiEndPoints.API_GET_PIZZA_CATEGORY_IDS)
|
||||
Call<ResponseArray<Integer>> getPizzaCategoryIds();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_REGISTER)
|
||||
Call<ResponseObject<UserModel>> register(@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_LOGIN)
|
||||
Call<ResponseObject<UserModel>> login(@Field("email") String email, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_LOGOUT)
|
||||
Call<ResponseObject> logout(@Field("token") String customerToken);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_ORDER_HISTORY)
|
||||
Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Query("token") String token);
|
||||
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProducts(@Url String url);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CartInfoModel>> getCartProductsForCommission(@Url String url,
|
||||
@Field("payment_method") String paymentMethodCode,
|
||||
@Field("shipping_method") String shippingMethodCode);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_CLEAR_CART)
|
||||
Call<ResponseObject> clearCart(@Query("token") String token);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_PRODUCTS_BY_CATEGORY)
|
||||
Call<ResponseArray<MenuProductModel>> getProductsByCategory(@Query("category_id") String categoryId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_GET_PRODUCT)
|
||||
Call<ResponseArray<MenuProductModel>> getProductById(@Field("product_id") int productId);
|
||||
|
||||
|
||||
// * Bu projedeki post servisler bizden form-data bekliyor. Bu serviste @FormUrlEncoded yapınca ve
|
||||
// * body'i @FieldMap HashMap<String, Object> body olarak verince, body içindeki alanlar
|
||||
// * encode ediliyor, mesela body içindeki "[" karakteri "%5D" ye falan dönüşüyor, dolayısı ile servis bunları okuyamıyor.
|
||||
// * Bu sebeple body olarak RequestBody verdim ve servisi çağırırken bod içindeki alanları FormBody olarak ekledim.
|
||||
@POST
|
||||
Call<ResponseObject<AddProductToBasketResponseModel>> addProductsToBasket(@Url String url,
|
||||
@Body RequestBody body);
|
||||
@GET(ApiEndPoints.API_GET_SHIPPING_METHODS)
|
||||
Call<ResponseArray<ShippingMethodModel>> getShippingMethods(@Query("token") String token);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_CUSTOMER_ADDRESSES)
|
||||
Call<ResponseArray<AddressModel>> getCustomerAddresses(@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<AddNewAddressResponseModel>> addNewAddress(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<DeleteAddressResponseModel>> deleteAddress(@Url String url,
|
||||
@Field("address_id") String addressId);
|
||||
@GET(ApiEndPoints.API_GET_PAYMENT_METHODS)
|
||||
Call<ResponseObject<PaymentMethodsResponseModel>> getPaymentMethods(@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<Integer>> createOrder(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_CHECK_UPDATE)
|
||||
Call<ResponseObject<AppVersionModel>> checkUpdate(@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_FORGOT_PASSWORD)
|
||||
Call<ResponseObject> forgotPassword(@Field("email") String emailAddress);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_CITY_LIST)
|
||||
Call<ResponseArray<CityModel>> getCityList();
|
||||
|
||||
@GET(ApiEndPoints.API_GET_COUNTRY_LIST)
|
||||
Call<ResponseArray<CountryModel>> getCountryList();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_GET_ZONE_LIST)
|
||||
Call<ResponseArray<ZoneModel>> getZoneList(@Field("country_id") String countryId);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_CUSTOMER_PROFILE)
|
||||
Call<ResponseObject<UserModel>> getCustomerProfile(@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> updatePassword(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<UserModel>> updateProfile(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<RemoveProductFromCartResponseModel>> removeProductFromCart(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
@GET(ApiEndPoints.API_GET_STORE_INFO)
|
||||
Call<ResponseObject<StoreInfoModel>> getStoreInfo();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseArray<OrderHistoryProductModel>> getOrderProductList(@Url String url,
|
||||
@Field("order_id") String orderId);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CheckCouponModel>> checkCoupon(@Url String url, @Field("coupon") String couponCode);
|
||||
|
||||
@GET(ApiEndPoints.API_CHECK_CAMPAIGN_PIZZAPASS)
|
||||
Call<ResponseObject<CampaignModel>> checkPizzapassCampaign(@Query("token") String token);
|
||||
|
||||
@GET(ApiEndPoints.API_CHECK_CAMPAIGN_KEBAPPASS)
|
||||
Call<ResponseObject<CampaignModel>> checkKebapPassCampaign(@Query("token") String token);
|
||||
|
||||
@GET(ApiEndPoints.API_CHECK_DELIVERY_TIME)
|
||||
Call<ResponseObject<Boolean>> checkDeliveryTime();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(ApiEndPoints.API_CHECK_DELIVERY_TIME)
|
||||
Call<ResponseObject<Boolean>> checkDeliveryTimeWithDateAndTime(@Field("delivery_date") String deliveryDateAndTime);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> createPayment(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject> repeatOrder(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@GET(ApiEndPoints.API_GET_STORE_LIST)
|
||||
Call<ResponseArray<StoreModel>> getStoreList();
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
69
app/src/main/java/ch/pizzacucia/android/api/ApiService.java
Normal file
69
app/src/main/java/ch/pizzacucia/android/api/ApiService.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ch.pizzacucia.android.BuildConfig;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class ApiService {
|
||||
|
||||
private static ApiService apiService = new ApiService();
|
||||
public static ApiInterface apiInterface;
|
||||
public static Retrofit retrofit;
|
||||
|
||||
private ApiService() { reset();}
|
||||
|
||||
public static ApiService getInstance() {
|
||||
return apiService;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.setLenient()
|
||||
.create();
|
||||
|
||||
|
||||
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
|
||||
builder.readTimeout(ApiConstants.API_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
builder.connectTimeout(ApiConstants.API_CONNECT_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
||||
builder.addInterceptor(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
|
||||
Request.Builder builder = chain.request().newBuilder();
|
||||
builder.addHeader("Content-Type", "application/json");
|
||||
|
||||
Request request = builder.build();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
});
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); // set your desired log level
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
if(BuildConfig.DEBUG){
|
||||
builder.addInterceptor(logging);
|
||||
}
|
||||
|
||||
OkHttpClient client = builder.build();
|
||||
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(ApiConstants.API_PATH)
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.client(client)
|
||||
.build();
|
||||
|
||||
apiInterface = retrofit.create(ApiInterface.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 22.10.2017.
|
||||
*/
|
||||
|
||||
public class BaseResponse implements Serializable {
|
||||
|
||||
@SerializedName("success") private boolean success;
|
||||
@SerializedName("message") private String message;
|
||||
@SerializedName("error_code") private int errorCode;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 05/10/2017.
|
||||
*/
|
||||
|
||||
public class ResponseArray<T> extends BaseResponse implements Serializable {
|
||||
|
||||
@SerializedName("data") private ArrayList<T> data;
|
||||
|
||||
public ArrayList<T> getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ch.pizzacucia.android.api;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 05/10/2017.
|
||||
*/
|
||||
|
||||
public class ResponseObject<T> extends BaseResponse implements Serializable {
|
||||
|
||||
@SerializedName("data") private T data;
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user