Class: WeiboOAuth2::Client

Inherits:
OAuth2::Client
  • Object
show all
Defined in:
lib/weibo_2/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id = '', client_secret = '', opts = {}, &block) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
# File 'lib/weibo_2/client.rb', line 6

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 Method Details

#accountObject



57
58
59
# File 'lib/weibo_2/client.rb', line 57

def 
  @account ||= WeiboOAuth2::Api::V2::Account.new(@access_token) if @access_token      
end

#auth_codeObject



93
94
95
# File 'lib/weibo_2/client.rb', line 93

def auth_code
  @auth_code ||= WeiboOAuth2::Strategy::AuthCode.new(self)
end

#authorize_url(params = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/weibo_2/client.rb', line 15

def authorize_url(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

Returns:

  • (Boolean)


37
38
39
# File 'lib/weibo_2/client.rb', line 37

def authorized?
  @access_token && @access_token.validated?
end

#commentsObject



49
50
51
# File 'lib/weibo_2/client.rb', line 49

def comments
  @comments ||= WeiboOAuth2::Api::V2::Comments.new(@access_token) if @access_token
end

#favoritesObject



61
62
63
# File 'lib/weibo_2/client.rb', line 61

def favorites
  @favorites ||= WeiboOAuth2::Api::V2::Favorites.new(@access_token) if @access_token      
end

#friendshipsObject



53
54
55
# File 'lib/weibo_2/client.rb', line 53

def friendships
  @friendships ||= WeiboOAuth2::Api::V2::Friendships.new(@access_token) if @access_token
end

#get_and_restore_token(params, access_token_opts = {}) ⇒ Object



28
29
30
# File 'lib/weibo_2/client.rb', line 28

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



22
23
24
25
26
# File 'lib/weibo_2/client.rb', line 22

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



32
33
34
35
# File 'lib/weibo_2/client.rb', line 32

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

#registerObject



73
74
75
# File 'lib/weibo_2/client.rb', line 73

def register
  @register ||= WeiboOAuth2::Api::V2::Register.new(@access_token) if @access_token      
end

#remindObject



89
90
91
# File 'lib/weibo_2/client.rb', line 89

def remind
  @remind ||= WeiboOAuth2::Api::V2::Remind.new(@access_token) if @access_token      
end

#searchObject



77
78
79
# File 'lib/weibo_2/client.rb', line 77

def search
  @search ||= WeiboOAuth2::Api::V2::Search.new(@access_token) if @access_token      
end

#short_urlObject



81
82
83
# File 'lib/weibo_2/client.rb', line 81

def short_url
  @short_url ||= WeiboOAuth2::Api::V2::ShortUrl.new(@access_token) if @access_token      
end

#statusesObject



45
46
47
# File 'lib/weibo_2/client.rb', line 45

def statuses
  @statues ||= WeiboOAuth2::Api::V2::Statuses.new(@access_token) if @access_token
end

#suggestionsObject



85
86
87
# File 'lib/weibo_2/client.rb', line 85

def suggestions
  @suggestions ||= WeiboOAuth2::Api::V2::Suggestions.new(@access_token) if @access_token      
end

#tagsObject



69
70
71
# File 'lib/weibo_2/client.rb', line 69

def tags
  @tags ||= WeiboOAuth2::Api::V2::Tags.new(@access_token) if @access_token      
end


65
66
67
# File 'lib/weibo_2/client.rb', line 65

def trends
  @trends ||= WeiboOAuth2::Api::V2::Trends.new(@access_token) if @access_token      
end

#usersObject



41
42
43
# File 'lib/weibo_2/client.rb', line 41

def users
  @users ||= WeiboOAuth2::Api::V2::Users.new(@access_token) if @access_token
end