ynab / ynab-sdk-ruby

YNAB API Client for Ruby
https://api.ynab.com
Apache License 2.0
66 stars 12 forks source link

Currency data not returned by client #12

Closed rafaelmillan closed 6 years ago

rafaelmillan commented 6 years ago

Hi,

The currency format data is returned in the raw API response but not in the YnabApi::CurrencyFormat objects of the client:

irb(main):084:0> client.budgets.api_client.config.debugging = true
=> true
irb(main):085:0> response = client.budgets.get_budgets
D, [2018-04-07T16:46:59.417961 #52429] DEBUG -- : Calling API: BudgetsApi.get_budgets ...
Connection 3 seems to be dead!
Closing connection 3
  Trying 50.16.212.181...
TCP_NODELAY set
Connected to api.youneedabudget.com (50.16.212.181) port 443 (#4)
SSL re-using session ID
TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
Server certificate: api.youneedabudget.com
Server certificate: Let's Encrypt Authority X3
Server certificate: DST Root CA X3
GET /v1/budgets HTTP/1.1
Host: api.youneedabudget.com
User-Agent: api_client/ruby/0.6.0
Content-Type: application/json
Accept: application/json
Authorization: Bearer TOKEN_HIDDEN

HTTP/1.1 200 OK
Server: Cowboy
Date: Sat, 07 Apr 2018 14:47:01 GMT
Connection: keep-alive
Content-Type: application/json; charset=utf-8
X-Rate-Limit: 8/200
Vary: Accept-Encoding, Origin
Etag: W/"99f504dcdedffbe6138d381fb76b034e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: b3bada1d-4f97-4144-b7c4-040a422e662a
X-Runtime: 0.030880
Strict-Transport-Security: max-age=15552000
Transfer-Encoding: chunked
Via: 1.1 vegur

Connection #4 to host api.youneedabudget.com left intact
D, [2018-04-07T16:47:01.508452 #52429] DEBUG -- : HTTP response body ~BEGIN~
{"data":{"budgets":[{"id":"budget_id_hidden","name":"Cuentas","last_modified_on":"2018-04-07T14:23:45+00:00","date_format":{"format":"DD/MM/YYYY"},"currency_format":{"iso_code":"EUR","example_format":"123 456,78","decimal_digits":2,"decimal_separator":",","symbol_first":false,"group_separator":" ","currency_symbol":"€","display_symbol":true},"first_month":"2014-09-01","last_month":"2018-04-01"}]}}
~END~

D, [2018-04-07T16:47:01.509703 #52429] DEBUG -- : API called: BudgetsApi#get_budgets
Data: #<YnabApi::BudgetSummaryResponse:0x00007fe80caf3718 @data=#<YnabApi::BudgetSummaryWrapper:0x00007fe80caf34c0 @budgets=[#<YnabApi::BudgetSummary:0x00007fe80caf31a0 @id="budget_id_hidden", @name="Cuentas", @last_modified_on=#<DateTime: 2018-04-07T14:23:45+00:00 ((2458216j,51825s,0n),+0s,2299161j)>, @date_format=#<YnabApi::DateFormat:0x00007fe80caf28b8>, @currency_format=#<YnabApi::CurrencyFormat:0x00007fe80caf2660>>]>>
Status code: 200
Headers: {"Server"=>"Cowboy", "Date"=>"Sat, 07 Apr 2018 14:47:01 GMT", "Connection"=>"keep-alive", "Content-Type"=>"application/json; charset=utf-8", "X-Rate-Limit"=>"8/200", "Vary"=>"Accept-Encoding, Origin", "Etag"=>"W/\"99f504dcdedffbe6138d381fb76b034e\"", "Cache-Control"=>"max-age=0, private, must-revalidate", "X-Request-Id"=>"b3bada1d-4f97-4144-b7c4-040a422e662a", "X-Runtime"=>"0.030880", "Strict-Transport-Security"=>"max-age=15552000", "Transfer-Encoding"=>"chunked", "Via"=>"1.1 vegur"}
=> #<YnabApi::BudgetSummaryResponse:0x00007fe80caf3718 @data=#<YnabApi::BudgetSummaryWrapper:0x00007fe80caf34c0 @budgets=[#<YnabApi::BudgetSummary:0x00007fe80caf31a0 @id="budget_id_hidden", @name="Cuentas", @last_modified_on=#<DateTime: 2018-04-07T14:23:45+00:00 ((2458216j,51825s,0n),+0s,2299161j)>, @date_format=#<YnabApi::DateFormat:0x00007fe80caf28b8>, @currency_format=#<YnabApi::CurrencyFormat:0x00007fe80caf2660>>]>>
irb(main):086:0> response.data.budgets.first.currency_format.to_hash
=> {}

Looking at your API docs it seems that the only field in the currency model is locale, so even though values such as iso_code are returned by the API, they are skipped by the client.

rafaelmillan commented 6 years ago

Same for date format.

bradymholt commented 6 years ago

Thanks for the report! Our swagger spec needed to be updated for these fields.

Fixed by https://github.com/ynab/ynab-sdk-ruby/pull/13, released to RubyGems as 0.7.0.

Updated format:

budget_response = ynab.budgets.get_budgets.data.budgets[0].date_format
 => #<YnabApi::DateFormat:0x00007fe3c929d920 @format="MM/DD/YYYY">
budget_response = ynab.budgets.get_budgets.data.budgets[0].currency_format
 => #<YnabApi::CurrencyFormat:0x00007fe3c926c730 @iso_code="USD", @example_format="123,456.78", @decimal_digits="2", @decimal_separator=".", @symbol_first=true, @group_separator=",", @currency_symbol="$", @display_symbol=true>
rafaelmillan commented 6 years ago

Sweet, thanks for the quick fix!