uploadcare / uploadcare-ruby

Ruby API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com
MIT License
39 stars 28 forks source link

Ability to use API client instances instead of globally configured instance #140

Open alxgsv opened 7 months ago

alxgsv commented 7 months ago

I am using uploadcare-ruby in my webservice that works with different Uploadcare projects. In order to switch between project I use this code: https://github.com/alxgsv/uc/blob/main/app/services/uploadcare_service.rb#L5-L14

However, without inspecting sources, I'm not sure that code is thread-safe, and I'm extremely worried about race conditions that could lead to reads or writes to wrong project, violating security and privacy.

It would be great to have an ability to initialize API client and to have guarantee that everything will work as expected:

client = Uploadcare::Api.new(credentials)