1- using TBC . OpenAPI . SDK . Core ;
1+ using System . Runtime . CompilerServices ;
2+ using TBC . OpenAPI . SDK . Core ;
23using TBC . OpenAPI . SDK . Core . Exceptions ;
34using TBC . OpenAPI . SDK . Core . Models ;
5+ using TBC . OpenAPI . SDK . ExchangeRates . Helpers ;
46using TBC . OpenAPI . SDK . ExchangeRates . Models ;
57
8+ [ assembly: InternalsVisibleTo ( "TBC.OpenAPI.SDK.ExchangeRates.Tests" ) ]
69namespace TBC . OpenAPI . SDK . ExchangeRates
710{
8- public class ExchangeRatesClient : IExchangeRatesClient
11+ internal class ExchangeRatesClient : IExchangeRatesClient
912 {
10- private readonly HttpHelper < ExchangeRatesClient > _http ;
13+ private readonly IHttpHelper < ExchangeRatesClient > _http ;
1114
12- public ExchangeRatesClient ( HttpHelper < ExchangeRatesClient > http )
15+ public ExchangeRatesClient ( IHttpHelper < ExchangeRatesClient > http )
1316 {
1417 _http = http ;
1518 }
1619
17-
1820 #region CommercialRates
21+
1922 /// <summary>
20- /// კომერციული კურსის დასაბრუნებელი მეთოდი
23+ /// Gets commercial exchange rates for Georgian Lari
2124 /// </summary>
22- /// <param name="currencies">(required) ვალუტები, რომლებიც უნდა დაბრუნდეს </param>
25+ /// <param name="currencies">List of comma-separated 3-letter currency codes for limiting results to specific currencies. e.g. USD,EUR,JPY. If this parameter is not provided, rates will be returned for all currencies </param>
2326 /// <param name="cancellationToken">(optional)</param>
24- /// <returns>აბრუნებს გადაცემული ვალუტების კურსებს</returns>
25-
26- public async Task < GetCommercialRatesResponse ? > GetCommercialRates ( string [ ] currencies , CancellationToken cancellationToken = default )
27+ /// <returns>Returns list of TBC Bank's commercial exchange rates</returns>
28+ public async Task < GetCommercialRatesResponse > GetCommercialRates ( IEnumerable < string > currencies = null , CancellationToken cancellationToken = default )
2729 {
2830 var queryParams = new QueryParamCollection ( ) ;
29- queryParams . Add ( "currency" , string . Join ( "," , currencies ) ) ;
31+
32+ if ( currencies != null )
33+ {
34+ ParametersValidationHelper . CurrencyListValidation ( currencies ) ;
35+
36+ queryParams . Add ( "currency" , string . Join ( "," , currencies ) ) ;
37+ }
3038
3139 var result = await _http . GetJsonAsync < GetCommercialRatesResponse > ( "/commercial" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
3240
3341 if ( ! result . IsSuccess )
3442 throw new OpenApiException ( result . Problem ? . Title ?? "Unexpected error occurred" , result . Exception ) ;
3543
36- return result . Data ! ;
44+ return result . Data ;
3745 }
3846
3947 /// <summary>
40- /// კომერციული კურსის დასაკონვერტირებელი მეთოდი
48+ /// Converts amount between currencies based on TBC bank's commercial exchange rates
4149 /// </summary>
42- /// <param name="amount">(required) დასაკონვენტირებელი თანხის რაოდენობა </param>
43- /// <param name="from">(required) ვალუტა, საიდანაც უნდა დაკონვერტირდეს </param>
44- /// <param name="to">(required) ვალუტა, რაშიც უნდა დაკონვერტირდეს </param>
50+ /// <param name="amount">(required) Value to be converted </param>
51+ /// <param name="from">(required) Base currency from which given amount should be converted </param>
52+ /// <param name="to">(required) Target currency to which amount should be converted </param>
4553 /// <param name="cancellationToken">(optional)</param>
46- /// <returns>აბრუნებს დაკონვერტირებული ვალუტის კურსს</returns>
47-
48- public async Task < ConvertCommercialRatesResponse ? > ConvertCommercialRate ( decimal amount , string from , string to , CancellationToken cancellationToken = default )
54+ /// <returns>Returns convertion value of amount between currencies specified in from and to parameters based on TBC bank's commercial exchange rates</returns>
55+ public async Task < ConvertCommercialRatesResponse > ConvertCommercialRate ( decimal amount , string from , string to , CancellationToken cancellationToken = default )
4956 {
50- var queryParams = new QueryParamCollection ( ) ;
51- queryParams . Add ( "amount" , amount ) ;
52- queryParams . Add ( "from" , from ) ;
53- queryParams . Add ( "to" , to ) ;
57+ ParametersValidationHelper . ConvertionParameterValidation ( amount , from , to ) ;
58+
59+ var queryParams = new QueryParamCollection
60+ {
61+ { "amount" , amount } ,
62+ { "from" , from } ,
63+ { "to" , to }
64+ } ;
5465
5566 var result = await _http . GetJsonAsync < ConvertCommercialRatesResponse > ( "/commercial/convert" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
5667
5768 if ( ! result . IsSuccess )
5869 throw new OpenApiException ( result . Problem ? . Title ?? "Unexpected error occurred" , result . Exception ) ;
5970
60- return result . Data ! ;
71+ return result . Data ;
6172 }
73+
6274 #endregion
6375
76+ #region Official Rates
77+
78+ /// <summary>
79+ /// Gets official exchange rates for Georgian Lari
80+ /// </summary>
81+ /// <param name="currencies">List of comma-separated 3-letter currency codes for limiting results to specific currencies. e.g. USD,EUR,JPY. If this parameter is not provided, rates will be returned for all currencies</param>
82+ /// <param name="cancellationToken">(optional)</param>
83+ /// <returns>Returns list of official exchange rates</returns>
84+ public async Task < List < OfficialRate > > GetOfficialRates ( IEnumerable < string > currencies = null , CancellationToken cancellationToken = default )
85+ {
86+ var queryParams = new QueryParamCollection ( ) ;
87+
88+ if ( currencies != null )
89+ {
90+ ParametersValidationHelper . CurrencyListValidation ( currencies ) ;
91+
92+ queryParams . Add ( "currency" , string . Join ( "," , currencies ) ) ;
93+ }
6494
95+ var result = await _http . GetJsonAsync < List < OfficialRate > > ( "/nbg" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
6596
97+ if ( ! result . IsSuccess )
98+ throw new OpenApiException ( result . Problem ? . Title ?? "Unexpected error occurred" , result . Exception ) ;
99+
100+ return result . Data ;
101+ }
66102
67- #region Official Rates
68103 /// <summary>
69- /// ოფიციალური კურსების დასაბრუნებელი მეთოდი
104+ /// Gets official exchange rates for Georgian Lari by specific date
70105 /// </summary>
71- /// <param name="currencies">(optional) ვალუტების მასივი, რომლებიც უნდა დაბრუნდეს(ამ პარამეტრის არგადაცემის შემთხვევაში აბრუნებს ყველა ვალუტას)</param>
106+ /// <param name="date">Parameter for getting official rates for specific date. Date should be passed in YYYY-MM-dd format</param>
107+ /// <param name="currencies">List of comma-separated 3-letter currency codes for limiting results to specific currencies. e.g. USD,EUR,JPY. If this parameter is not provided, rates will be returned for all currencies</param>
72108 /// <param name="cancellationToken">(optional)</param>
73- /// <returns>აბრუნებს ყველა ვალუტის ან გადაცემული ვალუტების კურსებს</returns>
74-
75- public async Task < List < OfficialRate > ? > GetOfficialRates ( string [ ] ? currencies = null , CancellationToken cancellationToken = default )
109+ /// <returns>Returns list of official exchange rates on specific date</returns>
110+ public async Task < List < OfficialRate > > GetOfficialRatesByDate ( IEnumerable < string > currencies = null , string ? date = null , CancellationToken cancellationToken = default )
76111 {
77112 var queryParams = new QueryParamCollection ( ) ;
78- if ( currencies ? . Any ( ) ?? false )
113+
114+ if ( currencies != null )
79115 {
80- queryParams . Add ( "currency" , string . Join ( "," , currencies ) ) ;
116+ ParametersValidationHelper . CurrencyListValidation ( currencies ) ;
117+
118+ queryParams . Add ( "currency" , string . Join ( "," , currencies ) ) ;
81119 }
82120
83- var result = await _http . GetJsonAsync < List < OfficialRate > ? > ( "/nbg" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
121+ if ( ! string . IsNullOrEmpty ( date ) )
122+ {
123+ ParametersValidationHelper . DateFormatValidation ( date ) ;
124+
125+ queryParams . Add ( "date" , date ) ;
126+ }
127+
128+ var result = await _http . GetJsonAsync < List < OfficialRate > > ( "/nbg" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
84129
85130 if ( ! result . IsSuccess )
86131 throw new OpenApiException ( result . Problem ? . Title ?? "Unexpected error occurred" , result . Exception ) ;
87132
88- return result . Data ! ;
133+ return result . Data ;
89134 }
90135
91136 /// <summary>
92- /// ოფიციალური კურსის დასაკონვერტირებელი მეთოდი
137+ /// Converts amount between currencies based on official exchange rates
93138 /// </summary>
94- /// <param name="amount">(required) დასაკონვენტირებელი თანხის რაოდენობა </param>
95- /// <param name="from">(required) ვალუტა, საიდანაც უნდა დაკონვერტირდეს </param>
96- /// <param name="to">(required) ვალუტა, რაშიც უნდა დაკონვერტირდეს </param>
139+ /// <param name="amount">(required) Value to be converted </param>
140+ /// <param name="from">(required) Base currency from which given amount should be converted </param>
141+ /// <param name="to">(required) Target currency to which amount should be converted </param>
97142 /// <param name="cancellationToken">(optional)</param>
98- /// <returns>დაკონვერტირებული ვალუტის კურსი </returns>
99- public async Task < ConvertOfficialRatesResponse ? > ConvertOfficialRates ( decimal amount , string from , string to , CancellationToken cancellationToken = default )
143+ /// <returns>Returns convertion value of amount between currencies specified in from and to parameters based on official exchange rates </returns>
144+ public async Task < ConvertOfficialRatesResponse > ConvertOfficialRates ( decimal amount , string from , string to , CancellationToken cancellationToken = default )
100145 {
101- var queryParams = new QueryParamCollection ( ) ;
102- queryParams . Add ( "amount" , amount ) ;
103- queryParams . Add ( "from" , from ) ;
104- queryParams . Add ( "to" , to ) ;
146+ ParametersValidationHelper . ConvertionParameterValidation ( amount , from , to ) ;
147+
148+ var queryParams = new QueryParamCollection
149+ {
150+ { "amount" , amount } ,
151+ { "from" , from } ,
152+ { "to" , to }
153+ } ;
105154
106155 var result = await _http . GetJsonAsync < ConvertOfficialRatesResponse > ( "/nbg/convert" , queryParams , cancellationToken ) . ConfigureAwait ( false ) ;
107156
108157 if ( ! result . IsSuccess )
109158 throw new OpenApiException ( result . Problem ? . Title ?? "Unexpected error occurred" , result . Exception ) ;
110159
111- return result . Data ! ;
160+ return result . Data ;
112161 }
162+
113163 #endregion
114164 }
115165}
0 commit comments