Class: DeviantArt::Client

Inherits:
Object
  • Object
show all
Includes:
Collections, Data, Deviation, Feed, Gallery, User
Defined in:
lib/deviantart/client.rb

Constant Summary collapse

@@host =
'www.deviantart.com'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Feed

#get_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.

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deviantart/client.rb', line 27

def initialize(options = {})
  @access_token = nil
  options.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
  @on_refreshed_authorization_code = nil
end

Instance Attribute Details

#access_tokenObject

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_refreshObject

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_idObject

Returns the value of attribute client_id.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def client_secret
  @client_secret
end

#codeObject

Returns the value of attribute code.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def code
  @code
end

#grant_typeObject

Returns the value of attribute grant_type.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def grant_type
  @grant_type
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def redirect_uri
  @redirect_uri
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



23
24
25
# File 'lib/deviantart/client.rb', line 23

def refresh_token
  @refresh_token
end

#user_agentObject



43
44
45
# File 'lib/deviantart/client.rb', line 43

def user_agent
  @user_agent ||= "DeviantArtRubyGem/#{DeviantArt::VERSION}/#{RUBY_DESCRIPTION}"
end

Class Method Details

.hostObject



39
40
41
# File 'lib/deviantart/client.rb', line 39

def self.host
  @@host
end

Instance Method Details

#access_token_auto_refresh?Boolean

Returns:

  • (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 on_refreshed_authorization_code(&block)
  @on_refreshed_authorization_code = 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