Exemplo n.º 1
0
        public Boolean ValidateCredentials(User user)
        {
            Boolean result = true;

            if (user != null)
            {
                if (user.getUser() == null || user.getUser().Equals(""))
                    throw new EmptyFieldUserException("User/Mail is empty");

                if (user.getPassword() == null || user.getPassword().Equals(""))
                    throw new EmptyFieldPassException("Password is empty");
            }
            else
                throw new EmptyFieldPassException("User is null");

            return result;
        }
Exemplo n.º 2
0
        public static User parseJsonToUser(string json)
        {

            Dictionary<string, object> aux = parseJsonToDictionary(json);

            User user = new User();
            JObject jCredentials = (JObject)aux["Credentials"];
            JObject jresultado = (JObject)jCredentials["resultado"];

            if ((int)jresultado["codigoResultado"] != 0){
                    throw new ResponseException((string)jresultado["mensajeKey"] + " - " + (string)jresultado["mensajeResultado"]);
            }else{
                    user.setApiKey((string)jCredentials["APIKey"]);
                    user.setMerchant((string)jCredentials["merchantId"]);
            }

            return user;
        }
Exemplo n.º 3
0
         public User getCredentials(User user){ 

             string URL = endpoint + CREDENTIALS;
             URL = URL.Replace("t/1.1/", "");
             User userResponse = new User();
             string result;

             var httpWebRequest = generateHttpWebRequest(URL, CONTENT_TYPE_APP_JSON, METHOD_POST,false);

             using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())){
                 string json = JsonConvert.SerializeObject(user.toDictionary(), Newtonsoft.Json.Formatting.Indented);
                 streamWriter.Write(json);
                 //System.Console.WriteLine(json);
             }

             var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
             using (var streamReader = new StreamReader(httpResponse.GetResponseStream())){
                 result = streamReader.ReadToEnd();
                 //System.Console.WriteLine(result);
             }
             userResponse = OperationsParser.parseJsonToUser(result);
             return userResponse;
         }
Exemplo n.º 4
0
        public User getCredentials(User user)
        {
            User result = user;
            CredentialsValidate cv = new CredentialsValidate();

            if (cv.ValidateCredentials(user))
                result = todoPagoClient.getCredentials(user);

            return result;		
        }
Exemplo n.º 5
0
 private User getUser()
 {
     String mail = "*****@*****.**";
     String pass = "******";
     User user = new User(mail, pass);
     return user;
 }
Exemplo n.º 6
0
            public void getCredentials()
            {
                User user = new User();

                try {
                     user = connector.getCredentials(getUser());
                     connector.setAuthorize(user.getApiKey());
                }
                     catch (EmptyFieldException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                     catch (ResponseException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine(user.toString()); 
            }