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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fdd663a915e28c0444e53eb3f732b93281a6524
4
- data.tar.gz: a93893796b12f74c8a39c0a1c74092313c85c115
3
+ metadata.gz: c8d5b6643a6f9af4d75fe988cb96492aea502fb2
4
+ data.tar.gz: ab439f5a0ac0c932663b906ac8a11335d57ea832
5
5
  SHA512:
6
- metadata.gz: 10e554efc6cee88812149878b94cd1de27e0f26d1fd278fe9202e5f24d42d604f99525a0cc63c17249527f854a86a748e05d2dbb18af5e0de3792aa47515bdd4
7
- data.tar.gz: 5f3bdb693bd1be7f1b0e0d48821067b5ee60a85ee2ae5ecfe3d77785c6fb4835f3d52a606812797820b8dcfadfd35d3c9315d23d088aa1ae91dcfaa51229a24b
6
+ metadata.gz: 2a28ea7daf05f8bfe250154e7c98de8d3481f08bf802bb71c020f81763c7e71f10d9dbfdf2b448a5bf0609cdf7815b16d5b0edb0e03088b553ae9b2efcfbfdd5
7
+ data.tar.gz: 6844ec96b4fa3c0378710077ebde6eba9167d5f6ddfa68b1eaa0ae4d5632c0f222ebaf06e74cf26abae88c6907b08ccd630d88b0456789eb64b507e8dc50fd7b
@@ -1,3 +1,4 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm: 2.3.1
4
+ script: REAL='' bundle exec rake test
data/Rakefile CHANGED
@@ -62,7 +62,7 @@ def get_access_token
62
62
  end
63
63
  end
64
64
 
65
- Rake::TestTask.new(:real) do |t|
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"
@@ -2,6 +2,7 @@ require "deviantart/version"
2
2
  require "deviantart/client"
3
3
 
4
4
  module DeviantArt
5
+ # Bypass args and block to DeviantArt::Client
5
6
  def self.new(*args, &block)
6
7
  DeviantArt::Client.new(*args, &block)
7
8
  end
@@ -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
- @@host = 'www.deviantart.com'
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(@@host, 443)
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
- def self.host
40
- @@host
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
- def on_refreshed_authorization_code(&block)
64
- @on_refreshed_authorization_code = block
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
- def on_refreshed_access_token(&block)
68
- @on_refreshed_access_token = block
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://#{@@host}#{path}")
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
- @on_refreshed_access_token.call(@access_token) if @on_refreshed_access_token
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
- @on_refreshed_access_token.call(@access_token) if @on_refreshed_access_token
128
- @on_refreshed_authorization_code.call(@access_token, response.json['refresh_token']) if @on_refreshed_authorization_code
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
@@ -19,6 +19,8 @@ module DeviantArt
19
19
  params['limit'] = limit if limit != 10
20
20
  perform(:get, "/api/v1/oauth2/collections/#{folderid}", params)
21
21
  end
22
+
23
+ # TODO: fave, folders/create, folders/remove/{folderid}, unfav
22
24
  end
23
25
  end
24
26
 
@@ -23,6 +23,8 @@ module DeviantArt
23
23
  def download_deviation(deviationid)
24
24
  perform(:get, "/api/v1/oauth2/deviation/download/#{deviationid}")
25
25
  end
26
+
27
+ # TODO: embeddedcontent, metadata
26
28
  end
27
29
  end
28
30
 
@@ -7,6 +7,8 @@ module DeviantArt
7
7
  params['mature_content'] = mature_content
8
8
  perform(:get, '/api/v1/oauth2/feed/home', params)
9
9
  end
10
+
11
+ # TODO: home/{bucketid}, notifications, profile, settings, settings/update
10
12
  end
11
13
  end
12
14
 
@@ -34,6 +34,8 @@ module DeviantArt
34
34
  end
35
35
  perform(:get, path, params)
36
36
  end
37
+
38
+ # TODO: create, remove/{folderid}
37
39
  end
38
40
  end
39
41
 
@@ -1,7 +1,7 @@
1
1
  module DeviantArt
2
2
  module User
3
3
  # Get user profile information
4
- def get_profile(username: nil, ext_collections: false, ext_galleries: false)
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: nil, offset: 0, limit: 10)
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
 
@@ -1,3 +1,3 @@
1
1
  module DeviantArt
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.0
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-14 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler