Class: Weibo::Client
- Inherits:
-
OAuth2::Client
- Object
- OAuth2::Client
- Weibo::Client
- Defined in:
- lib/weibo_focus/client.rb
Instance Method Summary collapse
- #account ⇒ Object
- #auth_code ⇒ Object
- #authorize_url(params = {}) ⇒ Object
- #authorized? ⇒ Boolean
- #comments ⇒ Object
- #common ⇒ 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
- #notification ⇒ 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.
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
#account ⇒ Object
61 62 63 |
# File 'lib/weibo_focus/client.rb', line 61 def account @account ||= Weibo::Api::V2::Account.new(@access_token) if @access_token end |
#auth_code ⇒ Object
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 (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
41 42 43 |
# File 'lib/weibo_focus/client.rb', line 41 def !!@access_token end |
#comments ⇒ Object
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 |
#common ⇒ Object
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 |
#favorites ⇒ Object
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 |
#friendships ⇒ Object
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 |
#location ⇒ Object
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 |
#notification ⇒ Object
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 |
#place ⇒ Object
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 |
#register ⇒ Object
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 |
#remind ⇒ Object
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 |
#search ⇒ Object
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_url ⇒ Object
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 |
#statuses ⇒ Object
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 |
#suggestions ⇒ Object
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 |
#tags ⇒ Object
73 74 75 |
# File 'lib/weibo_focus/client.rb', line 73 def @tags ||= Weibo::Api::V2::Tags.new(@access_token) if @access_token end |