Class: WeiboOAuth2::Client
- Inherits:
-
OAuth2::Client
- Object
- OAuth2::Client
- WeiboOAuth2::Client
- Defined in:
- lib/weibo_2/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
- #auth_code ⇒ Object
- #authorize_url(params = {}) ⇒ Object
- #authorized? ⇒ Boolean
- #comments ⇒ Object
- #favorites ⇒ Object
- #friendships ⇒ Object
- #get_and_restore_token(params, access_token_opts = {}) ⇒ Object
- #get_token(params, access_token_opts = {}) ⇒ Object
- #get_token_from_hash(hash) ⇒ Object
-
#initialize(client_id = '', client_secret = '', opts = {}, &block) ⇒ Client
constructor
A new instance of Client.
- #location ⇒ Object
- #place ⇒ Object
- #register ⇒ Object
- #remind ⇒ Object
- #search ⇒ Object
- #short_url ⇒ Object
- #statuses ⇒ Object
- #suggestions ⇒ Object
- #tags ⇒ Object
- #trends ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(client_id = '', client_secret = '', opts = {}, &block) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 |
# File 'lib/weibo_2/client.rb', line 8 def initialize(client_id='', client_secret='', opts={}, &block) client_id = WeiboOAuth2::Config.api_key if client_id.empty? client_secret = WeiboOAuth2::Config.api_secret if client_secret.empty? super @site = "https://api.weibo.com/2/" @options[:authorize_url] = '/oauth2/authorize' @options[:token_url] = '/oauth2/access_token' end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/weibo_2/client.rb', line 6 def access_token @access_token end |
Class Method Details
.from_code(code, opts = {}, &block) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/weibo_2/client.rb', line 17 def self.from_code(code, opts={}, &block) client = self.new(opts, &block) client.auth_code.get_token(code) client end |
.from_hash(hash, opts = {}, &block) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/weibo_2/client.rb', line 24 def self.from_hash(hash, opts={}, &block) client = self.new(opts, &block) client.get_token_from_hash(hash) client end |
Instance Method Details
#account ⇒ Object
73 74 75 |
# File 'lib/weibo_2/client.rb', line 73 def account @account ||= WeiboOAuth2::Api::V2::Account.new(@access_token) if @access_token end |
#auth_code ⇒ Object
109 110 111 |
# File 'lib/weibo_2/client.rb', line 109 def auth_code @auth_code ||= WeiboOAuth2::Strategy::AuthCode.new(self) end |
#authorize_url(params = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/weibo_2/client.rb', line 31 def (params={}) params[:client_id] = @id unless params[:client_id] params[:response_type] = 'code' unless params[:response_type] params[:redirect_uri] = WeiboOAuth2::Config.redirect_uri unless params[:redirect_uri] super end |
#authorized? ⇒ Boolean
53 54 55 |
# File 'lib/weibo_2/client.rb', line 53 def @access_token && @access_token.validated? end |
#comments ⇒ Object
65 66 67 |
# File 'lib/weibo_2/client.rb', line 65 def comments @comments ||= WeiboOAuth2::Api::V2::Comments.new(@access_token) if @access_token end |
#favorites ⇒ Object
77 78 79 |
# File 'lib/weibo_2/client.rb', line 77 def favorites @favorites ||= WeiboOAuth2::Api::V2::Favorites.new(@access_token) if @access_token end |
#friendships ⇒ Object
69 70 71 |
# File 'lib/weibo_2/client.rb', line 69 def friendships @friendships ||= WeiboOAuth2::Api::V2::Friendships.new(@access_token) if @access_token end |
#get_and_restore_token(params, access_token_opts = {}) ⇒ Object
44 45 46 |
# File 'lib/weibo_2/client.rb', line 44 def get_and_restore_token(params, access_token_opts={}) @access_token = get_token(params, access_token_opts={}) end |
#get_token(params, access_token_opts = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/weibo_2/client.rb', line 38 def get_token(params, access_token_opts={}) params = params.merge({:parse => :json}) access_token_opts = access_token_opts.merge({:header_format => "OAuth2 %s", :param_name => "access_token"}) super end |
#get_token_from_hash(hash) ⇒ Object
48 49 50 51 |
# File 'lib/weibo_2/client.rb', line 48 def get_token_from_hash(hash) access_token = hash.delete(:access_token) || hash.delete('access_token') @access_token = WeiboOAuth2::AccessToken.new( self, access_token, hash.merge(:header_format => 'OAuth2 %s', :param_name => 'access_token') ) end |
#location ⇒ Object
117 118 119 |
# File 'lib/weibo_2/client.rb', line 117 def location @location ||= WeiboOAuth2::Api::V2::Location.new(@access_token) if @access_token end |
#place ⇒ Object
113 114 115 |
# File 'lib/weibo_2/client.rb', line 113 def place @place ||= WeiboOAuth2::Api::V2::Place.new(@access_token) if @access_token end |
#register ⇒ Object
89 90 91 |
# File 'lib/weibo_2/client.rb', line 89 def register @register ||= WeiboOAuth2::Api::V2::Register.new(@access_token) if @access_token end |
#remind ⇒ Object
105 106 107 |
# File 'lib/weibo_2/client.rb', line 105 def remind @remind ||= WeiboOAuth2::Api::V2::Remind.new(@access_token) if @access_token end |
#search ⇒ Object
93 94 95 |
# File 'lib/weibo_2/client.rb', line 93 def search @search ||= WeiboOAuth2::Api::V2::Search.new(@access_token) if @access_token end |
#short_url ⇒ Object
97 98 99 |
# File 'lib/weibo_2/client.rb', line 97 def short_url @short_url ||= WeiboOAuth2::Api::V2::ShortUrl.new(@access_token) if @access_token end |
#statuses ⇒ Object
61 62 63 |
# File 'lib/weibo_2/client.rb', line 61 def statuses @statues ||= WeiboOAuth2::Api::V2::Statuses.new(@access_token) if @access_token end |
#suggestions ⇒ Object
101 102 103 |
# File 'lib/weibo_2/client.rb', line 101 def suggestions @suggestions ||= WeiboOAuth2::Api::V2::Suggestions.new(@access_token) if @access_token end |
#tags ⇒ Object
85 86 87 |
# File 'lib/weibo_2/client.rb', line 85 def @tags ||= WeiboOAuth2::Api::V2::Tags.new(@access_token) if @access_token end |
#trends ⇒ Object
81 82 83 |
# File 'lib/weibo_2/client.rb', line 81 def trends @trends ||= WeiboOAuth2::Api::V2::Trends.new(@access_token) if @access_token end |
#users ⇒ Object
57 58 59 |
# File 'lib/weibo_2/client.rb', line 57 def users @users ||= WeiboOAuth2::Api::V2::Users.new(@access_token) if @access_token end |