Ejemplo n.º 1
0
        public OutputBaseClass GenerateToken()
        {
            OutputBaseClass res = new OutputBaseClass();

            res.status    = true;
            res.http_code = "200";
            AngelTokenResponse restoken = new AngelTokenResponse();

            try
            {
                AngelToken Token = this.Token;
                if (Token != null)
                {
                    if (ValidateToken(Token))
                    {
                        string URL = APIURL + "/rest/auth/angelbroking/jwt/v1/generateTokens";

                        string PostData = "{\"refreshToken\":\"" + Token.refreshToken + "\"}";

                        string json = POSTWebRequest(Token, URL, PostData);
                        if (!json.Contains("PostError:"))
                        {
                            restoken          = JsonConvert.DeserializeObject <AngelTokenResponse>(json);
                            res.TokenResponse = restoken.data;
                            res.status        = restoken.status;
                            res.http_error    = restoken.message;
                            res.http_code     = restoken.errorcode;
                            this.Token        = restoken.data;
                        }
                        else
                        {
                            res.status     = false;
                            res.http_code  = "404";
                            res.http_error = json.Replace("PostError:", "");
                        }
                    }
                    else
                    {
                        res.status     = false;
                        res.http_code  = "404";
                        res.http_error = "The token is invalid";
                    }
                }
                else
                {
                    res.status     = false;
                    res.http_code  = "404";
                    res.http_error = "The token is invalid";
                }
            }
            catch (Exception ex)
            {
                res.status     = false;
                res.http_code  = "404";
                res.http_error = ex.Message;
            }
            return(res);
        }
Ejemplo n.º 2
0
        /*User Calls*/
        public OutputBaseClass GenerateSession(string clientcode, string password)
        {
            OutputBaseClass res = new OutputBaseClass();

            res.status    = true;
            res.http_code = "200";
            try
            {
                AngelTokenResponse agr = new AngelTokenResponse();

                string URL = APIURL + "/rest/auth/angelbroking/user/v1/loginByPassword";

                string PostData = "{\"clientcode\":\"" + clientcode + "\",\"password\":\"" + password + "\"}";

                string json = POSTWebRequest(null, URL, PostData);
                if (!json.Contains("PostError:"))
                {
                    agr = JsonConvert.DeserializeObject <AngelTokenResponse>(json);
                    res.TokenResponse = agr.data;
                    res.status        = agr.status;
                    res.http_error    = agr.message;
                    res.http_code     = agr.errorcode;
                    this.Token        = agr.data;
                }
                else
                {
                    res.status     = false;
                    res.http_code  = "404";
                    res.http_error = json.Replace("PostError:", "");
                }
            }
            catch (Exception ex)
            {
                res.status     = false;
                res.http_code  = "404";
                res.http_error = ex.Message;
            }
            return(res);
        }