/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.parallax.client.cloudsession;

import com.github.kevinsawicki.http.HttpRequest;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.parallax.client.cloudsession.exceptions.UnknownUserException;
import com.parallax.client.cloudsession.objects.User;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Michel
 */
public class CloudSessionUserService {

    private final String BASE_URL;

    public CloudSessionUserService(String baseUrl) {
        this.BASE_URL = baseUrl;
    }

    public User getUser(String email) throws UnknownUserException {
        Map<String, String> data = new HashMap<>();
        data.put("email", email);
        HttpRequest request = HttpRequest.get(getUrl("user/email/" + email));
//        int responseCode = request.code();
//        System.out.println("Response code: " + responseCode);
        String response = request.body();
//        System.out.println(response);
        JsonElement jelement = new JsonParser().parse(response);
        JsonObject responseObject = jelement.getAsJsonObject();
        if (responseObject.get("success").getAsBoolean()) {
            JsonObject userJson = responseObject.get("user").getAsJsonObject();
            User user = new User();
            user.setId(userJson.get("id").getAsLong());
            user.setEmail(userJson.get("email").getAsString());
            user.setLocale(userJson.get("locale").getAsString());
            user.setScreenname(userJson.get("screenname").getAsString());
            return user;
        } else {
            String message = responseObject.get("message").getAsString();
            switch (responseObject.get("code").getAsInt()) {
                case 400:
                    throw new UnknownUserException(email, message);
            }
            System.out.println(response);
            return null;
        }
    }

    private String getUrl(String actionUrl) {
        return BASE_URL + actionUrl;
    }

}

@@ -449,16 +449,91 @@
 eption;%0A
+import com.parallax.client.cloudsession.exceptions.UnknownUserIdException;%0A
 import c
@@ -2178,24 +2178,1433 @@
    %7D%0A    %7D%0A%0A
+    public User changeUserInfo(Long idUser, String screenname) throws UnknownUserIdException %7B%0A        Map%3CString, String%3E data = new HashMap%3C%3E();%0A        data.put(%22screenname%22, screenname);%0A        HttpRequest request = HttpRequest.post(getUrl(%22user/info/%22 + idUser)).form(data);%0A//        int responseCode = request.code();%0A//        System.out.println(%22Response code: %22 + responseCode);%0A        String response = request.body();%0A//        System.out.println(response);%0A        JsonElement jelement = new JsonParser().parse(response);%0A        JsonObject responseObject = jelement.getAsJsonObject();%0A        if (responseObject.get(%22success%22).getAsBoolean()) %7B%0A            JsonObject userJson = responseObject.get(%22user%22).getAsJsonObject();%0A            User user = new User();%0A            user.setId(userJson.get(%22id%22).getAsLong());%0A            user.setEmail(userJson.get(%22email%22).getAsString());%0A            user.setLocale(userJson.get(%22locale%22).getAsString());%0A            user.setScreenname(userJson.get(%22screenname%22).getAsString());%0A            return user;%0A        %7D else %7B%0A            String message = responseObject.get(%22message%22).getAsString();%0A            switch (responseObject.get(%22code%22).getAsInt()) %7B%0A                case 400:%0A                    throw new UnknownUserIdException(idUser, message);%0A            %7D%0A            System.out.println(response);%0A            return null;%0A        %7D%0A    %7D%0A%0A
     private 

Change user info