Class: DeviantArt::Client
- Inherits:
-
Object
- Object
- DeviantArt::Client
- Defined in:
- lib/deviantart/client.rb
Constant Summary collapse
- @@default_host =
'www.deviantart.com'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#access_token_auto_refresh ⇒ Object
Returns the value of attribute access_token_auto_refresh.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#code ⇒ Object
Returns the value of attribute code.
-
#grant_type ⇒ Object
Returns the value of attribute grant_type.
-
#host ⇒ Object
Returns the value of attribute host.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#user_agent ⇒ Object
User agent name.
Class Method Summary collapse
-
.default_host ⇒ Object
Default host name, it’s ‘www.deviantart.com’.
Instance Method Summary collapse
-
#access_token_auto_refresh? ⇒ Boolean
Auto refresh access token flag.
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
Create client object.
-
#on_refresh_access_token(&block) ⇒ Object
Call given block when access token is refreshed.
-
#on_refresh_authorization_code(&block) ⇒ Object
Call given block when authorization code is refreshed.
-
#perform(method, path, params = {}) ⇒ Object
Access API with params by method.
Methods included from Feed
Methods included from Data
#get_countries, #get_privacy, #get_submission, #get_tos
Methods included from User
#get_friends, #get_profile, #get_statuses, #search_friends, #whoami, #whois
Methods included from Collections
#get_collections, #get_collections_folders
Methods included from Gallery
#get_gallery, #get_gallery_all, #get_gallery_folders
Methods included from Deviation
#download_deviation, #get_deviation, #get_deviation_content, #get_deviation_whofaved
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Create client object.
- #host
-
Host name to access API.
- #access_token_auto_refresh
-
Bool for auto refresh access token.
- #grant_type
-
Use for refresh token.
-
:authorization_code -
:client_credentials
-
- #access_token
-
This is valid access token for now.
For refresh token with :authorization_code
- #client_id
-
App’s
client_id. - #client_secret
-
App’s
client_secret. - #redirect_uri
-
URL what is exactly match the value in authorization step.
- #code
-
Authorization step returns this.
- #refresh_token
-
Refresh token for
:authorization_code.
For refresh token with :client_credentials
- #client_id
-
App’s
client_id. - #client_secret
-
App’s
client_secret.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/deviantart/client.rb', line 50 def initialize( = {}) @access_token = nil @host = @@default_host @on_refresh_access_token = nil = nil .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? @http = Net::HTTP.new(@host, 443) @http.use_ssl = true end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def access_token @access_token end |
#access_token_auto_refresh ⇒ Object
Returns the value of attribute access_token_auto_refresh.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def access_token_auto_refresh @access_token_auto_refresh end |
#client_id ⇒ Object
Returns the value of attribute client_id.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def client_secret @client_secret end |
#code ⇒ Object
Returns the value of attribute code.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def code @code end |
#grant_type ⇒ Object
Returns the value of attribute grant_type.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def grant_type @grant_type end |
#host ⇒ Object
Returns the value of attribute host.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def host @host end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
24 25 26 |
# File 'lib/deviantart/client.rb', line 24 def refresh_token @refresh_token end |
#user_agent ⇒ Object
User agent name
69 70 71 |
# File 'lib/deviantart/client.rb', line 69 def user_agent @user_agent ||= "DeviantArtRubyGem/#{DeviantArt::VERSION}/#{RUBY_DESCRIPTION}" end |
Class Method Details
.default_host ⇒ Object
Default host name, it’s ‘www.deviantart.com’
64 65 66 |
# File 'lib/deviantart/client.rb', line 64 def self.default_host @@default_host end |
Instance Method Details
#access_token_auto_refresh? ⇒ Boolean
Auto refresh access token flag
74 75 76 |
# File 'lib/deviantart/client.rb', line 74 def access_token_auto_refresh? @access_token_auto_refresh end |
#on_refresh_access_token(&block) ⇒ Object
Call given block when access token is refreshed
97 98 99 |
# File 'lib/deviantart/client.rb', line 97 def on_refresh_access_token(&block) @on_refresh_access_token = block end |
#on_refresh_authorization_code(&block) ⇒ Object
Call given block when authorization code is refreshed
92 93 94 |
# File 'lib/deviantart/client.rb', line 92 def (&block) = block end |
#perform(method, path, params = {}) ⇒ Object
Access API with params by method
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/deviantart/client.rb', line 79 def perform(method, path, params = {}) if @access_token.nil? && access_token_auto_refresh? refresh_access_token end response = request(method, path, params) if response.code == '401' && access_token_auto_refresh? refresh_access_token response = request(method, path, params) end response.json end |