dropbox_concern.rb 823 B

1234567891011121314151617181920212223242526272829303132333435
  1. module DropboxConcern
  2. extend ActiveSupport::Concern
  3. included do
  4. include Oauthable
  5. valid_oauth_providers :dropbox_oauth2
  6. gem_dependency_check { defined?(Dropbox) && Devise.omniauth_providers.include?(:dropbox) }
  7. end
  8. def dropbox
  9. Dropbox::API::Config.app_key = consumer_key
  10. Dropbox::API::Config.app_secret = consumer_secret
  11. Dropbox::API::Config.mode = 'dropbox'
  12. Dropbox::API::Client.new(token: oauth_token, secret: oauth_token_secret)
  13. end
  14. private
  15. def consumer_key
  16. (config = Devise.omniauth_configs[:dropbox]) && config.strategy.client_id
  17. end
  18. def consumer_secret
  19. (config = Devise.omniauth_configs[:dropbox]) && config.strategy.client_secret
  20. end
  21. def oauth_token
  22. service && service.token
  23. end
  24. def oauth_token_secret
  25. service && service.secret
  26. end
  27. end