deviantart 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/README.md +1 -1
  4. data/Rakefile +42 -26
  5. data/deviantart.gemspec +1 -1
  6. data/lib/deviantart.rb +6 -2
  7. data/lib/deviantart/base.rb +74 -0
  8. data/lib/deviantart/client.rb +52 -18
  9. data/lib/deviantart/client/collections.rb +30 -0
  10. data/lib/deviantart/client/data.rb +31 -0
  11. data/lib/deviantart/client/deviation.rb +36 -0
  12. data/lib/deviantart/client/feed.rb +18 -0
  13. data/lib/deviantart/client/gallery.rb +46 -0
  14. data/lib/deviantart/client/user.rb +75 -0
  15. data/lib/deviantart/collections.rb +5 -23
  16. data/lib/deviantart/collections/folders.rb +8 -0
  17. data/lib/deviantart/data.rb +3 -21
  18. data/lib/deviantart/data/countries.rb +7 -0
  19. data/lib/deviantart/data/privacy.rb +7 -0
  20. data/lib/deviantart/data/submission.rb +7 -0
  21. data/lib/deviantart/data/tos.rb +7 -0
  22. data/lib/deviantart/deviation.rb +9 -27
  23. data/lib/deviantart/deviation/content.rb +6 -0
  24. data/lib/deviantart/deviation/download.rb +6 -0
  25. data/lib/deviantart/deviation/whofaved.rb +7 -0
  26. data/lib/deviantart/error.rb +12 -0
  27. data/lib/deviantart/feed.rb +3 -11
  28. data/lib/deviantart/feed/home.rb +14 -0
  29. data/lib/deviantart/gallery.rb +5 -38
  30. data/lib/deviantart/gallery/all.rb +8 -0
  31. data/lib/deviantart/gallery/folders.rb +8 -0
  32. data/lib/deviantart/status.rb +10 -0
  33. data/lib/deviantart/user.rb +5 -53
  34. data/lib/deviantart/user/friends.rb +8 -0
  35. data/lib/deviantart/user/friends/search.rb +8 -0
  36. data/lib/deviantart/user/profile.rb +11 -0
  37. data/lib/deviantart/user/statuses.rb +8 -0
  38. data/lib/deviantart/user/watchers.rb +8 -0
  39. data/lib/deviantart/user/whois.rb +8 -0
  40. data/lib/deviantart/version.rb +1 -1
  41. metadata +29 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ca81525691db52ba0941c72234faf3c5067466f
4
- data.tar.gz: 14339469bd87431a08a7cc5fc88db0c78ddcd91e
3
+ metadata.gz: 162d1fde53c7eccf7687ae2392536e3b0bd0540a
4
+ data.tar.gz: 13ac6cbf255db8fd66ec059dbc2828b495990168
5
5
  SHA512:
6
- metadata.gz: 36bfe4f6b74e23e4e4a59fea897882bc1f6fe083555f0c9fc47418a912f7f2578d54902e08cb1fa2d1fb16572f5f43eb8db90c398eac074bfc034caa8bc6750a
7
- data.tar.gz: 096e49d7687efb0abba6d068a80d6c0e7f99a4dca9216ef1f79e99fe495e10508b81621bdfffe8881a7bc8d40645ae2c11acf23cdab24e79e6d3f6b208c2c811
6
+ metadata.gz: f39a3cfe0373bebd317ed7c22a7dfaf6356af1ddf641c0e62c15012edd0055d744b6c4a7165c3bbedb49ed45bdf418bb7532b3a0531394bd436092f1cd903123
7
+ data.tar.gz: 024e4b0350e98ad6d0a314733989c0167cd89bd209dcdabd1a940dc101a7d7e10e2a4bc6d9f019c07b57ba699212b3a965d330b12c6c0fbbbd01d1c3f1c4ad8f
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  language: ruby
3
- rvm: 2.3.1
4
- script: REAL='' bundle exec rake test
3
+ rvm: 2.3.3
4
+ script: bundle exec rake test
data/README.md CHANGED
@@ -34,7 +34,7 @@ And you will run test with stub APIs:
34
34
  $ bundle exec rake test
35
35
  ```
36
36
 
37
- If you want to use *real* API in test, run this one:
37
+ If you want to use **real** API in test, run this one:
38
38
 
39
39
  ```bash
40
40
  $ bundle exec rake real
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
- require "readline"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'readline'
4
+ require 'net/http'
5
+
6
+ BROWSER_COMMAND_FILE = 'test/browser_command'
7
+ AUTHORIZATION_CODE_FILE = 'test/fixtures/authorization_code.json'
8
+ OUTPUT_PIPE = 'test/output_pipe'
4
9
 
5
10
  test_pettern = FileList['test/**/*_test.rb']
6
11
 
@@ -11,20 +16,40 @@ Rake::TestTask.new(:test) do |t|
11
16
  end
12
17
 
13
18
  def get_browser_command
14
- browser_command_file = 'test/browser_command'
15
- if !File.exists?(browser_command_file)
16
- browser_command = Readline.readline('Input your browser command> ')
17
- open(browser_command_file, 'w') do |f|
18
- f.write(browser_command)
19
- end
20
- puts "Wrote \"#{browser_command}\" to #{browser_command_file}"
21
- browser_command
22
- else
23
- open(browser_command_file, 'r').read
19
+ open(BROWSER_COMMAND_FILE, 'r').read
20
+ end
21
+
22
+ file BROWSER_COMMAND_FILE do
23
+ browser_command = Readline.readline('Input your browser command> ')
24
+ open(BROWSER_COMMAND_FILE, 'w') do |f|
25
+ f.write(browser_command)
26
+ end
27
+ puts "Wrote \"#{browser_command}\" to #{BROWSER_COMMAND_FILE}"
28
+ end
29
+
30
+ def wait_oauth_consumer_booting
31
+ http = Net::HTTP.new('localhost', 4567)
32
+ http.open_timeout = 1
33
+ begin
34
+ http.start
35
+ rescue Errno::ECONNREFUSED
36
+ sleep 1
37
+ retry
38
+ rescue Net::OpenTimeout
39
+ retry
40
+ rescue => e
41
+ puts e.class.name
42
+ end
43
+ while http.head('/').code != '200'
44
+ sleep 1
24
45
  end
25
46
  end
26
47
 
27
- def get_access_token
48
+ file AUTHORIZATION_CODE_FILE => BROWSER_COMMAND_FILE do
49
+ if File.exists?(OUTPUT_PIPE)
50
+ File.unlink(OUTPUT_PIPE)
51
+ end
52
+ File.mkfifo(OUTPUT_PIPE)
28
53
  cv = ConditionVariable.new
29
54
  mutex = Mutex.new
30
55
  is_pinged = false
@@ -34,6 +59,7 @@ def get_access_token
34
59
  system('bundle exec ruby test/oauth_consumer.rb > /dev/null 2>&1 &')
35
60
  open(OUTPUT_PIPE).read # block to get 'ping'
36
61
  is_pinged = true
62
+ wait_oauth_consumer_booting
37
63
  cv.signal
38
64
  }
39
65
  }
@@ -60,20 +86,10 @@ def get_access_token
60
86
  open(AUTHORIZATION_CODE_FILE, 'w') do |f|
61
87
  f.write(result)
62
88
  end
89
+ File.unlink(OUTPUT_PIPE)
63
90
  end
64
91
 
65
- task :access_token do
66
- AUTHORIZATION_CODE_FILE = 'test/fixtures/authorization_code.json'
67
- if !File.exists?(AUTHORIZATION_CODE_FILE)
68
- OUTPUT_PIPE = 'test/output_pipe'
69
- if File.exists?(OUTPUT_PIPE)
70
- File.unlink(OUTPUT_PIPE)
71
- end
72
- File.mkfifo(OUTPUT_PIPE)
73
- get_access_token
74
- File.unlink(OUTPUT_PIPE)
75
- end
76
- end
92
+ task :access_token => AUTHORIZATION_CODE_FILE
77
93
 
78
94
  Rake::TestTask.new(:real) do |t|
79
95
  t.deps << :access_token
data/deviantart.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/aycabta/deviantart"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
18
18
  spec.bindir = "exe"
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
data/lib/deviantart.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "deviantart/version"
2
- require "deviantart/client"
1
+ require 'deviantart/version'
2
+ require 'deviantart/client'
3
+ require 'deviantart/base'
4
+ require 'deviantart/deviation'
5
+ require 'deviantart/user'
6
+ require 'deviantart/status'
3
7
 
4
8
  module DeviantArt
5
9
  # Bypass args and block to DeviantArt::Client
@@ -0,0 +1,74 @@
1
+ module DeviantArt
2
+ class Base
3
+ attr_reader :attrs
4
+ @points_class_mapping = {}
5
+
6
+ def initialize(attrs)
7
+ @attrs = attrs
8
+ define_hash_attrs(self, @attrs, [])
9
+ end
10
+
11
+ class << self
12
+ def points_class_mapping
13
+ @points_class_mapping ||= {}
14
+ end
15
+ def points_class_mapping=(v)
16
+ @points_class_mapping = v
17
+ end
18
+
19
+ def point_to_class(point, klass)
20
+ self.points_class_mapping[point] = klass
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def define_hash_attrs(receiver, attrs, point)
27
+ attrs.each_pair do |key, value|
28
+ attr_accessor_with_receiver(receiver, key)
29
+ receiver.instance_variable_set(:"@#{key}", nested_value(value, point + [key.to_sym]))
30
+ end
31
+ receiver
32
+ end
33
+
34
+ def attr_accessor_with_receiver(receiver, name)
35
+ receiver.instance_eval do
36
+ reader_name = name.to_sym
37
+ writer_name = :"#{name}="
38
+ variable_name = :"@#{name}"
39
+ if !receiver.respond_to?(reader_name)
40
+ define_singleton_method(reader_name, proc { |dummy=nil| instance_variable_get(variable_name) })
41
+ end
42
+ if !receiver.respond_to?(writer_name)
43
+ define_singleton_method(writer_name, method(:instance_variable_set).curry.(variable_name))
44
+ end
45
+ end
46
+ end
47
+
48
+ def define_array_attrs(array, attrs, point)
49
+ attrs.each do |value|
50
+ array << nested_value(value, point)
51
+ end
52
+ array
53
+ end
54
+
55
+ def nested_value(value, point)
56
+ if self.class.points_class_mapping.include?(point)
57
+ self.class.points_class_mapping[point].new(value)
58
+ else
59
+ case value
60
+ when Array
61
+ define_array_attrs(Array.new, value, point + [:[]])
62
+ when Hash
63
+ define_hash_attrs(Object.new, value, point)
64
+ else
65
+ value
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ class Deviation < Base; end
72
+ class User < Base; end
73
+ class Status < Base; end
74
+ end
@@ -1,10 +1,11 @@
1
- require 'deviantart/deviation'
2
- require 'deviantart/gallery'
3
- require 'deviantart/collections'
4
- require 'deviantart/user'
5
- require 'deviantart/data'
6
- require 'deviantart/feed'
1
+ require 'deviantart/client/deviation'
2
+ require 'deviantart/client/gallery'
3
+ require 'deviantart/client/collections'
4
+ require 'deviantart/client/user'
5
+ require 'deviantart/client/data'
6
+ require 'deviantart/client/feed'
7
7
  # TODO: comments, cured, messages, notes, stash, util
8
+ require 'deviantart/error'
8
9
  require 'net/http'
9
10
  require 'uri'
10
11
  require 'json'
@@ -15,13 +16,13 @@ end
15
16
 
16
17
  module DeviantArt
17
18
  class Client
18
- include DeviantArt::Deviation
19
- include DeviantArt::Gallery
20
- include DeviantArt::Collections
21
- include DeviantArt::User
22
- include DeviantArt::Data
23
- include DeviantArt::Feed
24
- attr_accessor :access_token, :client_id, :client_secret, :code, :redirect_uri, :grant_type, :access_token_auto_refresh, :refresh_token, :host
19
+ include DeviantArt::Client::Deviation
20
+ include DeviantArt::Client::Gallery
21
+ include DeviantArt::Client::Collections
22
+ include DeviantArt::Client::User
23
+ include DeviantArt::Client::Data
24
+ include DeviantArt::Client::Feed
25
+ attr_accessor :access_token, :client_id, :client_secret, :code, :redirect_uri, :grant_type, :access_token_auto_refresh, :refresh_token, :host, :headers
25
26
  attr_writer :user_agent
26
27
  @@default_host = 'www.deviantart.com'
27
28
 
@@ -42,6 +43,7 @@ module DeviantArt
42
43
  # [#redirect_uri] URL what is exactly match the value in authorization step.
43
44
  # [#code] Authorization step returns this.
44
45
  # [#refresh_token] Refresh token for +:authorization_code+.
46
+ # [#headers] Add custom headers for request.
45
47
  #
46
48
  # For refresh token with +:client_credentials+
47
49
  #
@@ -52,6 +54,9 @@ module DeviantArt
52
54
  @host = @@default_host
53
55
  @on_refresh_access_token = nil
54
56
  @on_refresh_authorization_code = nil
57
+ @access_token_auto_refresh = true
58
+ @grant_type = nil
59
+ @headers = {}
55
60
  options.each do |key, value|
56
61
  instance_variable_set("@#{key}", value)
57
62
  end
@@ -72,11 +77,11 @@ module DeviantArt
72
77
 
73
78
  # Auto refresh access token flag
74
79
  def access_token_auto_refresh?
75
- @access_token_auto_refresh
80
+ @access_token_auto_refresh && !@grant_type.nil?
76
81
  end
77
82
 
78
83
  # Access API with params by method
79
- def perform(method, path, params = {})
84
+ def perform(klass, method, path, params = {})
80
85
  if @access_token.nil? && access_token_auto_refresh?
81
86
  refresh_access_token
82
87
  end
@@ -85,7 +90,29 @@ module DeviantArt
85
90
  refresh_access_token
86
91
  response = request(method, path, params)
87
92
  end
88
- response.json
93
+ case response.code
94
+ when '200'
95
+ klass.new(response.json)
96
+ when '400'
97
+ # Request failed due to client error,
98
+ # e.g. validation failed or User not found
99
+ DeviantArt::Error.new(response.json, response.code.to_i)
100
+ when '401'
101
+ # Invalid token
102
+ DeviantArt::Error.new(response.json, response.code.to_i)
103
+ when '429'
104
+ # Rate limit reached or service overloaded
105
+ DeviantArt::Error.new(response.json, response.code.to_i)
106
+ when '500'
107
+ # Our servers encountered an internal error, try again
108
+ DeviantArt::Error.new(response.json, response.code.to_i)
109
+ when '503'
110
+ # Our servers are currently unavailable, try again later.
111
+ # This is normally due to planned or emergency maintenance.
112
+ DeviantArt::Error.new(response.json, response.code.to_i)
113
+ else
114
+ DeviantArt::Error.new(response.json, response.code.to_i)
115
+ end
89
116
  end
90
117
 
91
118
  # Call given block when authorization code is refreshed
@@ -129,8 +156,16 @@ module DeviantArt
129
156
  if not @access_token.nil?
130
157
  request["Authorization"] = "Bearer #{@access_token}"
131
158
  end
159
+ @headers.each_pair do |key, value|
160
+ request[key] = value
161
+ end
132
162
  response = @http.request(request)
133
- response.json = JSON.parse(response.body)
163
+ if response.code == '403'
164
+ # You must send User-Agent and use HTTP compression in request
165
+ response.json = JSON.parse('{}')
166
+ else
167
+ response.json = JSON.parse(response.body)
168
+ end
134
169
  response
135
170
  end
136
171
 
@@ -171,4 +206,3 @@ module DeviantArt
171
206
  end
172
207
  end
173
208
  end
174
-
@@ -0,0 +1,30 @@
1
+ require 'deviantart/collections'
2
+ require 'deviantart/collections/folders'
3
+
4
+ module DeviantArt
5
+ class Client
6
+ module Collections
7
+ # Fetch collection folders
8
+ def get_collections_folders(username: nil, calculate_size: false, ext_preload: false, offset: 0, limit: 10)
9
+ params = {}
10
+ params['username'] = username unless username.nil?
11
+ params['calculate_size'] = calculate_size if calculate_size
12
+ params['ext_preload'] = ext_preload if ext_preload
13
+ params['offset'] = offset if offset != 0
14
+ params['limit'] = limit if limit != 10
15
+ perform(DeviantArt::Collections::Folders, :get, '/api/v1/oauth2/collections/folders', params)
16
+ end
17
+
18
+ # Fetch collection folder contents
19
+ def get_collections(folderid, username: nil, offset: 0, limit: 10)
20
+ params = {}
21
+ params['username'] = username unless username.nil?
22
+ params['offset'] = offset if offset != 0
23
+ params['limit'] = limit if limit != 10
24
+ perform(DeviantArt::Collections, :get, "/api/v1/oauth2/collections/#{folderid}", params)
25
+ end
26
+
27
+ # TODO: fave, folders/create, folders/remove/{folderid}, unfav
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'deviantart/data'
2
+ require 'deviantart/data/countries'
3
+ require 'deviantart/data/privacy'
4
+ require 'deviantart/data/submission'
5
+ require 'deviantart/data/tos'
6
+
7
+ module DeviantArt
8
+ class Client
9
+ module Data
10
+ # Get a list of countries
11
+ def get_countries
12
+ perform(DeviantArt::Data::Countries, :get, '/api/v1/oauth2/data/countries')
13
+ end
14
+
15
+ # Returns the DeviantArt Privacy Policy
16
+ def get_privacy
17
+ perform(DeviantArt::Data::Privacy, :get, '/api/v1/oauth2/data/privacy')
18
+ end
19
+
20
+ # Returns the DeviantArt Submission Policy
21
+ def get_submission
22
+ perform(DeviantArt::Data::Submission, :get, '/api/v1/oauth2/data/submission')
23
+ end
24
+
25
+ # Returns the DeviantArt Terms of Service
26
+ def get_tos
27
+ perform(DeviantArt::Data::TOS, :get, '/api/v1/oauth2/data/tos')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'deviantart/deviation'
2
+ require 'deviantart/deviation/content'
3
+ require 'deviantart/deviation/whofaved'
4
+ require 'deviantart/deviation/download'
5
+
6
+ module DeviantArt
7
+ class Client
8
+ module Deviation
9
+ # Fetch a deviation details
10
+ def get_deviation(deviationid)
11
+ perform(DeviantArt::Deviation, :get, "/api/v1/oauth2/deviation/#{deviationid}")
12
+ end
13
+
14
+ # Fetch full data that is not included in the main devaition details
15
+ def get_deviation_content(deviationid)
16
+ perform(DeviantArt::Deviation::Content, :get, '/api/v1/oauth2/deviation/content', { deviationid: deviationid })
17
+ end
18
+
19
+ # Fetch a list of users who faved the deviation
20
+ def get_deviation_whofaved(deviationid, offset: 0, limit: 10)
21
+ params = {}
22
+ params['deviationid'] = deviationid
23
+ params['offset'] = offset if offset != 0
24
+ params['limit'] = limit if limit != 10
25
+ perform(DeviantArt::Deviation::WhoFaved, :get, '/api/v1/oauth2/deviation/whofaved', params)
26
+ end
27
+
28
+ # Get the original file download (if allowed)
29
+ def download_deviation(deviationid)
30
+ perform(DeviantArt::Deviation::Download, :get, "/api/v1/oauth2/deviation/download/#{deviationid}")
31
+ end
32
+
33
+ # TODO: embeddedcontent, metadata
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ require 'deviantart/feed'
2
+ require 'deviantart/feed/home'
3
+
4
+ module DeviantArt
5
+ class Client
6
+ module Feed
7
+ # Fetch Watch Feed
8
+ def get_feed(mature_content: false, cursor: nil)
9
+ params = {}
10
+ params['cursor'] = cursor unless cursor.nil?
11
+ params['mature_content'] = mature_content
12
+ perform(DeviantArt::Feed::Home, :get, '/api/v1/oauth2/feed/home', params)
13
+ end
14
+
15
+ # TODO: home/{bucketid}, notifications, profile, settings, settings/update
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,46 @@
1
+ require 'deviantart/gallery'
2
+ require 'deviantart/gallery/all'
3
+ require 'deviantart/gallery/folders'
4
+
5
+ module DeviantArt
6
+ class Client
7
+ module Gallery
8
+ # Get the "all" view of a users gallery
9
+ def get_gallery_all(username: nil, offset: 0, limit: 10)
10
+ params = {}
11
+ params['username'] = username unless username.nil?
12
+ params['offset'] = offset if offset != 0
13
+ params['limit'] = limit if limit != 10
14
+ perform(DeviantArt::Gallery::All, :get, '/api/v1/oauth2/gallery/all', params)
15
+ end
16
+
17
+ # Fetch gallery folders
18
+ def get_gallery_folders(username: nil, calculate_size: false, ext_preload: false, offset: 0, limit: 10)
19
+ params = {}
20
+ params['username'] = username unless username.nil?
21
+ params['calculate_size'] = calculate_size if calculate_size
22
+ params['ext_preload'] = ext_preload if ext_preload
23
+ params['offset'] = offset if offset != 0
24
+ params['limit'] = limit if limit != 10
25
+ perform(DeviantArt::Gallery::Folders, :get, '/api/v1/oauth2/gallery/folders', params)
26
+ end
27
+
28
+ # Fetch gallery folder contents
29
+ def get_gallery(username: nil, folderid: nil, mode: nil, offset: 0, limit: 10)
30
+ params = {}
31
+ params['username'] = username unless username.nil?
32
+ params['mode'] = mode unless mode.nil?
33
+ params['offset'] = offset if offset != 0
34
+ params['limit'] = limit if limit != 10
35
+ unless folderid.nil?
36
+ path = "/api/v1/oauth2/gallery/#{folderid}"
37
+ else
38
+ path = '/api/v1/oauth2/gallery/'
39
+ end
40
+ perform(DeviantArt::Gallery, :get, path, params)
41
+ end
42
+
43
+ # TODO: create, remove/{folderid}
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,75 @@
1
+ require 'deviantart/user'
2
+ require 'deviantart/user/profile'
3
+ require 'deviantart/user/friends'
4
+ require 'deviantart/user/friends/search'
5
+ require 'deviantart/user/whois'
6
+ require 'deviantart/user/statuses'
7
+ require 'deviantart/user/watchers'
8
+
9
+ module DeviantArt
10
+ class Client
11
+ module User
12
+ # Get user profile information
13
+ def get_profile(username, ext_collections: false, ext_galleries: false)
14
+ params = {}
15
+ params['ext_collections'] = ext_collections if ext_collections
16
+ params['ext_galleries'] = ext_galleries if ext_galleries
17
+ perform(DeviantArt::User::Profile, :get, "/api/v1/oauth2/user/profile/#{username.nil? ? '' : username}", params)
18
+ end
19
+
20
+ # Get the users list of friends
21
+ def get_friends(username, offset: 0, limit: 10)
22
+ params = {}
23
+ params['offset'] = offset if offset != 0
24
+ params['limit'] = limit if limit != 10
25
+ perform(DeviantArt::User::Friends, :get, "/api/v1/oauth2/user/friends/#{username.nil? ? '' : username}", params)
26
+ end
27
+
28
+ # Fetch user info for given usernames
29
+ def whois(users)
30
+ params = { usernames: users.is_a?(Enumerable) ? users : [users] }
31
+ perform(DeviantArt::User::Whois, :post, '/api/v1/oauth2/user/whois', params)
32
+ end
33
+
34
+ # Fetch user info of authenticated user
35
+ def whoami
36
+ perform(DeviantArt::User, :get, '/api/v1/oauth2/user/whoami?')
37
+ end
38
+
39
+ # Search friends by username
40
+ def search_friends(query, username: nil)
41
+ params = {}
42
+ params['query'] = query
43
+ params['username'] = username unless username.nil?
44
+ perform(DeviantArt::User::Friends::Search, :get, '/api/v1/oauth2/user/friends/search', params)
45
+ end
46
+
47
+ # User Statuses
48
+ def get_statuses(username, offset: 0, limit: 10, mature_content: true)
49
+ params = {}
50
+ params['username'] = username
51
+ params['mature_content'] = mature_content
52
+ params['offset'] = offset if offset != 0
53
+ params['limit'] = limit if limit != 10
54
+ perform(DeviantArt::User::Statuses, :get, '/api/v1/oauth2/user/statuses/', params)
55
+ end
56
+
57
+ # Fetch the status
58
+ def get_status(statusid, mature_content: true)
59
+ params = {}
60
+ params['mature_content'] = mature_content
61
+ perform(DeviantArt::Status, :get, "/api/v1/oauth2/user/statuses/#{statusid}", params)
62
+ end
63
+
64
+ # Get the user's list of watchers
65
+ def get_watchers(username: nil, offset: 0, limit: 10)
66
+ params = {}
67
+ params['offset'] = offset if offset != 0
68
+ params['limit'] = limit if limit != 10
69
+ perform(DeviantArt::User::Watchers, :get, "/api/v1/oauth2/user/watchers/#{username.nil? ? '' : username}", params)
70
+ end
71
+
72
+ # TODO: damntoken, friends/unwatch/{username}, friends/watch/{username}, friends/watching/{username}, profile/update, statuses/post
73
+ end
74
+ end
75
+ end
@@ -1,26 +1,8 @@
1
- module DeviantArt
2
- module Collections
3
- # Fetch collection folders
4
- def get_collections_folders(username: nil, calculate_size: false, ext_preload: false, offset: 0, limit: 10)
5
- params = {}
6
- params['username'] = username unless username.nil?
7
- params['calculate_size'] = calculate_size if calculate_size
8
- params['ext_preload'] = ext_preload if ext_preload
9
- params['offset'] = offset if offset != 0
10
- params['limit'] = limit if limit != 10
11
- perform(:get, '/api/v1/oauth2/collections/folders', params)
12
- end
13
-
14
- # Fetch collection folder contents
15
- def get_collections(folderid, username: nil, offset: 0, limit: 10)
16
- params = {}
17
- params['username'] = username unless username.nil?
18
- params['offset'] = offset if offset != 0
19
- params['limit'] = limit if limit != 10
20
- perform(:get, "/api/v1/oauth2/collections/#{folderid}", params)
21
- end
1
+ require 'deviantart/base'
22
2
 
23
- # TODO: fave, folders/create, folders/remove/{folderid}, unfav
3
+ module DeviantArt
4
+ class Collections < Base
5
+ attr_accessor :has_more, :next_offset, :name, :results
6
+ point_to_class [:results, :[]], DeviantArt::Deviation
24
7
  end
25
8
  end
26
-
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Collections::Folders < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[], :deviations, :[]], DeviantArt::Deviation
7
+ end
8
+ end
@@ -1,24 +1,6 @@
1
- module DeviantArt
2
- module Data
3
- # Get a list of countries
4
- def get_countries
5
- perform(:get, '/api/v1/oauth2/data/countries')
6
- end
7
-
8
- # Returns the DeviantArt Privacy Policy
9
- def get_privacy
10
- perform(:get, '/api/v1/oauth2/data/privacy')
11
- end
12
-
13
- # Returns the DeviantArt Submission Policy
14
- def get_submission
15
- perform(:get, '/api/v1/oauth2/data/submission')
16
- end
1
+ require 'deviantart/base'
17
2
 
18
- # Returns the DeviantArt Terms of Service
19
- def get_tos
20
- perform(:get, '/api/v1/oauth2/data/tos')
21
- end
3
+ module DeviantArt
4
+ class Data < Base
22
5
  end
23
6
  end
24
-
@@ -0,0 +1,7 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Data::Countries < Base
5
+ attr_accessor :results
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Data::Privacy < Base
5
+ attr_accessor :text
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Data::Submission < Base
5
+ attr_accessor :text
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Data::TOS < Base
5
+ attr_accessor :text
6
+ end
7
+ end
@@ -1,30 +1,12 @@
1
- module DeviantArt
2
- module Deviation
3
- # Fetch a deviation details
4
- def get_deviation(deviationid)
5
- perform(:get, "/api/v1/oauth2/deviation/#{deviationid}")
6
- end
7
-
8
- # Fetch full data that is not included in the main devaition details
9
- def get_deviation_content(deviationid)
10
- perform(:get, '/api/v1/oauth2/deviation/content', { deviationid: deviationid })
11
- end
12
-
13
- # Fetch a list of users who faved the deviation
14
- def get_deviation_whofaved(deviationid, offset: 0, limit: 10)
15
- params = {}
16
- params['deviationid'] = deviationid
17
- params['offset'] = offset if offset != 0
18
- params['limit'] = limit if limit != 10
19
- perform(:get, '/api/v1/oauth2/deviation/whofaved', params)
20
- end
1
+ require 'deviantart/base'
21
2
 
22
- # Get the original file download (if allowed)
23
- def download_deviation(deviationid)
24
- perform(:get, "/api/v1/oauth2/deviation/download/#{deviationid}")
25
- end
26
-
27
- # TODO: embeddedcontent, metadata
3
+ module DeviantArt
4
+ class Deviation < Base
5
+ attr_accessor :deviationid, :printid, :url, :title, :category, :category_path, :is_favourited, :is_deleted, :author, :stats
6
+ attr_accessor :published_time, :allows_comments, :preview, :content, :thumbs, :videos, :flash, :daily_deviation
7
+ attr_accessor :excerpt, :is_mature, :is_downloadable, :download_filesize, :challenge, :challenge_entry, :motion_book
8
+ point_to_class [:author], DeviantArt::User
9
+ point_to_class [:daily_deviation, :giver], DeviantArt::User
10
+ point_to_class [:daily_deviation, :suggester], DeviantArt::User
28
11
  end
29
12
  end
30
-
@@ -0,0 +1,6 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Deviation::Content < Base
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Deviation::Download < Base
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Deviation::WhoFaved < Base
5
+ point_to_class [:results, :[], :user], DeviantArt::User
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Error < Base
5
+ attr_accessor :error, :error_description, :error_details, :error_code, :status_code
6
+
7
+ def initialize(json, status_code)
8
+ super(json)
9
+ @status_code = status_code
10
+ end
11
+ end
12
+ end
@@ -1,14 +1,6 @@
1
- module DeviantArt
2
- module Feed
3
- # Fetch Watch Feed
4
- def get_feed(mature_content: false, cursor: nil)
5
- params = {}
6
- params['cursor'] = cursor unless cursor.nil?
7
- params['mature_content'] = mature_content
8
- perform(:get, '/api/v1/oauth2/feed/home', params)
9
- end
1
+ require 'deviantart/base'
10
2
 
11
- # TODO: home/{bucketid}, notifications, profile, settings, settings/update
3
+ module DeviantArt
4
+ class Feed < Base
12
5
  end
13
6
  end
14
-
@@ -0,0 +1,14 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Feed::Home < Base
5
+ attr_accessor :cursor, :has_more, :items
6
+ point_to_class [:items, :[], :by_user], DeviantArt::User
7
+ point_to_class [:items, :[], :deviations, :[]], DeviantArt::Deviation
8
+ point_to_class [:items, :[], :status], DeviantArt::Status
9
+ #point_to_class [:items, :[], :comment], DeviantArt::Comment
10
+ #point_to_class [:items, :[], :comment_parent], DeviantArt::Comment
11
+ point_to_class [:items, :[], :comment_deviation], DeviantArt::Deviation
12
+ point_to_class [:items, :[], :comment_profile], DeviantArt::User
13
+ end
14
+ end
@@ -1,41 +1,8 @@
1
- module DeviantArt
2
- module Gallery
3
- # Get the "all" view of a users gallery
4
- def get_gallery_all(username: nil, offset: 0, limit: 10)
5
- params = {}
6
- params['username'] = username unless username.nil?
7
- params['offset'] = offset if offset != 0
8
- params['limit'] = limit if limit != 10
9
- perform(:get, '/api/v1/oauth2/gallery/all', params)
10
- end
11
-
12
- # Fetch gallery folders
13
- def get_gallery_folders(username: nil, calculate_size: false, ext_preload: false, offset: 0, limit: 10)
14
- params = {}
15
- params['username'] = username unless username.nil?
16
- params['calculate_size'] = calculate_size if calculate_size
17
- params['ext_preload'] = ext_preload if ext_preload
18
- params['offset'] = offset if offset != 0
19
- params['limit'] = limit if limit != 10
20
- perform(:get, '/api/v1/oauth2/gallery/folders', params)
21
- end
22
-
23
- # Fetch gallery folder contents
24
- def get_gallery(username: nil, folderid: nil, mode: nil, offset: 0, limit: 10)
25
- params = {}
26
- params['username'] = username unless username.nil?
27
- params['mode'] = mode unless mode.nil?
28
- params['offset'] = offset if offset != 0
29
- params['limit'] = limit if limit != 10
30
- unless folderid.nil?
31
- path = "/api/v1/oauth2/gallery/#{folderid}"
32
- else
33
- path = '/api/v1/oauth2/gallery/'
34
- end
35
- perform(:get, path, params)
36
- end
1
+ require 'deviantart/base'
37
2
 
38
- # TODO: create, remove/{folderid}
3
+ module DeviantArt
4
+ class Gallery < Base
5
+ attr_accessor :has_more, :next_offset, :name, :results
6
+ point_to_class [:results, :[]], DeviantArt::Deviation
39
7
  end
40
8
  end
41
-
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Gallery::All < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[]], DeviantArt::Deviation
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Gallery::Folders < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[], :deviations, :[]], DeviantArt::Deviation
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class Status < Base
5
+ attr_accessor :statusid, :body, :ts, :url, :comments_count, :is_share, :is_deleted, :author, :items
6
+ point_to_class [:author], DeviantArt::User
7
+ point_to_class [:items, :[], :status], DeviantArt::Status
8
+ point_to_class [:items, :[], :deviation], DeviantArt::Deviation
9
+ end
10
+ end
@@ -1,56 +1,8 @@
1
- module DeviantArt
2
- module User
3
- # Get user profile information
4
- def get_profile(username, ext_collections: false, ext_galleries: false)
5
- params = {}
6
- params['ext_collections'] = ext_collections if ext_collections
7
- params['ext_galleries'] = ext_galleries if ext_galleries
8
- perform(:get, "/api/v1/oauth2/user/profile/#{username.nil? ? '' : username}", params)
9
- end
10
-
11
- # Get the users list of friends
12
- def get_friends(username, offset: 0, limit: 10)
13
- params = {}
14
- params['offset'] = offset if offset != 0
15
- params['limit'] = limit if limit != 10
16
- perform(:get, "/api/v1/oauth2/user/friends/#{username.nil? ? '' : username}", params)
17
- end
18
-
19
- # Fetch user info for given usernames
20
- def whois(users)
21
- params = { usernames: users.is_a?(Enumerable) ? users : [users] }
22
- perform(:post, '/api/v1/oauth2/user/whois', params)
23
- end
24
-
25
- # Fetch user info of authenticated user
26
- def whoami
27
- perform(:get, '/api/v1/oauth2/user/whoami?')
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
1
+ require 'deviantart/base'
37
2
 
38
- def get_statuses(username, offset: 0, limit: 10, mature_content: true)
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
- def get_status(statusid, mature_content: true)
48
- params = {}
49
- params['mature_content'] = mature_content
50
- perform(:get, "/api/v1/oauth2/user/statuses/#{statusid}", params)
51
- end
52
-
53
- # TODO: damntoken, friends/unwatch/{username}, friends/watch/{username}, friends/watching/{username}, profile/update, statuses/post, watchers/{username}
3
+ module DeviantArt
4
+ class User < Base
5
+ attr_accessor :userid, :username, :usericon, :type, :is_watching, :details, :geo, :profile, :stats
6
+ point_to_class [:profile, :profile_pic], DeviantArt::Deviation
54
7
  end
55
8
  end
56
-
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Friends < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[], :user], DeviantArt::User
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Friends::Search < Base
5
+ attr_accessor :results
6
+ point_to_class [:results, :[]], DeviantArt::User
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Profile < Base
5
+ attr_accessor :user, :is_watching, :profile_url, :user_is_artist, :artist_level, :artist_specialty, :real_name, :tagline
6
+ attr_accessor :countryid, :country, :website, :bio, :cover_photo, :profile_pic, :last_status, :stats, :collections, :galleries
7
+ point_to_class [:user], DeviantArt::User
8
+ point_to_class [:profile_pic], DeviantArt::Deviation
9
+ point_to_class [:last_status], DeviantArt::Status
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Statuses < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[]], DeviantArt::Status
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Watchers < Base
5
+ attr_accessor :has_more, :next_offset, :results
6
+ point_to_class [:results, :[], :user], DeviantArt::User
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'deviantart/base'
2
+
3
+ module DeviantArt
4
+ class User::Whois < Base
5
+ attr_accessor :results
6
+ point_to_class [:results, :[]], DeviantArt::User
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module DeviantArt
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
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.2
4
+ version: 0.3.0
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-22 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,13 +69,39 @@ files:
69
69
  - bin/setup
70
70
  - deviantart.gemspec
71
71
  - lib/deviantart.rb
72
+ - lib/deviantart/base.rb
72
73
  - lib/deviantart/client.rb
74
+ - lib/deviantart/client/collections.rb
75
+ - lib/deviantart/client/data.rb
76
+ - lib/deviantart/client/deviation.rb
77
+ - lib/deviantart/client/feed.rb
78
+ - lib/deviantart/client/gallery.rb
79
+ - lib/deviantart/client/user.rb
73
80
  - lib/deviantart/collections.rb
81
+ - lib/deviantart/collections/folders.rb
74
82
  - lib/deviantart/data.rb
83
+ - lib/deviantart/data/countries.rb
84
+ - lib/deviantart/data/privacy.rb
85
+ - lib/deviantart/data/submission.rb
86
+ - lib/deviantart/data/tos.rb
75
87
  - lib/deviantart/deviation.rb
88
+ - lib/deviantart/deviation/content.rb
89
+ - lib/deviantart/deviation/download.rb
90
+ - lib/deviantart/deviation/whofaved.rb
91
+ - lib/deviantart/error.rb
76
92
  - lib/deviantart/feed.rb
93
+ - lib/deviantart/feed/home.rb
77
94
  - lib/deviantart/gallery.rb
95
+ - lib/deviantart/gallery/all.rb
96
+ - lib/deviantart/gallery/folders.rb
97
+ - lib/deviantart/status.rb
78
98
  - lib/deviantart/user.rb
99
+ - lib/deviantart/user/friends.rb
100
+ - lib/deviantart/user/friends/search.rb
101
+ - lib/deviantart/user/profile.rb
102
+ - lib/deviantart/user/statuses.rb
103
+ - lib/deviantart/user/watchers.rb
104
+ - lib/deviantart/user/whois.rb
79
105
  - lib/deviantart/version.rb
80
106
  homepage: https://github.com/aycabta/deviantart
81
107
  licenses:
@@ -97,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
123
  version: '0'
98
124
  requirements: []
99
125
  rubyforge_project:
100
- rubygems_version: 2.6.6
126
+ rubygems_version: 2.5.2
101
127
  signing_key:
102
128
  specification_version: 4
103
129
  summary: deviantART API library