weibo_concern.rb 752 B

1234567891011121314151617181920212223242526272829
  1. module WeiboConcern
  2. extend ActiveSupport::Concern
  3. included do
  4. self.validate :validate_weibo_options
  5. end
  6. def validate_weibo_options
  7. unless options['app_key'].present? &&
  8. options['app_secret'].present? &&
  9. options['access_token'].present?
  10. errors.add(:base, "app_key, app_secret and access_token are required")
  11. end
  12. end
  13. def weibo_client
  14. unless @weibo_client
  15. WeiboOAuth2::Config.api_key = options['app_key'] # WEIBO_APP_KEY
  16. WeiboOAuth2::Config.api_secret = options['app_secret'] # WEIBO_APP_SECRET
  17. @weibo_client = WeiboOAuth2::Client.new
  18. @weibo_client.get_token_from_hash :access_token => options['access_token']
  19. end
  20. @weibo_client
  21. end
  22. module ClassMethods
  23. end
  24. end