Class: Renren2::Client
- Inherits:
-
OAuth2::Client
- Object
- OAuth2::Client
- Renren2::Client
- Defined in:
- lib/renren2/client.rb
Overview
The Renren2::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 authentication_code.
-
.from_hash(hash, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a hash.
Instance Method Summary collapse
-
#admin ⇒ Object
APIs.
-
#auth_code ⇒ Object
The Authorization Code strategy.
- #blog ⇒ Object
- #checkins ⇒ Object
- #feed ⇒ Object
- #friends ⇒ 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.
- #hash_for_save ⇒ Object
- #include_scope?(scope_name) ⇒ Boolean
-
#initialize(opts = {}) {|builder| ... } ⇒ Client
constructor
Initializes a new Client.
- #invitations ⇒ Object
-
#is_authorized? ⇒ Boolean
Whether or not the client is authorized.
- #like ⇒ Object
- #notifications ⇒ Object
- #pages ⇒ Object
-
#password ⇒ Object
The Resource Owner Password Credentials strategy.
- #pay ⇒ Object
- #photos ⇒ Object
- #places ⇒ Object
-
#refresh!(params = {}) ⇒ AccessToken
Refreshes the current Access Token.
- #requests ⇒ Object
- #scope ⇒ Object
- #share ⇒ Object
- #status ⇒ Object
-
#user ⇒ Object
Some info.
- #user_id ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(opts = {}) {|builder| ... } ⇒ Client
Initializes a new Client
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/renren2/client.rb', line 45 def initialize(opts={}, &block) id = Renren2::Config.api_key secret = Renren2::Config.api_secret @redirect_uri = Renren2::Config.redirect_uri = {:site => "https://graph.renren.com", :authorize_url => "/oauth/authorize", :token_url => "/oauth/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/renren2/client.rb', line 8 def redirect_uri @redirect_uri end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/renren2/client.rb', line 9 def token @token end |
Class Method Details
.from_code(code, opts = {}) {|builder| ... } ⇒ Object
Initializes a new Client from a authentication_code
18 19 20 21 22 23 |
# File 'lib/renren2/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
32 33 34 35 36 37 |
# File 'lib/renren2/client.rb', line 32 def self.from_hash(hash, opts={}, &block) client = self.new(opts, &block) client.get_token_from_hash(hash) client end |
Instance Method Details
#admin ⇒ Object
APIs
155 156 157 |
# File 'lib/renren2/client.rb', line 155 def admin @admin ||= Renren2::Interface::Admin.new(self) end |
#auth_code ⇒ Object
The Authorization Code strategy
140 141 142 |
# File 'lib/renren2/client.rb', line 140 def auth_code @auth_code ||= Renren2::Strategy::AuthCode.new(self) end |
#blog ⇒ Object
159 160 161 |
# File 'lib/renren2/client.rb', line 159 def blog @blog ||= Renren2::Interface::Blog.new(self) end |
#checkins ⇒ Object
163 164 165 |
# File 'lib/renren2/client.rb', line 163 def checkins @checkins ||= Renren2::Interface::Checkins.new(self) end |
#feed ⇒ Object
167 168 169 |
# File 'lib/renren2/client.rb', line 167 def feed @feed ||= Renren2::Interface::Feed.new(self) end |
#friends ⇒ Object
171 172 173 |
# File 'lib/renren2/client.rb', line 171 def friends @friends ||= Renren2::Interface::Friends.new(self) end |
#get_token(params, access_token_opts = {}) ⇒ AccessToken
Initializes an AccessToken by making a request to the token endpoint
71 72 73 74 75 76 |
# File 'lib/renren2/client.rb', line 71 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 => "oauth_token"}) @token = super(params, access_token_opts) end |
#get_token_from_hash(hash) ⇒ AccessToken
Initializes an AccessToken from a hash
82 83 84 85 86 87 88 89 |
# File 'lib/renren2/client.rb', line 82 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.delete("expires") || hash.delete(:expires), :header_format => "OAuth2 %s", :param_name => "oauth_token"}.merge(hash) @token = OAuth2::AccessToken.new(self, access_token, opts) end |
#hash_for_save ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/renren2/client.rb', line 124 def hash_for_save if token token.params.merge({"expires_in" => token.expires_in, "expires_at" => token.expires_at, "refresh_token" => token.refresh_token, "access_token" => token.token}) end end |
#include_scope?(scope_name) ⇒ Boolean
115 116 117 118 119 120 121 122 |
# File 'lib/renren2/client.rb', line 115 def include_scope?(scope_name) return true if token && token.params["scope"] token.params["scope"].split.include? scope_name else false end end |
#invitations ⇒ Object
175 176 177 |
# File 'lib/renren2/client.rb', line 175 def invitations @invitations ||= Renren2::Interface::Invitations.new(self) end |
#is_authorized? ⇒ Boolean
Whether or not the client is authorized
62 63 64 |
# File 'lib/renren2/client.rb', line 62 def !!token && !token.expired? end |
#like ⇒ Object
179 180 181 |
# File 'lib/renren2/client.rb', line 179 def like @like ||= Renren2::Interface::Like.new(self) end |
#notifications ⇒ Object
183 184 185 |
# File 'lib/renren2/client.rb', line 183 def notifications @notifications ||= Renren2::Interface::Notifications.new(self) end |
#pages ⇒ Object
187 188 189 |
# File 'lib/renren2/client.rb', line 187 def pages @pages ||= Renren2::Interface::Pages.new(self) end |
#password ⇒ Object
The Resource Owner Password Credentials strategy
147 148 149 |
# File 'lib/renren2/client.rb', line 147 def password super end |
#pay ⇒ Object
191 192 193 |
# File 'lib/renren2/client.rb', line 191 def pay @pay ||= Renren2::Interface::Pay.new(self) end |
#photos ⇒ Object
195 196 197 |
# File 'lib/renren2/client.rb', line 195 def photos @photos ||= Renren2::Interface::Photos.new(self) end |
#places ⇒ Object
199 200 201 |
# File 'lib/renren2/client.rb', line 199 def places @places ||= Renren2::Interface::Places.new(self) end |
#refresh!(params = {}) ⇒ AccessToken
options should be carried over to the new AccessToken
Refreshes the current Access Token
95 96 97 |
# File 'lib/renren2/client.rb', line 95 def refresh!(params={}) @token = token.refresh!(params) end |
#requests ⇒ Object
203 204 205 |
# File 'lib/renren2/client.rb', line 203 def requests @requests ||= Renren2::Interface::Requests.new(self) end |
#scope ⇒ Object
111 112 113 |
# File 'lib/renren2/client.rb', line 111 def scope token.params["scope"] if token end |
#share ⇒ Object
207 208 209 |
# File 'lib/renren2/client.rb', line 207 def share @share ||= Renren2::Interface::Share.new(self) end |
#status ⇒ Object
211 212 213 |
# File 'lib/renren2/client.rb', line 211 def status @status ||= Renren2::Interface::Status.new(self) end |
#user ⇒ Object
Some info
103 104 105 |
# File 'lib/renren2/client.rb', line 103 def user token.params["user"] if token end |
#user_id ⇒ Object
107 108 109 |
# File 'lib/renren2/client.rb', line 107 def user_id user["id"] if user end |