Skip to content

Commit e7b5b91

Browse files
committed
Adding a response in JSON format
1 parent 576b838 commit e7b5b91

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

nip24Example/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
67
*
78
* http://www.apache.org/licenses/LICENSE-2.0
89
*
910
* Unless required by applicable law or agreed to in writing, software
1011
* distributed under the License is distributed on an "AS IS" BASIS,
1112
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
1214
* limitations under the License.
1315
*
1416
* @author NETCAT <[email protected]>
@@ -30,17 +32,20 @@ static void Main(string[] args)
3032
{
3133
try
3234
{
35+
// Utworzenie obiektu klienta usługi serwisu produkcyjnego
3336
// id – ciąg znaków reprezentujący identyfikator klucza API
3437
// key – ciąg znaków reprezentujący klucz API
3538
// NIP24Client nip24 = new NIP24Client("id", "key");
3639

40+
// Utworzenie obiektu klienta usługi serwisu testowego
3741
NIP24Client nip24 = new NIP24Client();
3842

3943
string nip = "7171642051";
4044
string nip_eu = "PL" + nip;
4145
string account_number = "49154000046458439719826658";
4246
string krs_number = "0000030897";
4347

48+
// Sprawdzenie stanu konta
4449
AccountStatus account = nip24.GetAccountStatus();
4550

4651
if (account != null)
@@ -71,6 +76,7 @@ static void Main(string[] args)
7176
}
7277
}
7378

79+
// Sprawdzenie statusu firmy w rejestrze VAT
7480
VATStatus vat = nip24.GetVATStatus(Number.NIP, nip);
7581

7682
if (vat != null)
@@ -142,6 +148,7 @@ static void Main(string[] args)
142148
Console.WriteLine("Błąd: " + nip24.LastError + " (kod: " + nip24.LastErrorCode + ")");
143149
}
144150

151+
// Wywołanie metody wyszukującej dane w rejestrze VAT
145152
SearchResult result = nip24.SearchVATRegistry(Number.NIP, nip);
146153

147154
if (result != null)

nip24Example/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.InteropServices;
33

44
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
56
// associated with an assembly.
67
[assembly: AssemblyTitle("NIP24 Service Client")]
78
[assembly: AssemblyDescription("NIP24 Service Client for .NET Framework (C#)")]
@@ -22,10 +23,13 @@
2223

2324
// Version information for an assembly consists of the following four values:
2425
//
26+
// Major Version
2527
// Minor Version
28+
// Build Number
29+
// Revision
2630
//
2731
// You can specify all the values or you can default the Build and Revision Numbers
2832
// by using the '*' as shown below:
2933
// [assembly: AssemblyVersion("1.0.*")]
30-
[assembly: AssemblyVersion("1.4.7.0")]
31-
[assembly: AssemblyFileVersion("1.4.7.0")]
34+
[assembly: AssemblyVersion("1.4.8.0")]
35+
[assembly: AssemblyFileVersion("1.4.8.0")]

nip24Library/NIP24Client.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public interface INIP24Client
355355
[ComVisible(true)]
356356
public class NIP24Client : INIP24Client
357357
{
358-
public const string VERSION = "1.4.7";
358+
public const string VERSION = "1.4.8";
359359

360360
public const string PRODUCTION_URL = "https://www.nip24.pl/api";
361361
public const string TEST_URL = "https://www.nip24.pl/api-test";
@@ -1473,7 +1473,7 @@ public KRSData GetKRSSection(Number type, string number, int section)
14731473
// prepare url
14741474
Uri url = new Uri(URL + "/get/krs/current/" + suffix + "/" + section);
14751475

1476-
return (KRSData)Get(url, typeof(KRSData));
1476+
return (KRSData)Get(url, "krs", typeof(KRSData));
14771477
}
14781478
catch (Exception e)
14791479
{
@@ -1596,10 +1596,12 @@ private void Set(int code, string err = null)
15961596
}
15971597

15981598
/// <summary>
1599+
/// HTTP GET
15991600
/// </summary>
16001601
/// <param name="url">adres URL</param>
1602+
/// <param name="mimetype">typ odpowiedzi (application/xml lub application/json)</param>
16011603
/// <returns>pobrana odpowiedź lub null</returns>
1602-
private byte[] GetBytes(Uri url)
1604+
private byte[] GetBytes(Uri url, string mimetype)
16031605
{
16041606
try
16051607
{
@@ -1640,6 +1642,7 @@ private byte[] GetBytes(Uri url)
16401642
{
16411643
wc.Proxy = Proxy;
16421644

1645+
wc.Headers.Set("Accept", mimetype);
16431646
wc.Headers.Set("Authorization", GetAuthHeader("GET", url));
16441647
wc.Headers.Set("User-Agent", GetAgentHeader());
16451648

@@ -1655,6 +1658,7 @@ private byte[] GetBytes(Uri url)
16551658
}
16561659

16571660
/// <summary>
1661+
/// Pobranie odpowiedzi jako XML
16581662
/// </summary>
16591663
/// <param name="url">adres URL</param>
16601664
/// <returns>pobrana odpowiedź lub null</returns>
@@ -1663,7 +1667,7 @@ private XPathDocument Get(Uri url)
16631667
try
16641668
{
16651669
// get response
1666-
byte[] b = GetBytes(url);
1670+
byte[] b = GetBytes(url, "application/xml");
16671671

16681672
if (b == null)
16691673
{
@@ -1682,11 +1686,13 @@ private XPathDocument Get(Uri url)
16821686
}
16831687

16841688
/// <summary>
1689+
/// Pobranie odpowiedzi jako obiektu
16851690
/// </summary>
16861691
/// <param name="url">adres URL</param>
1692+
/// <param name="attr">nazwa atrybutu JSON do zwrócenia</param>
16871693
/// <param name="type">typ obiektu do zwrócenia w odpowiedzi</param>
16881694
/// <returns>pobrana odpowiedź lub null</returns>
1689-
private object Get(Uri url, Type type)
1695+
private object Get(Uri url, string attr, Type type)
16901696
{
16911697
JsonSerializerSettings s = new JsonSerializerSettings
16921698
{
@@ -1696,7 +1702,7 @@ private object Get(Uri url, Type type)
16961702
try
16971703
{
16981704
// get response
1699-
byte[] b = GetBytes(url);
1705+
byte[] b = GetBytes(url, "application/json");
17001706

17011707
if (b == null)
17021708
{
@@ -1728,7 +1734,7 @@ private object Get(Uri url, Type type)
17281734
return null;
17291735
}
17301736

1731-
return json["krs"].ToObject(type);
1737+
return json[attr].ToObject(type);
17321738
}
17331739
catch (Exception e)
17341740
{

nip24Library/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
// You can specify all the values or you can default the Build and Revision Numbers
2626
// by using the '*' as shown below:
2727
// [assembly: AssemblyVersion("1.0.*")]
28-
[assembly: AssemblyVersion("1.4.7.0")]
29-
[assembly: AssemblyFileVersion("1.4.7.0")]
28+
[assembly: AssemblyVersion("1.4.8.0")]
29+
[assembly: AssemblyFileVersion("1.4.8.0")]
3030

3131
#endif
3232

nip24Library/Properties/Settings.Designer.cs

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nip24Library/nip24Library.csproj

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66

77
<PackageId>NIP24.NIP24Client</PackageId>
8-
<Version>1.4.7</Version>
9-
<AssemblyVersion>1.4.7.0</AssemblyVersion>
10-
<FileVersion>1.4.7.0</FileVersion>
8+
<Version>1.4.8</Version>
9+
<AssemblyVersion>1.4.8.0</AssemblyVersion>
10+
<FileVersion>1.4.8.0</FileVersion>
1111

1212
<Title>NIP24 Service Client</Title>
1313
<Summary>NIP24 Service Client for .NET Framework (C#)</Summary>
@@ -62,31 +62,7 @@
6262
<Reference Include="System.Xml" />
6363
</ItemGroup>
6464

65-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
66-
<PackageReference Include="System.Configuration.ConfigurationManager">
67-
<Version>7.0.0</Version>
68-
</PackageReference>
69-
</ItemGroup>
70-
71-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
72-
<PackageReference Include="System.Configuration.ConfigurationManager">
73-
<Version>7.0.0</Version>
74-
</PackageReference>
75-
</ItemGroup>
76-
77-
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
78-
<PackageReference Include="System.Configuration.ConfigurationManager">
79-
<Version>7.0.0</Version>
80-
</PackageReference>
81-
</ItemGroup>
82-
83-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
84-
<PackageReference Include="System.Configuration.ConfigurationManager">
85-
<Version>7.0.0</Version>
86-
</PackageReference>
87-
</ItemGroup>
88-
8965
<ItemGroup>
90-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
66+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
9167
</ItemGroup>
9268
</Project>

0 commit comments

Comments
 (0)