/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 Vincent Zhang/PhoenixLAB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package co.phoenixlab.discord.api.impl;

import co.phoenixlab.discord.api.endpoints.AuthenticationEndpoint;
import co.phoenixlab.discord.api.endpoints.GatewayEndpoint;
import co.phoenixlab.discord.api.endpoints.async.AuthenticationEndpointAsync;
import co.phoenixlab.discord.api.endpoints.async.GatewayEndpointAsync;
import co.phoenixlab.discord.api.entities.TokenResponse;
import co.phoenixlab.discord.api.entities.WebsocketEndpointResponse;
import co.phoenixlab.discord.api.exceptions.ApiException;
import co.phoenixlab.discord.api.request.EmailPasswordLoginRequest;
import co.phoenixlab.discord.api.request.LogoutRequest;
import com.google.gson.Gson;
import com.google.inject.Inject;
import com.mashape.unirest.http.HttpResponse;

import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;

import static co.phoenixlab.discord.api.impl.EndpointsImpl.*;

public class LoginEndpointsImpl
        implements AuthenticationEndpoint, AuthenticationEndpointAsync,
        GatewayEndpoint, GatewayEndpointAsync {

    private static final String LOGIN_ENDPOINT = "/auth/login";
    private static final String LOGOUT_ENDPOINT = "/auth/login";
    private static final String GATEWAY_ENDPOINT = "/gateway";

    @Inject
    private ScheduledExecutorService executorService;
    @Inject
    private EndpointsImpl endpoints;
    @Inject
    private Gson gson;

    @Override
    public TokenResponse logIn(EmailPasswordLoginRequest request) throws ApiException {
        try {
            HttpResponse<String> response =
                    endpoints.defaultPostUnauth(BASE_URL + LOGIN_ENDPOINT, gson.toJson(request));
            return gson.fromJson(response.getBody(), TokenResponse.class);
        } catch (Exception e) {
            throw new ApiException(LOGIN_ENDPOINT, e);
        }
    }

    @Override
    public void logOut(LogoutRequest request) throws ApiException {
        try {
            HttpResponse<String> response =
                    endpoints.defaultPostUnauth(BASE_URL + LOGOUT_ENDPOINT, gson.toJson(request));
        } catch (Exception e) {
            throw new ApiException(LOGOUT_ENDPOINT, e);
        }
    }

    @Override
    public Future<TokenResponse> logInAsync(EmailPasswordLoginRequest request) throws ApiException {
        return executorService.submit(() -> logIn(request));
    }

    @Override
    public Future<Void> logOutAsync(LogoutRequest request) throws ApiException {
        return executorService.submit(() -> logOut(request), null);
    }

    @Override
    public WebsocketEndpointResponse getGateway() throws ApiException {

        return null;
    }

    @Override
    public Future<WebsocketEndpointResponse> getGatewayAsync() throws ApiException {
        return null;
    }
}

@@ -1762,96 +1762,21 @@
 gle.
-gson.Gson;%0Aimport com.google.inject.Inject;%0Aimport com.mashape.unirest.http.HttpResponse
+inject.Inject
 ;%0A%0Ai
@@ -1924,17 +1924,135 @@
 ntsImpl.
-*
+BASE_URL;%0Aimport static com.mashape.unirest.http.HttpMethod.GET;%0Aimport static com.mashape.unirest.http.HttpMethod.POST
 ;%0A%0Apubli
@@ -2510,43 +2510,8 @@
 nts;
-%0A    @Inject%0A    private Gson gson;
 %0A%0A  
@@ -2640,59 +2640,14 @@
     
-HttpResponse%3CString%3E response =%0A                   
+return
  end
@@ -2702,82 +2702,15 @@
 NT, 
-gson.toJson(request));%0A            return gson.fromJson(response.getBody()
+request
 , To
@@ -2796,16 +2796,22 @@
 ception(
+POST, 
 LOGIN_EN
@@ -2939,60 +2939,8 @@
 y %7B%0A
-            HttpResponse%3CString%3E response =%0A        
     
@@ -3007,28 +3007,27 @@
 NT, 
-gson.toJson(request)
+request, Void.class
 );%0A 
@@ -3092,16 +3092,22 @@
 ception(
+POST, 
 LOGOUT_E
@@ -3575,16 +3575,29 @@
 ption %7B%0A
+        try %7B
 %0A       
@@ -3593,36 +3593,222 @@
 y %7B%0A        
+    
 return 
-null;
+endpoints.defaultGet(BASE_URL + GATEWAY_ENDPOINT, WebsocketEndpointResponse.class);%0A        %7D catch (Exception e) %7B%0A            throw new ApiException(GET, GATEWAY_ENDPOINT, e);%0A        %7D
 %0A    %7D%0A%0A    
@@ -3917,20 +3917,56 @@
  return 
-null
+executorService.submit(this::getGateway)
 ;%0A    %7D%0A

Implement getting gateway