Class: DeviantArt::Client
- Inherits:
-
Object
- Object
- DeviantArt::Client
- Defined in:
- lib/deviantart/client.rb
Constant Summary collapse
- @@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.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
- #user_agent ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #access_token_auto_refresh? ⇒ Boolean
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #on_refreshed_access_token(&block) ⇒ Object
- #on_refreshed_authorization_code(&block) ⇒ Object
- #perform(method, path, params = {}) ⇒ Object
Methods included from Feed
Methods included from Data
#get_countries, #get_privacy, #get_submission, #get_tos
Methods included from User
#get_friends, #get_profile, #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
Returns a new instance of Client.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deviantart/client.rb', line 27 def initialize( = {}) @access_token = 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 @on_refreshed_access_token = nil = nil end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def access_token @access_token end |
#access_token_auto_refresh ⇒ Object
Returns the value of attribute access_token_auto_refresh.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def access_token_auto_refresh @access_token_auto_refresh end |
#client_id ⇒ Object
Returns the value of attribute client_id.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def client_secret @client_secret end |
#code ⇒ Object
Returns the value of attribute code.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def code @code end |
#grant_type ⇒ Object
Returns the value of attribute grant_type.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def grant_type @grant_type end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
23 24 25 |
# File 'lib/deviantart/client.rb', line 23 def refresh_token @refresh_token end |
#user_agent ⇒ Object
43 44 45 |
# File 'lib/deviantart/client.rb', line 43 def user_agent @user_agent ||= "DeviantArtRubyGem/#{DeviantArt::VERSION}/#{RUBY_DESCRIPTION}" end |
Class Method Details
.host ⇒ Object
39 40 41 |
# File 'lib/deviantart/client.rb', line 39 def self.host @@host end |
Instance Method Details
#access_token_auto_refresh? ⇒ Boolean
47 48 49 |
# File 'lib/deviantart/client.rb', line 47 def access_token_auto_refresh? @access_token_auto_refresh end |
#on_refreshed_access_token(&block) ⇒ Object
67 68 69 |
# File 'lib/deviantart/client.rb', line 67 def on_refreshed_access_token(&block) @on_refreshed_access_token = block end |
#on_refreshed_authorization_code(&block) ⇒ Object
63 64 65 |
# File 'lib/deviantart/client.rb', line 63 def (&block) = block end |
#perform(method, path, params = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/deviantart/client.rb', line 51 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 |