public async Task <IEnumerable <License> > GetLicensesAsync()
        {
            const string BASEURL          = "https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json";
            const string USERAGENT_HEADER = "User-Agent";
            const string USERAGENT_VALUE  = "LicenseTracker";

            var results = new List <License>();
            var list    = await BASEURL
                          .WithHeader(USERAGENT_HEADER, USERAGENT_VALUE)
                          .GetJsonAsync <LicenseInfoList>();

            foreach (var licenseInfo in list.Licenses)
            {
                var fullLicenseInfo = await licenseInfo.DetailsUrl
                                      .WithHeader(USERAGENT_HEADER, USERAGENT_VALUE)
                                      .GetJsonAsync <FullLicenseInfo>();

                results.Add(new License
                {
                    Key  = fullLicenseInfo.LicenseId,
                    Name = fullLicenseInfo.Name,
                    Text = fullLicenseInfo.StandardLicenseTemplate
                });
            }

            return(results);
        }
Exemple #2
0
        public async Task <IEnumerable <License> > GetLicensesAsync()
        {
            const string BASEURL          = "https://api.github.com/licenses";
            const string USERAGENT_HEADER = "User-Agent";
            const string USERAGENT_VALUE  = "LicenseTracker";

            var results = new List <License>();
            var list    = await BASEURL
                          .WithHeader(USERAGENT_HEADER, USERAGENT_VALUE)
                          .GetJsonAsync <IEnumerable <LicenseInfo> >();

            foreach (var licenseInfo in list)
            {
                var fullLicenseInfo = await licenseInfo.Url
                                      .WithHeader(USERAGENT_HEADER, USERAGENT_VALUE)
                                      .GetJsonAsync <FullLicenseInfo>();

                results.Add(new License
                {
                    Key  = fullLicenseInfo.SpdxId,
                    Name = fullLicenseInfo.Name,
                    Text = fullLicenseInfo.Body
                });
            }

            return(results);
        }
Exemple #3
0
        public async Task <License> GetLicenseAsync(string packageName, string version)
        {
            const string BASEURL = "https://registry.npmjs.org";

            try
            {
                string licenseName = (await BASEURL
                                      .AppendPathSegment($"{packageName.ToLowerInvariant()}")
                                      .AppendPathSegment(version)
                                      .GetJsonAsync <PackageInfo>())
                                     .License;

                return(_knownLicenses
                       .FirstOrDefault(x => x.Key == licenseName || x.Name == licenseName));
            }
            catch
            {
                return(null);
            }
        }