diff --git a/.github/workflows/dotnet-build-and-tests.yml b/.github/workflows/dotnet-build-and-tests.yml new file mode 100644 index 0000000..89e69d7 --- /dev/null +++ b/.github/workflows/dotnet-build-and-tests.yml @@ -0,0 +1,26 @@ +name: Build & Tests + +on: [push] + +jobs: + build: + + name: Run Build & Tests + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ubuntu-latest] + dotnet-version: ['6.0.x'] + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET ${{ matrix.dotnet-version }} + uses: actions/setup-dotnet@v1.7.2 + with: + dotnet-version: ${{ matrix.dotnet-version }} + - name: Install dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-restore --verbosity normal diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml deleted file mode 100644 index a0f1b1d..0000000 --- a/.github/workflows/dotnetcore.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: .NET Core - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.2.108 - - name: Build Projects - run: dotnet build --configuration Release - - name: Run Tests - run: dotnet test --configuration Release diff --git a/BinInfo.Tests/BinInfo.Tests.csproj b/BinInfo.Tests/BinInfo.Tests.csproj index 17ee479..aac7e02 100644 --- a/BinInfo.Tests/BinInfo.Tests.csproj +++ b/BinInfo.Tests/BinInfo.Tests.csproj @@ -1,16 +1,22 @@ - netcoreapp2.0 + net6.0 false - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/BinInfo/BinInfo.csproj b/BinInfo/BinInfo.csproj index 1737c5a..e103cc2 100644 --- a/BinInfo/BinInfo.csproj +++ b/BinInfo/BinInfo.csproj @@ -1,7 +1,7 @@  - net40;net45;netstandard2.0 + netstandard2.0 BinInfo BinInfo BinInfo diff --git a/BinInfo/BinList.cs b/BinInfo/BinList.cs index d8201d5..021d1e4 100644 --- a/BinInfo/BinList.cs +++ b/BinInfo/BinList.cs @@ -24,36 +24,23 @@ public static class BinList /// IssuerInformation public static IssuerInformation Find(string bin) { - if (bin == null) - throw new ArgumentNullException("bin"); - - if (!bin.Trim().All(c => char.IsNumber(c)) || string.IsNullOrWhiteSpace(bin)) - throw new ArgumentException("Make sure to enter a valid BIN/IIN number."); + BinSanityCheck(bin); - using (WebClient web = new WebClient()) + try { - try - { - string json = web.DownloadString(BaseUrl + bin); - - DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IssuerInformation)); - - using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json))) - { - var issuerInfo = (IssuerInformation)serializer.ReadObject(stream); - return issuerInfo; - } - } - catch (WebException ex) + using (var web = new WebClient()) { - string addInfo = $"No results for {bin}. Make sure you enter a valid BIN/IIN number. --- "; - throw new WebException(addInfo + ex.Message, ex, ex.Status, ex.Response); + var json = web.DownloadString($"{BaseUrl}{bin}"); + return GetIssuerInformation(json); } } + catch (WebException ex) + { + var addInfo = $"No results for {bin}. Make sure you enter a valid BIN/IIN number. --- "; + throw new WebException(addInfo + ex.Message, ex, ex.Status, ex.Response); + } } -#if !NET40 - /// /// binlist.net is a public web service for searching Issuer Identification Numbers (IIN). /// This webservice has an internal database with IIN/BIN information. @@ -65,34 +52,40 @@ public static IssuerInformation Find(string bin) /// IssuerInformation public async static Task FindAsync(string bin) { - if (bin == null) - throw new ArgumentNullException("bin"); + BinSanityCheck(bin); - if (!bin.Trim().All(c => char.IsNumber(c)) || string.IsNullOrWhiteSpace(bin)) - throw new ArgumentException("Make sure to enter a valid BIN/IIN number."); - - using (WebClient web = new WebClient()) + try { - try + using (var web = new WebClient()) { - string json = await web.DownloadStringTaskAsync(BaseUrl + bin); - - DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IssuerInformation)); - - using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json))) - { - var issuerInfo = (IssuerInformation)serializer.ReadObject(stream); - return issuerInfo; - } - } - catch (WebException ex) - { - string addInfo = $"No results for {bin}. Make sure you enter a valid BIN/IIN number. --- "; - throw new WebException(addInfo + ex.Message, ex, ex.Status, ex.Response); + var json = await web.DownloadStringTaskAsync($"{BaseUrl}{bin}"); + return GetIssuerInformation(json); } } + catch (WebException ex) + { + var addInfo = $"No results for {bin}. Make sure you enter a valid BIN/IIN number. --- "; + throw new WebException(addInfo + ex.Message, ex, ex.Status, ex.Response); + } } -#endif + private static IssuerInformation GetIssuerInformation(string json) + { + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json))) + { + var serializer = new DataContractJsonSerializer(typeof(IssuerInformation)); + var issuerInfo = (IssuerInformation)serializer.ReadObject(stream); + return issuerInfo; + } + } + + private static void BinSanityCheck(string bin) + { + if (bin == null) + throw new ArgumentNullException("bin"); + + if (!bin.Trim().All(c => char.IsNumber(c)) || string.IsNullOrWhiteSpace(bin)) + throw new ArgumentException("Make sure to enter a valid BIN/IIN number."); + } } } diff --git a/README.md b/README.md index 3af5d1f..5578c57 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# BinInfo ![.NET Core](https://github.com/gustavofrizzo/BinInfo/workflows/.NET%20Core/badge.svg?branch=master) +# BinInfo [![Build & Tests](https://github.com/gustavofrizzo/BinInfo/actions/workflows/dotnet-build-and-tests.yml/badge.svg)](https://github.com/gustavofrizzo/BinInfo/actions/workflows/dotnet-build-and-tests.yml) -BinInfo gets information about Credit Card Issuers through [binlist.net](https://binlist.net/) public REST API. +BinInfo is an API wrapper that retrieves information about Credit Card Issuers through [binlist.net](http://binlist.net) public REST API. NuGet Package -> https://www.nuget.org/packages/BinInfo