currencycloud / currencycloud-ruby Goto Github PK
View Code? Open in Web Editor NEWRuby implementation of API v2
License: MIT License
Ruby implementation of API v2
License: MIT License
I am able to bypass by calling:
CurrencyCloud::Reference.client.get('payment_dates', currency: 'USD')
But for the sake of completeness it should be included.
We are currently using Currency Cloud Api v1 and plan to move to v2. We have a use case like this:
login_id
, api_key
(each pair is for a different broker).In order to speed things up we make each request for rates in a separate thread. Looking at your example of usage, we'll need something like:
broker_accounts = { 'login_id1' => 'key1', 'login_id2' => 'key2' }
threads = []
broker_accounts.each do |login_id, api_key|
threads << Thread.new do
CurrencyCloud.login_id = login_id
CurrencyCloud.api_key = api_key
result = CurrencyCloud::Rate.detailed(params)
process_in_some_way(result)
end
end
threads.each(&:join)
However this will not work, because of a concurrency issue it is possible that threads overwrite each other's login_id
and api_key
.
I see this gem is not yet completed, but do you plan to implement functionality where instead of setting login_id
and api_key
on the module we can create instances of some class that contains the credentials?
Something like:
...
threads << Thread.new do
client = CurrencyCloud::Client.new(login_id, api_key)
result = client.rate.detailed(params)
process_in_some_way(result)
end
...
Or is there something that I miss in the current implementation?
With the EOL of Ruby v2.7 coming soon, is there any initiative to support v3?
Issue
Calling FundingAccount.find without a currency parameter does not fail gracefully. This is occurring as the http response for FundingAccount.find is as below, with the same value for error code and message.
#<HTTParty::Response:0x16be8 parsed_response={"error_code"=>"currency_is_required", "error_messages"=>{"base"=>{"code"=>"currency_is_required", "message"=>"Currency is required", "params"=>{}}}}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>
Expected Behaviour
Response from API should have error code set as an Int so that the error is correctly parsed by the SDK helper, or SDK should be able to handle situation where non-int error code is returned. This will mean you don't have to dig through the SDK and print the http response to find the actual error.
Traceback
Traceback (most recent call last):
15: from currencycloud.rb:11:in `<main>'
14: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/actions/find.rb:5:in `find'
13: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/client.rb:8:in `get'
12: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/request_handler.rb:10:in `get'
11: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/request_handler.rb:42:in `retry_authenticate'
10: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/response_handler.rb:14:in `process'
9: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/response_handler.rb:32:in `handle_failure'
8: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/response_handler.rb:32:in `new'
7: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:39:in `initialize'
6: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:39:in `each'
5: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:40:in `block in initialize'
4: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:40:in `each'
3: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:41:in `block (2 levels) in initialize'
2: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:41:in `new'
1: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:7:in `initialize'
/home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/errors/api_error.rb:7:in `[]': no implicit conversion of String into Integer (TypeError)
5: from currencycloud.rb:11:in `<main>'
4: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/actions/find.rb:5:in `find'
3: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/client.rb:8:in `get'
2: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/request_handler.rb:10:in `get'
1: from /home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/request_handler.rb:25:in `retry_authenticate'
/home/adam/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/currency_cloud-1.0.3/lib/currency_cloud/request_handler.rb:46:in `rescue in retry_authenticate': CurrencyCloud::UnexpectedError (CurrencyCloud::UnexpectedError)
---
platform: ruby-2.7.2
request:
parameters: {}
verb: get
url: https://devapi.currencycloud.com/v2/funding_accounts/find
inner_error: no implicit conversion of String into Integer
https://rubysec.com/advisories/GHSA-5pq7-52mg-hr42/
httparty gem vulnerability
currencycloud-ruby/currency_cloud.gemspec
Line 17 in 259c7fa
1.8 is 4 years old now
In a multi-user environment, can this be done? To allow each user to have their own API Session?
Would it be enough to switch out @session
and @token?
Are there any other concerns around this? I would be open to contributing the solution through a PR.
Hi,
I would like the option to only ask for bid rates, only ask for offer rates, or both.
https://github.com/CurrencyCloud/currencycloud-ruby/blob/master/lib/currency_cloud/rate.rb
Here, without the offer rates, it becomes:
module CurrencyCloud
class Rate
include CurrencyCloud::Resource
resource :rates
def self.find(params)
response = client.get("find", params)
rates = response["rates"].map do |currency_pair, (bid)|
new(currency_pair: currency_pair, bid: bid)
end
Rates.new(currencies: rates, unavailable: response["unavailable"])
end
def self.detailed(params)
new(client.get("detailed", params))
end
end
end
In fact, in my case, I only need bid rates. Do you plan to have a key on your rates/find API endpoint, called rates
with type string
and values bid
, offer
or both
?
And btw, do you plan to implement GraphQL for the V3 of your API?
Thank you,
This example about on_behalf_of in README doesn't work
pry(main)> CurrencyCloud::Account.create(account_name: 'My Test User', on_behalf_of: "bafd5d45-6d76-4f6f-b816-865b06a96ccf")
CurrencyCloud::BadRequestError: CurrencyCloud::BadRequestError
---
platform: ruby-2.5.8
request:
parameters:
account_name: My Test User
on_behalf_of: bafd5d45-6d76-4f6f-b816-865b06a96ccf
verb: post
url: https://devapi.currencycloud.com/v2/accounts/create
response:
status_code: 400
date: Wed, 24 Aug 2022 09:33:06 GMT
request_id: 0
errors:
- field: base
code: invalid_extra_parameters
message: Invalid extra parameters:'{:on_behalf_of=>"bafd5d45-6d76-4f6f-b816-865b06a96ccf"}'
params:
parameters:
on_behalf_of: bafd5d45-6d76-4f6f-b816-865b06a96ccf
from /home/peter/.rvm/gems/ruby-2.5.8/gems/currency_cloud-1.1.4/lib/currency_cloud/response_handler.rb:32:in `handle_failure'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.