Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.tryingapp;
- import java.io.IOException;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.Response;
- /**
- * Created by DELL on 20/02/2017.
- */
- public class ConnectAndCommunicateWithServer {
- static OkHttpClient client = new OkHttpClient();
- final String BasicUrl = "http://aviyam1811.pythonanywhere.com";
- boolean updateFCMId(String FCMId , String mail) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("FCMId", FCMId)
- .add("mail", mail)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/updatefcmid")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- //TODO: look about the problem here
- System.out.println(response.body().string());
- return response.body().string().contains("Update FCMId succeeded!");
- }
- boolean register(String pass, String mail , String FCMId) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("mail", mail)
- .add("password", pass)
- .add("FCMId" , FCMId)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/register")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- return response.body().string().equals("Signup completed!");
- }
- boolean addNewContact(String mail , String additionalMail , String isFull) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("additionalMail", additionalMail)
- .add("mail", mail)
- .add("isFull" , isFull)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/addnewcontact")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- return response.body().string().contains("contact adding succeeded!");
- }
- boolean changeSO(String mail , String additionalMail , String isFull) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("additionalMail", additionalMail)
- .add("mail", mail)
- .add("isFull" , isFull)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/changeso")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- System.out.println(response.body().string());//TODO remove just for debug
- return response.body().string().contains("succeeded");
- }
- boolean deleteContact(String mail , String additionalMail) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("additionalMail", additionalMail)
- .add("mail", mail)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/deletecontact")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- System.out.println(response.body().string());
- return response.body().string().contains("succeeded!");//TODO check why return false
- }
- boolean emergencyCase(String mail) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("mail", mail)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/emergencycase")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- System.out.println(response.body().string());
- return response.body().string().equals("true");//TODO check why not notify
- }
- boolean fullCase(String mail) throws IOException {
- FormBody formBody = new FormBody.Builder()
- .add("mail", mail)
- .build();
- okhttp3.Request request = new Request.Builder()
- .url(BasicUrl + "/fullcase")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- return response.body().string().equals("true");
- }
- //just for debug
- public static void main(String[] args) throws IOException {
- ConnectAndCommunicateWithServer example = new ConnectAndCommunicateWithServer();
- // issue the post request - register
- //System.out.println(example.register("fromMainIntryingApp2" , "Good"));
- //System.out.println(example.addNewContact("aviyam1811@walla.com" ,"yael1709@gmail.com" , "true"));
- //System.out.println(example.changeSO("ivgi1234@walla.com" ,"xhdhdhh@hdjdhdb.com" , "good"));
- //System.out.println(example.deleteContact("aviyam1811@walla.com" ,"yael1709@gmail.com"));
- System.out.println(example.emergencyCase("aviyam1811@walla.com"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement