deviantart 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Rakefile +5 -1
- data/lib/deviantart.rb +1 -0
- data/lib/deviantart/client.rb +45 -15
- data/lib/deviantart/collections.rb +2 -0
- data/lib/deviantart/deviation.rb +2 -0
- data/lib/deviantart/feed.rb +2 -0
- data/lib/deviantart/gallery.rb +2 -0
- data/lib/deviantart/user.rb +21 -2
- data/lib/deviantart/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d5b6643a6f9af4d75fe988cb96492aea502fb2
|
4
|
+
data.tar.gz: ab439f5a0ac0c932663b906ac8a11335d57ea832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a28ea7daf05f8bfe250154e7c98de8d3481f08bf802bb71c020f81763c7e71f10d9dbfdf2b448a5bf0609cdf7815b16d5b0edb0e03088b553ae9b2efcfbfdd5
|
7
|
+
data.tar.gz: 6844ec96b4fa3c0378710077ebde6eba9167d5f6ddfa68b1eaa0ae4d5632c0f222ebaf06e74cf26abae88c6907b08ccd630d88b0456789eb64b507e8dc50fd7b
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -62,7 +62,7 @@ def get_access_token
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
task :access_token do
|
66
66
|
AUTHORIZATION_CODE_FILE = 'test/fixtures/authorization_code.json'
|
67
67
|
if !File.exists?(AUTHORIZATION_CODE_FILE)
|
68
68
|
OUTPUT_PIPE = 'test/output_pipe'
|
@@ -73,6 +73,10 @@ Rake::TestTask.new(:real) do |t|
|
|
73
73
|
get_access_token
|
74
74
|
File.unlink(OUTPUT_PIPE)
|
75
75
|
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Rake::TestTask.new(:real) do |t|
|
79
|
+
t.deps << :access_token
|
76
80
|
t.ruby_opts << '-I. -e "ENV[\'REAL\']=\'1\'"'
|
77
81
|
t.loader = :direct
|
78
82
|
t.libs << "test"
|
data/lib/deviantart.rb
CHANGED
data/lib/deviantart/client.rb
CHANGED
@@ -4,6 +4,7 @@ require 'deviantart/collections'
|
|
4
4
|
require 'deviantart/user'
|
5
5
|
require 'deviantart/data'
|
6
6
|
require 'deviantart/feed'
|
7
|
+
# TODO: comments, cured, messages, notes, stash, util
|
7
8
|
require 'net/http'
|
8
9
|
require 'uri'
|
9
10
|
require 'json'
|
@@ -20,34 +21,61 @@ module DeviantArt
|
|
20
21
|
include DeviantArt::User
|
21
22
|
include DeviantArt::Data
|
22
23
|
include DeviantArt::Feed
|
23
|
-
attr_accessor :access_token, :client_id, :client_secret, :code, :redirect_uri, :grant_type, :access_token_auto_refresh, :refresh_token
|
24
|
+
attr_accessor :access_token, :client_id, :client_secret, :code, :redirect_uri, :grant_type, :access_token_auto_refresh, :refresh_token, :host
|
24
25
|
attr_writer :user_agent
|
25
|
-
@@
|
26
|
+
@@default_host = 'www.deviantart.com'
|
26
27
|
|
28
|
+
# Create client object.
|
29
|
+
#
|
30
|
+
# [#host] Host name to access API.
|
31
|
+
# [#access_token_auto_refresh] Bool for auto refresh access token.
|
32
|
+
# [#grant_type]
|
33
|
+
# Use for refresh token.
|
34
|
+
# - +:authorization_code+
|
35
|
+
# - +:client_credentials+
|
36
|
+
# [#access_token] This is valid access token for now.
|
37
|
+
#
|
38
|
+
# For refresh token with +:authorization_code+
|
39
|
+
#
|
40
|
+
# [#client_id] App's +client_id+.
|
41
|
+
# [#client_secret] App's +client_secret+.
|
42
|
+
# [#redirect_uri] URL what is exactly match the value in authorization step.
|
43
|
+
# [#code] Authorization step returns this.
|
44
|
+
# [#refresh_token] Refresh token for +:authorization_code+.
|
45
|
+
#
|
46
|
+
# For refresh token with +:client_credentials+
|
47
|
+
#
|
48
|
+
# [#client_id] App's +client_id+.
|
49
|
+
# [#client_secret] App's +client_secret+.
|
27
50
|
def initialize(options = {})
|
28
51
|
@access_token = nil
|
52
|
+
@host = @@default_host
|
53
|
+
@on_refresh_access_token = nil
|
54
|
+
@on_refresh_authorization_code = nil
|
29
55
|
options.each do |key, value|
|
30
56
|
instance_variable_set("@#{key}", value)
|
31
57
|
end
|
32
58
|
yield(self) if block_given?
|
33
|
-
@http = Net::HTTP.new(
|
59
|
+
@http = Net::HTTP.new(@host, 443)
|
34
60
|
@http.use_ssl = true
|
35
|
-
@on_refreshed_access_token = nil
|
36
|
-
@on_refreshed_authorization_code = nil
|
37
61
|
end
|
38
62
|
|
39
|
-
|
40
|
-
|
63
|
+
# Default host name, it's 'www.deviantart.com'
|
64
|
+
def self.default_host
|
65
|
+
@@default_host
|
41
66
|
end
|
42
67
|
|
68
|
+
# User agent name
|
43
69
|
def user_agent
|
44
70
|
@user_agent ||= "DeviantArtRubyGem/#{DeviantArt::VERSION}/#{RUBY_DESCRIPTION}"
|
45
71
|
end
|
46
72
|
|
73
|
+
# Auto refresh access token flag
|
47
74
|
def access_token_auto_refresh?
|
48
75
|
@access_token_auto_refresh
|
49
76
|
end
|
50
77
|
|
78
|
+
# Access API with params by method
|
51
79
|
def perform(method, path, params = {})
|
52
80
|
if @access_token.nil? && access_token_auto_refresh?
|
53
81
|
refresh_access_token
|
@@ -60,18 +88,20 @@ module DeviantArt
|
|
60
88
|
response.json
|
61
89
|
end
|
62
90
|
|
63
|
-
|
64
|
-
|
91
|
+
# Call given block when authorization code is refreshed
|
92
|
+
def on_refresh_authorization_code(&block)
|
93
|
+
@on_refresh_authorization_code = block
|
65
94
|
end
|
66
95
|
|
67
|
-
|
68
|
-
|
96
|
+
# Call given block when access token is refreshed
|
97
|
+
def on_refresh_access_token(&block)
|
98
|
+
@on_refresh_access_token = block
|
69
99
|
end
|
70
100
|
|
71
101
|
private
|
72
102
|
|
73
103
|
def request(method, path, params = {})
|
74
|
-
uri = URI.parse("https://#{
|
104
|
+
uri = URI.parse("https://#{@host}#{path}")
|
75
105
|
case method
|
76
106
|
when :get
|
77
107
|
uri.query = URI.encode_www_form(params)
|
@@ -111,7 +141,7 @@ module DeviantArt
|
|
111
141
|
)
|
112
142
|
if response.code == '200'
|
113
143
|
@access_token = response.json['access_token']
|
114
|
-
@
|
144
|
+
@on_refresh_access_token.call(@access_token) if @on_refresh_access_token
|
115
145
|
else
|
116
146
|
@access_token = nil
|
117
147
|
end
|
@@ -124,8 +154,8 @@ module DeviantArt
|
|
124
154
|
)
|
125
155
|
if response.code == '200'
|
126
156
|
@access_token = response.json['access_token']
|
127
|
-
@
|
128
|
-
@
|
157
|
+
@on_refresh_access_token.call(@access_token) if @on_refresh_access_token
|
158
|
+
@on_refresh_authorization_code.call(@access_token, response.json['refresh_token']) if @on_refresh_authorization_code
|
129
159
|
else
|
130
160
|
@access_token = nil
|
131
161
|
end
|
data/lib/deviantart/deviation.rb
CHANGED
data/lib/deviantart/feed.rb
CHANGED
data/lib/deviantart/gallery.rb
CHANGED
data/lib/deviantart/user.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DeviantArt
|
2
2
|
module User
|
3
3
|
# Get user profile information
|
4
|
-
def get_profile(username
|
4
|
+
def get_profile(username, ext_collections: false, ext_galleries: false)
|
5
5
|
params = {}
|
6
6
|
params['ext_collections'] = ext_collections if ext_collections
|
7
7
|
params['ext_galleries'] = ext_galleries if ext_galleries
|
@@ -9,7 +9,7 @@ module DeviantArt
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Get the users list of friends
|
12
|
-
def get_friends(username
|
12
|
+
def get_friends(username, offset: 0, limit: 10)
|
13
13
|
params = {}
|
14
14
|
params['offset'] = offset if offset != 0
|
15
15
|
params['limit'] = limit if limit != 10
|
@@ -26,6 +26,25 @@ module DeviantArt
|
|
26
26
|
def whoami
|
27
27
|
perform(:get, '/api/v1/oauth2/user/whoami?')
|
28
28
|
end
|
29
|
+
|
30
|
+
# Search friends by username
|
31
|
+
def search_friends(query, username: nil)
|
32
|
+
params = {}
|
33
|
+
params['query'] = query
|
34
|
+
params['username'] = username unless username.nil?
|
35
|
+
perform(:get, '/api/v1/oauth2/user/friends/search', params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_statuses(username, offset: 0, limit: 10, mature_content: false)
|
39
|
+
params = {}
|
40
|
+
params['username'] = username
|
41
|
+
params['mature_content'] = mature_content
|
42
|
+
params['offset'] = offset if offset != 0
|
43
|
+
params['limit'] = limit if limit != 10
|
44
|
+
perform(:get, '/api/v1/oauth2/user/statuses/', params)
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: damntoken, friends/unwatch/{username}, friends/watch/{username}, friends/watching/{username}, profile/update, ertatuses/{statusid}, statuses/post, watchers/{username}
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
data/lib/deviantart/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deviantart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Ass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|