Ejemplo n.º 1
0
        /// <summary>
        /// Get vehicles of specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <param name="styles"></param>
        /// <returns>VehicleInfo array</returns>
        public static async Task <IEnumerable <VehicleInfo> > GetPersonVehiclesAsync(this EsiaClient client, string oid, SendStyles styles = SendStyles.Normal)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri = String.Format("{0}{1}/{2}?embed=(elements)", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid,
                                       client.Options.VhlsSfx);
            var response = await client.GetAsync(uri, styles);

            IDictionary <string, JToken> vehicleDictionary = JObject.Parse(response);
            var result = new List <VehicleInfo>();

            if (vehicleDictionary != null && vehicleDictionary.ContainsKey("elements"))
            {
                foreach (var vehicle in vehicleDictionary["elements"])
                {
                    var vehicleObject = vehicle as JObject;

                    if (vehicleObject != null)
                    {
                        result.Add(new VehicleInfo(vehicleObject));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void Parse(string accessToken)
        {
            string[] parts         = accessToken.Split('.');
            string   payload       = Encoding.UTF8.GetString(Base64Decode(parts[1]));
            JObject  payloadObject = JObject.Parse(payload);

            Sid   = EsiaHelpers.PropertyValueIfExists("urn:esia:sid", payloadObject);
            SbjId = EsiaHelpers.PropertyValueIfExists("urn:esia:sbj_id", payloadObject);

            double seconds;
            string value = EsiaHelpers.PropertyValueIfExists("exp", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                EndDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }

            value = EsiaHelpers.PropertyValueIfExists("nbf", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                BeginDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }

            value = EsiaHelpers.PropertyValueIfExists("iat", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                CreateDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }
        }
Ejemplo n.º 3
0
        public AddrInfo(JObject addrInfo)
        {
            if (addrInfo != null)
            {
                var value = EsiaHelpers.PropertyValueIfExists("type", addrInfo);

                switch (value)
                {
                case "PLV":
                    AddrType = AddrType.Residential;
                    break;

                default:
                    AddrType = AddrType.Registration;
                    break;
                }

                ZipCode            = EsiaHelpers.PropertyValueIfExists("zipCode", addrInfo);
                CountryId          = EsiaHelpers.PropertyValueIfExists("countryId", addrInfo);
                AddressStr         = EsiaHelpers.PropertyValueIfExists("addressStr", addrInfo);
                Building           = EsiaHelpers.PropertyValueIfExists("building", addrInfo);
                Frame              = EsiaHelpers.PropertyValueIfExists("frame", addrInfo);
                House              = EsiaHelpers.PropertyValueIfExists("house", addrInfo);
                Flat               = EsiaHelpers.PropertyValueIfExists("flat", addrInfo);
                FiasCode           = EsiaHelpers.PropertyValueIfExists("fiasCode", addrInfo);
                Region             = EsiaHelpers.PropertyValueIfExists("region", addrInfo);
                City               = EsiaHelpers.PropertyValueIfExists("city", addrInfo);
                District           = EsiaHelpers.PropertyValueIfExists("district", addrInfo);
                Area               = EsiaHelpers.PropertyValueIfExists("area", addrInfo);
                Settlement         = EsiaHelpers.PropertyValueIfExists("settlement", addrInfo);
                AdditionArea       = EsiaHelpers.PropertyValueIfExists("additionArea", addrInfo);
                AdditionAreaStreet = EsiaHelpers.PropertyValueIfExists("additionAreaStreet", addrInfo);
                Street             = EsiaHelpers.PropertyValueIfExists("street", addrInfo);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get child documents of specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <param name="styles"></param>
        /// <returns>DocInfo array</returns>
        public static async Task <IEnumerable <DocInfo> > GetPersonChildDocsAsync(this EsiaClient client, string oid, string childOid,
                                                                                  SendStyles styles = SendStyles.Normal)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri = String.Format("{0}{1}/{2}/{3}/{4}?embed=(elements)", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid,
                                       client.Options.KidsSfx, childOid, client.Options.DocsSfx);
            var response = await client.GetAsync(uri, styles);

            IDictionary <string, JToken> docDictionary = JObject.Parse(response);
            var result = new List <DocInfo>();

            if (docDictionary != null && docDictionary.ContainsKey("elements"))
            {
                foreach (var doc in docDictionary["elements"])
                {
                    var docObject = doc as JObject;

                    if (docObject != null)
                    {
                        result.Add(new DocInfo(docObject));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get children of specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <returns>PersonInfo array</returns>
        public static async Task <IEnumerable <PersonInfo> > GetPersonKidsAsync(this EsiaClient client, string oid)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri = String.Format("{0}{1}/{2}?embed=(elements)", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid,
                                       client.Options.KidsSfx);
            var result   = new List <PersonInfo>();
            var response = await client.GetAsync(uri);

            if (response != null)
            {
                IDictionary <string, JToken> kidsDictionary = JObject.Parse(response);

                if (kidsDictionary != null && kidsDictionary.ContainsKey("elements"))
                {
                    foreach (var child in kidsDictionary["elements"])
                    {
                        var childObject = child as JObject;

                        if (childObject != null)
                        {
                            result.Add(new PersonInfo(childObject));
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get addresses of specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <param name="styles"></param>
        /// <returns>AddrInfo array</returns>
        public static IEnumerable <AddrInfo> GetPersonAddrsAsync(this EsiaClient client, string oid, SendStyles styles = SendStyles.Normal)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri = String.Format("{0}{1}/{2}?embed=(elements)", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid,
                                       client.Options.AddrsSfx);
            var result   = new List <AddrInfo>();
            var response = client.GetAsync(uri, styles);

            if (response != null)
            {
                IDictionary <string, JToken> addrDictionary = JObject.Parse(response);

                if (addrDictionary != null && addrDictionary.ContainsKey("elements"))
                {
                    foreach (var addr in addrDictionary["elements"])
                    {
                        var addrObject = addr as JObject;

                        if (addrObject != null)
                        {
                            result.Add(new AddrInfo(addrObject));
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public DocInfo(JObject docInfo)
        {
            DocType = DocType.None;

            if (docInfo != null)
            {
                var value = EsiaHelpers.PropertyValueIfExists("type", docInfo);

                switch (value)
                {
                case "RF_PASSPORT":
                    DocType = DocType.Passport;
                    break;

                case "FID_DOC":
                    DocType = DocType.Foreign;
                    break;

                case "RF_DRIVING_LICENSE":
                    DocType = DocType.DrivingLicense;
                    break;

                case "MLTR_ID":
                    DocType = DocType.Military;
                    break;

                case "FRGN_PASS":
                    DocType = DocType.ForeignPassport;
                    break;

                case "MDCL_PLCY":
                    DocType = DocType.MedicalPolicy;
                    break;

                case "BRTH_CERT":
                    DocType = DocType.BirthCert;
                    break;

                default:
                    DocType = DocType.None;
                    break;
                }

                Verified = docInfo["vrfStu"].Value <string>() == "VERIFIED";

                Series     = EsiaHelpers.PropertyValueIfExists("series", docInfo);
                Number     = EsiaHelpers.PropertyValueIfExists("number", docInfo);
                IssueDate  = EsiaHelpers.PropertyValueIfExists("issueDate", docInfo);
                IssueId    = EsiaHelpers.PropertyValueIfExists("issueId", docInfo);
                IssuedBy   = EsiaHelpers.PropertyValueIfExists("issuedBy", docInfo);
                ExpiryDate = EsiaHelpers.PropertyValueIfExists("expiryDate", docInfo);
                FirstName  = EsiaHelpers.PropertyValueIfExists("firstName", docInfo);
                LastName   = EsiaHelpers.PropertyValueIfExists("lastName", docInfo);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get personal information about specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <param name="styles"></param>
        /// <returns>PersonInfo instance</returns>
        public static async Task <PersonInfo> GetPersonInfoAsync(this EsiaClient client, string oid, SendStyles styles = SendStyles.Normal)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri      = String.Format("{0}{1}", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid);
            var    response = await client.GetAsync(uri, styles);

            return(new PersonInfo(JObject.Parse(response)));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get contacts of specified user
        /// </summary>
        /// <param name="client"></param>
        /// <param name="oid">User oid</param>
        /// <returns>ContactInfo array</returns>
        public static async Task <IEnumerable <ContactInfo> > GetPersonContactsAsync(this EsiaClient client, string oid)
        {
            if (String.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            string uri = String.Format("{0}{1}/{2}?embed=(elements)", EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx), oid,
                                       client.Options.CttsSfx);
            var result   = new List <ContactInfo>();
            var response = await client.GetAsync(uri);

            if (response != null)
            {
                IDictionary <string, JToken> contactsDictionary = JObject.Parse(response);

                if (contactsDictionary != null && contactsDictionary.ContainsKey("elements"))
                {
                    foreach (var contact in contactsDictionary["elements"])
                    {
                        var         type = contact["type"].Value <string>();
                        ContactType contactType;

                        switch (type)
                        {
                        case "MBT":
                            contactType = ContactType.Mobile;
                            break;

                        case "EML":
                            contactType = ContactType.Email;
                            break;

                        case "CEM":
                            contactType = ContactType.Cem;
                            break;

                        case "PHN":
                        default:
                            contactType = ContactType.Phone;
                            break;
                        }

                        result.Add(new ContactInfo(contactType, contact["value"].Value <string>(), contact["vrfStu"].Value <string>() == "VERIFIED"));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        public VehicleInfo(JObject vehicleInfo)
        {
            if (vehicleInfo != null)
            {
                Id          = EsiaHelpers.PropertyValueIfExists("id", vehicleInfo);
                Name        = EsiaHelpers.PropertyValueIfExists("name", vehicleInfo);
                NumberPlate = EsiaHelpers.PropertyValueIfExists("numberPlate", vehicleInfo);

                var regObject = vehicleInfo["regCertificate"] as JObject;

                if (regObject != null)
                {
                    RegSeries = EsiaHelpers.PropertyValueIfExists("series", regObject);
                    RegNumber = EsiaHelpers.PropertyValueIfExists("number", regObject);
                }
            }
        }
Ejemplo n.º 11
0
        internal PersonInfo(JObject personInfo)
        {
            if (personInfo != null)
            {
                Id          = EsiaHelpers.PropertyValueIfExists("id", personInfo);
                FirstName   = EsiaHelpers.PropertyValueIfExists("firstName", personInfo);
                LastName    = EsiaHelpers.PropertyValueIfExists("lastName", personInfo);
                MiddleName  = EsiaHelpers.PropertyValueIfExists("middleName", personInfo);
                BirthPlace  = EsiaHelpers.PropertyValueIfExists("birthPlace", personInfo);
                Gender      = EsiaHelpers.PropertyValueIfExists("gender", personInfo);
                Citizenship = EsiaHelpers.PropertyValueIfExists("citizenship", personInfo);
                Snils       = EsiaHelpers.PropertyValueIfExists("snils", personInfo);
                Inn         = EsiaHelpers.PropertyValueIfExists("inn", personInfo);

                var value = EsiaHelpers.PropertyValueIfExists("trusted", personInfo);

                Trusted = !String.IsNullOrWhiteSpace(value) && value.ToLowerInvariant() == "true";

                if (!String.IsNullOrWhiteSpace(LastName))
                {
                    Name = LastName;

                    if (!String.IsNullOrWhiteSpace(FirstName))
                    {
                        Name = String.Format("{0} {1}", Name, FirstName);
                    }
                    if (!String.IsNullOrWhiteSpace(MiddleName))
                    {
                        Name = String.Format("{0} {1}", Name, MiddleName);
                    }
                }

                value = EsiaHelpers.PropertyValueIfExists("birthDate", personInfo);

                DateTime date;

                if (DateTime.TryParse(value, new CultureInfo("ru-RU"), DateTimeStyles.AssumeLocal, out date))
                {
                    BirthDate = date;
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initialize a new instance with access token parameters
        /// </summary>
        /// <param name="accessToken">Access token</param>
        /// <param name="refreshToken">Refresh token</param>
        /// <param name="expiresIn">Expires in</param>
        /// <param name="payload">Payload object to parse</param>
        public EsiaToken(string accessToken, string refreshToken, string expiresIn, JObject payload) : this(accessToken)
        {
            RefreshToken = refreshToken;

            int expiresValue;

            if (Int32.TryParse(expiresIn, NumberStyles.Integer, CultureInfo.InvariantCulture, out expiresValue))
            {
                ExpiresIn = TimeSpan.FromSeconds(expiresValue);
            }

            if (payload != null)
            {
                Sid   = EsiaHelpers.PropertyValueIfExists("urn:esia:sid", payload);
                SbjId = EsiaHelpers.PropertyValueIfExists("urn:esia:sbj_id", payload);

                double seconds;
                string value = EsiaHelpers.PropertyValueIfExists("exp", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    EndDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }

                value = EsiaHelpers.PropertyValueIfExists("nbf", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    BeginDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }

                value = EsiaHelpers.PropertyValueIfExists("iat", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    CreateDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }
            }
        }