123456789101112131415161718192021222324252627282930 |
- module WeiboConcern
- extend ActiveSupport::Concern
- included do
- self.validate :validate_weibo_options
- end
- def validate_weibo_options
- unless options[:app_key].present? &&
- options[:app_secret].present? &&
- options[:access_token].present?
- errors.add(:base, "app_key, app_secret and access_token are required")
- end
- end
- def weibo_client
- unless @weibo_client
- WeiboOAuth2::Config.api_key = options[:app_key]
- WeiboOAuth2::Config.api_secret = options[:app_secret]
- @weibo_client = WeiboOAuth2::Client.new
- @weibo_client.get_token_from_hash :access_token => options[:access_token]
- end
- @weibo_client
- end
- module ClassMethods
- end
- end
|