initial commit

This commit is contained in:
2017-09-11 23:04:34 +03:00
commit 1f233d977b
62 changed files with 1451 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package ch.pizzalink.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 = "";
}

View File

@@ -0,0 +1,6 @@
package ch.pizzalink.android.api;
public class ApiEndPoints {
private static final String PREFIX = "services/admin/index.php?route=services/news/";
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories";
}

View File

@@ -0,0 +1,43 @@
package ch.pizzalink.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;
}
}

View File

@@ -0,0 +1,26 @@
package ch.pizzalink.android.api;
import java.io.IOException;
import java.lang.annotation.Annotation;
import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.helper.DialogHelper;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Response;
public class ApiErrorUtils {
public static ApiError parseError(Response<?> response) {
Converter<ResponseBody, ApiError> converter = ApiService.retrofit.responseBodyConverter(ApiError.class, new Annotation[0]);
ApiError error = new ApiError();
error.setStatusCode(response.code());
try {
error = converter.convert(response.errorBody());
DialogHelper.showDialogWithPositiveButton(BaseActivity.currentActivity, error.getMessage());
} catch (IOException e) {
return error;
}
return error;
}
}

View File

@@ -0,0 +1,125 @@
package ch.pizzalink.android.api;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
/**
* Created by cimenmus on 04/02/2017.
*/
public interface ApiInterface {
/*
@GET(ApiEndPoints.API_GET_ALL_CATEGORIES)
Call<CategoryListResponseModel> getAllCategories();
@GET(ApiEndPoints.API_GET_ALL_AUTHORS)
Call<AuthorListResponseModel> getAllAuthors();
@GET(ApiEndPoints.API_GET_MAGAZINES)
Call<MagazineListResponseModel> getMagazineList();
@GET(ApiEndPoints.API_GET_MAIN_PAGE_NEWS)
Call<NewsListResponseModel> getMainPageNews();
@GET(ApiEndPoints.API_GET_NEWS_LIST_BY_CATEGORY)
Call<NewsListResponseModel> getNewsListByCategory(@Query("category_id") String categoryId);
@GET(ApiEndPoints.API_GET_NEWS_DETAILS)
Call<NewsDetailsResponseModel> getNewsDetails(@Query("article_id") String articleId);
@GET(ApiEndPoints.API_GET_NEWS_DETAILS)
Call<NewsDetailsResponseModel> getVideoNewsDetails(@Query("article_id") String articleId, @Query("video") String video);
@GET(ApiEndPoints.API_GET_TAGS_OF_NEWS)
Call<NewsDetailsResponseModel> getTagsOfNews(@Query("getTagsByArticle") String articleId);
// NOT : tag ları yazarken boşluk yerine %20 işreti koy
@GET(ApiEndPoints.API_GET_NEWS_LIST_BY_TAG)
Call<NewsListResponseModel> getNewsListByTag(@Query("tag_name") String tagName);
@GET(ApiEndPoints.API_GET_ARTICLES_OF_AUTHOR)
Call<NewsListResponseModel> getArticlesOfAuthor(@Query("author_id") String authorId);
@GET(ApiEndPoints.API_GET_ARTICLE_DETAILS)
Call<NewsDetailsResponseModel> getArticleDetails(@Query("article_id") String articleId);
@GET(ApiEndPoints.API_GET_EVENT_LOCATIONS)
Call<EventLocationListResponseModel> getEventLocations();
@GET(ApiEndPoints.API_GET_CURRENT_EVENTS)
Call<EventListResponseModel> getCurrentEvents();
@GET(ApiEndPoints.API_GET_CURRENT_EVENTS)
Call<EventListResponseModel> getCurrentEvents(@Query("location") String locationName);
@GET(ApiEndPoints.API_GET_UPCOMING_EVENTS)
Call<EventListResponseModel> getUpcomingEvents(@Query("day") String dayCount);
@GET(ApiEndPoints.API_GET_UPCOMING_EVENTS)
Call<EventListResponseModel> getUpcomingEvents(@Query("day") String dayCount, @Query("location") String locationName);
@GET(ApiEndPoints.API_GET_SQUARE_ADS)
Call<AdResponseModel> getSquareAds();
@GET(ApiEndPoints.API_GET_BANNER_ADS)
Call<AdResponseModel> getBannerAds();
@FormUrlEncoded
@POST(ApiEndPoints.API_CUSTOMER_LOGIN)
Call<LoginCustomerResponseModel> loginUser(@Field("email") String email, @Field("password") String password);
@FormUrlEncoded
@POST(ApiEndPoints.API_CUSTOMER_LOG_OUT)
Call<ResponseModel> logoutUser(@Field("token") String customerToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_REGISTER_CUSTOMER)
Call<LoginCustomerResponseModel> registerCustomer(@Field("customer_name") String name, @Field("customer_surname") String surname,
@Field("customer_mail") String email, @Field("customer_phone") String phone,
@Field("customer_password") String password);
@FormUrlEncoded
@POST(ApiEndPoints.API_GET_CUSTOMER_INFO)
Call<CustomerInfoResponseModel> getCustomerInfo(@Field("token") String customerToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_GET_STORE_CUSTOMER_INFO)
Call<StoreCustomerInfoResponseModel> getStoreCustomerInfo(@Field("token") String customerToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_REFRESH_CUSTOMER_TOKEN)
Call<RefreshTokenResponseModel> refreshCustomerToken(@Field("refresh_token") String refreshToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_REFRESH_STORE_CUSTOMER_TOKEN)
Call<RefreshTokenResponseModel> refreshStoreCustomerToken(@Field("refresh_token") String refreshToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_GET_ALL_CAMPAIGNS)
Call<AllCampaignsResponseModel> getAllCampaigns(@Field("token") String customerToken);
@FormUrlEncoded
@POST(ApiEndPoints.API_GET_CAMPAIGN_DETAILS)
Call<AllCampaignsResponseModel> getCampaignDetails(@Field("token") String customerToken,
@Field("campaign_id") String campaignId);
@FormUrlEncoded
@POST(ApiEndPoints.API_GET_CAMPAIGN_LIST_OF_COMPANY)
Call<AllCampaignsResponseModel> getCampaingsOfCompany(@Field("token") String customerToken,
@Field("firm_barcode") String firmBarcode);
@FormUrlEncoded
@POST(ApiEndPoints.API_STORE_CUSTOMER_LOGIN)
Call<LoginStoreCustomerResponseModel> loginStoreCustomer(@Field("username") String email, @Field("password") String password);
@POST(ApiEndPoints.API_CUSTOMER_LOGIN)
Call<LoginCustomerResponseModel> loginUser(@Body HashMap<String, Object> body);
*/
}

View File

@@ -0,0 +1,59 @@
package ch.pizzalink.android.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
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()
.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);
}
});
OkHttpClient client = builder.build();
retrofit = new Retrofit.Builder()
.baseUrl(ApiConstants.API_PATH)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();
apiInterface = retrofit.create(ApiInterface.class);
}
}