Class: Weibo2::Client
- Inherits:
-
OAuth2::Client
- Object
- OAuth2::Client
- Weibo2::Client
- Defined in:
- lib/weibo2/client.rb
Overview
The Weibo2::Client class
Instance Attribute Summary collapse
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
-
.from_code(code, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a signed_request.
-
.from_hash(hash, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a hash.
-
.from_signed_request(signed_request, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a signed_request.
Instance Method Summary collapse
-
#account ⇒ Object
APIs.
-
#auth_code ⇒ Object
The Authorization Code strategy.
- #comments ⇒ Object
- #favorites ⇒ Object
- #friendships ⇒ Object
-
#get_token(params, access_token_opts = {}) ⇒ AccessToken
Initializes an AccessToken by making a request to the token endpoint.
-
#get_token_from_hash(hash) ⇒ AccessToken
Initializes an AccessToken from a hash.
-
#initialize(opts = {}) {|builder| ... } ⇒ Client
constructor
Initializes a new Client.
-
#is_authorized? ⇒ Boolean
Whether or not the client is authorized.
-
#password ⇒ Object
The Resource Owner Password Credentials strategy.
-
#refresh!(params = {}) ⇒ AccessToken
Refreshes the current Access Token.
- #register ⇒ Object
- #search ⇒ Object
-
#signed_request ⇒ Object
The Signed Request Strategy.
- #statuses ⇒ Object
- #suggestions ⇒ Object
- #tags ⇒ Object
- #trends ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(opts = {}) {|builder| ... } ⇒ Client
Initializes a new Client
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/weibo2/client.rb', line 59 def initialize(opts={}, &block) id = Weibo2::Config.api_key secret = Weibo2::Config.api_secret @redirect_uri = Weibo2::Config.redirect_uri = {:site => "https://api.weibo.com/2/", :authorize_url => "/oauth2/authorize", :token_url => "/oauth2/access_token", :raise_errors => false, :ssl => {:verify => false}}.merge(opts) super(id, secret, , &block) end |
Instance Attribute Details
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
8 9 10 |
# File 'lib/weibo2/client.rb', line 8 def redirect_uri @redirect_uri end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/weibo2/client.rb', line 9 def token @token end |
Class Method Details
.from_code(code, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a signed_request
18 19 20 21 22 23 |
# File 'lib/weibo2/client.rb', line 18 def self.from_code(code, opts={}, &block) client = self.new(opts, &block) client.auth_code.get_token(code) client end |
.from_hash(hash, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a hash
46 47 48 49 50 51 |
# File 'lib/weibo2/client.rb', line 46 def self.from_hash(hash, opts={}, &block) client = self.new(opts, &block) client.get_token_from_hash(hash) client end |
.from_signed_request(signed_request, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a signed_request
32 33 34 35 36 37 |
# File 'lib/weibo2/client.rb', line 32 def self.from_signed_request(signed_request, opts={}, &block) client = self.new(opts, &block) client.signed_request.get_token(signed_request) client end |
Instance Method Details
#account ⇒ Object
APIs
142 143 144 |
# File 'lib/weibo2/client.rb', line 142 def account @account ||= Weibo2::Interface::Account.new(self) end |
#auth_code ⇒ Object
The Authorization Code strategy
120 121 122 |
# File 'lib/weibo2/client.rb', line 120 def auth_code @auth_code ||= Weibo2::Strategy::AuthCode.new(self) end |
#comments ⇒ Object
146 147 148 |
# File 'lib/weibo2/client.rb', line 146 def comments @comments ||= Weibo2::Interface::Comments.new(self) end |
#favorites ⇒ Object
150 151 152 |
# File 'lib/weibo2/client.rb', line 150 def favorites @favorites ||= Weibo2::Interface::Favorites.new(self) end |
#friendships ⇒ Object
154 155 156 |
# File 'lib/weibo2/client.rb', line 154 def friendships @friendships ||= Weibo2::Interface::Friendships.new(self) end |
#get_token(params, access_token_opts = {}) ⇒ AccessToken
Initializes an AccessToken by making a request to the token endpoint
85 86 87 88 89 90 |
# File 'lib/weibo2/client.rb', line 85 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"}) @token = super(params, access_token_opts) end |
#get_token_from_hash(hash) ⇒ AccessToken
Initializes an AccessToken from a hash
96 97 98 99 100 101 102 103 |
# File 'lib/weibo2/client.rb', line 96 def get_token_from_hash(hash) access_token = hash.delete('access_token') || hash.delete(:access_token) || hash.delete('oauth_token') || hash.delete(:oauth_token) opts = {:expires_at => hash["expires"] || hash[:expires], :header_format => "OAuth2 %s", :param_name => "access_token"} @token = OAuth2::AccessToken.new(self, access_token, opts) end |
#is_authorized? ⇒ Boolean
Whether or not the client is authorized
76 77 78 |
# File 'lib/weibo2/client.rb', line 76 def !!token && !token.expired? end |
#password ⇒ Object
The Resource Owner Password Credentials strategy
127 128 129 |
# File 'lib/weibo2/client.rb', line 127 def password super end |
#refresh!(params = {}) ⇒ AccessToken
options should be carried over to the new AccessToken
Refreshes the current Access Token
109 110 111 |
# File 'lib/weibo2/client.rb', line 109 def refresh!(params={}) @token = token.refresh!(params) end |
#register ⇒ Object
158 159 160 |
# File 'lib/weibo2/client.rb', line 158 def register @register ||= Weibo2::Interface::Register.new(self) end |
#search ⇒ Object
162 163 164 |
# File 'lib/weibo2/client.rb', line 162 def search @search ||= Weibo2::Interface::Search.new(self) end |
#signed_request ⇒ Object
The Signed Request Strategy
134 135 136 |
# File 'lib/weibo2/client.rb', line 134 def signed_request @signed_request ||= Weibo2::Strategy::SignedRequest.new(self) end |
#statuses ⇒ Object
166 167 168 |
# File 'lib/weibo2/client.rb', line 166 def statuses @statuses ||= Weibo2::Interface::Statuses.new(self) end |
#suggestions ⇒ Object
170 171 172 |
# File 'lib/weibo2/client.rb', line 170 def suggestions @suggestions ||= Weibo2::Interface::Suggestions.new(self) end |
#tags ⇒ Object
174 175 176 |
# File 'lib/weibo2/client.rb', line 174 def @tags ||= Weibo2::Interface::Tags.new(self) end |