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

uninitialized constant Uploadcare #69

Closed ipatovanton closed 2 years ago

ipatovanton commented 3 years ago

When I try to upload image Uploadcare::Uploader.upload('https://placekitten.com/96/139')

I get an error: uninitialized constant Uploadcare

Also when I try to add: require 'uploadcare'

I get an error:

uploadcare-ruby-3.0.5/lib/uploadcare/client/rest_client.rb:12:in `': uninitialized constant Uploadcare::Client::ApiStruct (NameError)

dmitry-mukhin commented 3 years ago

have you set your config settings? e.g.:

# your_config_initializer_file.rb
Uploadcare.config.public_key = 'demopublickey'
Uploadcare.config.secret_key = 'demoprivatekey'
dmitry-mukhin commented 3 years ago

If that's so, I agree that we need a more human friendly error message in this case.

rudietuesdays commented 3 years ago

Having the same issue, having set my config keys! Thanks for taking a look!

dmitry-mukhin commented 3 years ago

Sorry, you've set the keys and still get the error. Correct?

rudietuesdays commented 3 years ago

Having the same issue, having set my config keys! Thanks for taking a look!

Yes, I have set the keys @dmitry-mukhin

Edit: If it's helpful context, this is happening after upgrading from v2 to v3 in Ruby 2.6.3 and Rails 5.2.5.

shyankashani commented 3 years ago

I am having the same problem

shyankashani commented 3 years ago

@dmitry-mukhin @rudietuesdays I've figured it out, you have to add this gem: https://github.com/rubygarage/api_struct/

dmitry-mukhin commented 3 years ago

@shyankashani uploadcare-ruby already depends on api_struct, so not sure how that could help. maybe you bundler wasn't run properly?

dmitry-mukhin commented 3 years ago

@rudietuesdays could you also check that you run bundler after gem version upgrade? thanks!

shyankashani commented 3 years ago

@dmitry-mukhin Huh, I'm not sure! I think it was, but it may not have been. Let's see if that works for @rudietuesdays

dmitry-mukhin commented 3 years ago

@shyankashani bundle run should install all explicit and implicit dependencies, and api-struct is a dependency

maysam commented 3 years ago

setting ENV variables should be enough and running Uploadcare.config.public_key in the console causes error.

something is not right

dmitrijivanchenko commented 3 years ago

You should place require 'uploadcare' in a file where you use this gem. Problem with unitialized constant ApiStruct must be fixed in the branch feature/1-new-entity-attrs. We are working on a new version. It is coming soon. For now, you can use the branch feature/1-new-entity-attrs.

solidiquis commented 2 years ago

I had the same problem but fixed it by explicitly requiring 'uploadcare' in my initializer.

config/initializers/uploadcare.rb

require 'uploadcare'

Uploadcare.config.public_key = ENV["UPLOADCARE_PUBLIC_KEY"]
Uploadcare.config.secret_key = ENV["UPLOADCARE_SECRET_KEY"]
dmitrijivanchenko commented 2 years ago

We fixed this issue in the version 3.1.0. Please, check