Class: Weibo::Client

Inherits:
OAuth2::Client
  • Object
show all
Defined in:
lib/weibo_focus/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_focus/client.rb', line 6

def initialize(client_id='', client_secret='', opts={}, &block)
  client_id = Weibo::Config.api_key if client_id.empty?
  client_secret = Weibo::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



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

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

#auth_codeObject



113
114
115
# File 'lib/weibo_focus/client.rb', line 113

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

#authorize_url(params = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/weibo_focus/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] = Weibo::Config.redirect_uri unless params[:redirect_uri]
  super
end

#authorized?Boolean

Returns:

  • (Boolean)


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

def authorized?
  !!@access_token
end

#commentsObject



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

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

#commonObject



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

def common
  @common ||= Weibo::Api::V2::Common.new(@access_token) if @access_token      
end

#favoritesObject



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

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

#friendshipsObject



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

def friendships
  @friendships ||= Weibo::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_focus/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_focus/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
36
37
38
39
# File 'lib/weibo_focus/client.rb', line 32

def get_token_from_hash(hash)
  access_token = hash.delete(:access_token) || hash.delete('access_token')
  opts = {:expires_at => (hash.delete(:expires_at) || hash.delete('expires_at')),
          :header_format => "OAuth2 %s",
          :param_name => "access_token"}

  @access_token = Weibo::AccessToken.new(self, access_token, opts)
end

#locationObject



109
110
111
# File 'lib/weibo_focus/client.rb', line 109

def location
  @location ||= Weibo::Api::V2::Location.new(@access_token) if @access_token      
end

#notificationObject



105
106
107
# File 'lib/weibo_focus/client.rb', line 105

def notification
  @notification ||= Weibo::Api::V2::Notification.new(@access_token) if @access_token      
end

#placeObject



101
102
103
# File 'lib/weibo_focus/client.rb', line 101

def place
  @place ||= Weibo::Api::V2::Place.new(@access_token) if @access_token      
end

#registerObject



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

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

#remindObject



97
98
99
# File 'lib/weibo_focus/client.rb', line 97

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

#searchObject



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

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

#short_urlObject



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

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

#statusesObject



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

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

#suggestionsObject



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

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

#tagsObject



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

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


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

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

#usersObject



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

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