Giter Club home page Giter Club logo

currencycloud-ruby's People

Contributors

cpacalevcc avatar cranieri avatar davidlj95 avatar eaddario avatar einzige avatar francescobbo avatar janwilk avatar jonathancouchman avatar liamm avatar lizzie88 avatar maria-thom avatar martijnrusschen avatar matid avatar rjnienaber avatar siwilliams avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

currencycloud-ruby's Issues

Multiple CurrencyCloud accounts and threads

We are currently using Currency Cloud Api v1 and plan to move to v2. We have a use case like this:

  • User has more than one pair of login_id, api_key (each pair is for a different broker).
  • User needs detailed rates for a currency pair from each of the brokers.
  • User selects the best rate and books is.

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?

Ruby v3.0 support

With the EOL of Ruby v2.7 coming soon, is there any initiative to support v3?

FundingAccount.find error code not Int

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

Using Multiple API Keys/Sessions/Authentication Tokens

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.

Rates API endpoint, rates key with values bid/offer/both

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,

README Example Doesn't Work

This example about on_behalf_of in README doesn't work

Screenshot from 2022-08-24 17-35-10

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'

Tasks for version 1.0

  • All methods available on connect.currencycloud.com
  • Debug logging
  • Model instance methods
    • .save
    • .delete
  • Relationships between entities (has_many, has_one, belongs_to)
  • Pagination methods (.next_page, .previous_page)
  • On behalf of
  • Updated README.md with examples and pointer to documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.