dribbble 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +33 -0
  3. data/.travis.yml +3 -6
  4. data/CHANGELOG.md +58 -0
  5. data/Gemfile +10 -0
  6. data/Guardfile +4 -2
  7. data/README.md +44 -285
  8. data/Rakefile +2 -0
  9. data/dribbble.gemspec +10 -8
  10. data/lib/dribbble.rb +3 -1
  11. data/lib/dribbble/attachment.rb +9 -1
  12. data/lib/dribbble/base.rb +3 -1
  13. data/lib/dribbble/client.rb +5 -30
  14. data/lib/dribbble/errors.rb +3 -3
  15. data/lib/dribbble/project.rb +10 -2
  16. data/lib/dribbble/shot.rb +3 -33
  17. data/lib/dribbble/user.rb +1 -51
  18. data/lib/dribbble/utils.rb +5 -3
  19. data/lib/dribbble/utils/creatable.rb +3 -1
  20. data/lib/dribbble/utils/deletable.rb +3 -1
  21. data/lib/dribbble/utils/findable.rb +2 -0
  22. data/lib/dribbble/utils/has_children.rb +16 -12
  23. data/lib/dribbble/utils/updatable.rb +2 -0
  24. data/lib/dribbble/version.rb +3 -1
  25. data/spec/lib/dribbble/base_spec.rb +10 -8
  26. data/spec/lib/dribbble/client_spec.rb +16 -69
  27. data/spec/lib/dribbble/project_spec.rb +52 -16
  28. data/spec/lib/dribbble/shot_spec.rb +14 -197
  29. data/spec/lib/dribbble/user_spec.rb +5 -175
  30. data/spec/spec_helper.rb +5 -3
  31. data/spec/support/dribbble_api.rb +17 -88
  32. data/spec/support/fixtures/current_user_success.json +35 -24
  33. data/spec/support/fixtures/project_success.json +1 -1
  34. data/spec/support/fixtures/projects_accepted.json +8 -0
  35. data/spec/support/fixtures/projects_deleted.json +8 -0
  36. data/spec/support/fixtures/projects_success.json +1 -1
  37. data/spec/support/fixtures/projects_updated.json +8 -0
  38. data/spec/support/fixtures/shot_success.json +16 -16
  39. data/spec/support/fixtures/shot_updated.json +78 -78
  40. data/spec/support/fixtures/shots_success.json +81 -103
  41. data/spec/support/fixtures/user_success.json +35 -24
  42. metadata +33 -67
  43. data/lib/dribbble/bucket.rb +0 -33
  44. data/lib/dribbble/comment.rb +0 -29
  45. data/lib/dribbble/like.rb +0 -7
  46. data/lib/dribbble/team.rb +0 -6
  47. data/spec/lib/dribbble/bucket_spec.rb +0 -136
  48. data/spec/lib/dribbble/comment_spec.rb +0 -77
  49. data/spec/lib/dribbble/team_spec.rb +0 -43
  50. data/spec/support/fixtures/attachments_success.json +0 -11
  51. data/spec/support/fixtures/bucket_created.json +0 -8
  52. data/spec/support/fixtures/bucket_success.json +0 -8
  53. data/spec/support/fixtures/bucket_updated.json +0 -8
  54. data/spec/support/fixtures/buckets_success.json +0 -10
  55. data/spec/support/fixtures/comment_created.json +0 -38
  56. data/spec/support/fixtures/comment_likes_success.json +0 -40
  57. data/spec/support/fixtures/comment_success.json +0 -38
  58. data/spec/support/fixtures/comment_updated.json +0 -38
  59. data/spec/support/fixtures/comments_success.json +0 -37
  60. data/spec/support/fixtures/followers_success.json +0 -33
  61. data/spec/support/fixtures/following_success.json +0 -33
  62. data/spec/support/fixtures/shot_likes_success.json +0 -33
  63. data/spec/support/fixtures/team_success.json +0 -26
  64. data/spec/support/fixtures/teams_success.json +0 -28
  65. data/spec/support/fixtures/user_likes_success.json +0 -91
  66. data/spec/support/fixtures/users_success.json +0 -27
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/dribbble.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- require File.expand_path('../lib/dribbble/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/dribbble/version', __dir__)
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = 'dribbble'
@@ -14,12 +16,12 @@ Gem::Specification.new do |s|
14
16
  s.files = `git ls-files`.split("\n")
15
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
18
 
17
- s.required_ruby_version = '>= 2.0.0'
18
- s.add_runtime_dependency 'rest-client', '~> 1.7'
19
+ s.required_ruby_version = ['>= 2.5.0', '< 3.0']
20
+ s.add_runtime_dependency 'rest-client', '~> 2.0'
19
21
 
20
- s.add_development_dependency 'rake', '~> 10.3'
21
- s.add_development_dependency 'rspec', '~> 2.14'
22
- s.add_development_dependency 'guard-rspec', '~> 4.3'
23
- s.add_development_dependency 'sinatra', '~> 1.4'
24
- s.add_development_dependency 'webmock', '~> 1.17'
22
+ s.add_development_dependency 'guard-rspec', '~> 4.7'
23
+ s.add_development_dependency 'rake', '~> 12.3.3'
24
+ s.add_development_dependency 'rspec', '~> 3.10'
25
+ s.add_development_dependency 'sinatra', '~> 2.1'
26
+ s.add_development_dependency 'webmock', '~> 3.13'
25
27
  end
data/lib/dribbble.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
- API_URI = 'https://api.dribbble.com/v1'
4
+ API_URI = ENV.fetch('DRIBBBLE_API_URI', 'https://api.dribbble.com/v2')
3
5
  end
4
6
 
5
7
  require 'dribbble/client'
@@ -1,7 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dribbble/utils/creatable'
4
+ require 'dribbble/utils/deletable'
5
+
1
6
  module Dribbble
2
7
  class Attachment < Dribbble::Base
8
+ include Dribbble::Utils::Creatable
9
+ include Dribbble::Utils::Deletable
10
+
3
11
  def self.available_fields
4
- %i(file)
12
+ %i[file]
5
13
  end
6
14
  end
7
15
  end
data/lib/dribbble/base.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dribbble/utils'
2
4
  require 'dribbble/utils/has_children'
3
5
 
@@ -17,7 +19,7 @@ module Dribbble
17
19
  @dribbble_url = build_dribbble_url(@raw['id'].to_s, dribbble_url)
18
20
 
19
21
  @raw.each do |k, _v|
20
- define_singleton_method(k) { @raw[k] } unless self.respond_to?(k)
22
+ define_singleton_method(k) { @raw[k] } unless respond_to?(k)
21
23
  end
22
24
  end
23
25
 
@@ -1,9 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dribbble/base'
4
+ require 'dribbble/shot'
2
5
  require 'dribbble/user'
3
- require 'dribbble/bucket'
4
6
  require 'dribbble/project'
5
- require 'dribbble/shot'
6
- require 'dribbble/team'
7
7
  require 'dribbble/errors'
8
8
 
9
9
  require 'rest_client'
@@ -16,22 +16,8 @@ module Dribbble
16
16
  def initialize(token = nil)
17
17
  token = token.is_a?(Hash) ? token[:token] : token
18
18
  @token = token
19
- fail Dribbble::Error::MissingToken if @token.nil?
20
- end
21
-
22
- # Get authenticated user's buckets
23
- def buckets(attrs = {})
24
- Dribbble::Bucket.batch_new token, html_get('/user/buckets', attrs)
25
- end
26
-
27
- # Get authenticated user's followers
28
- def followers(attrs = {})
29
- Dribbble::User.batch_new token, html_get('/user/followers', attrs)
30
- end
31
-
32
- # Get authenticated user's likes
33
- def likes(attrs = {})
34
- Dribbble::Shot.batch_new token, html_get('/user/likes', attrs), 'shot'
19
+ super(token, {})
20
+ raise Dribbble::Error::MissingToken if @token.nil?
35
21
  end
36
22
 
37
23
  # Get authenticated user's followers
@@ -44,17 +30,6 @@ module Dribbble
44
30
  Dribbble::Shot.batch_new token, html_get('/user/shots', attrs)
45
31
  end
46
32
 
47
- # Get authenticated user's followees shots
48
- # Limited to first 600 shots regardless of the pagination
49
- def following_shots(attrs = {})
50
- Dribbble::Shot.batch_new token, html_get('/user/following/shots', attrs)
51
- end
52
-
53
- # Get authenticated user's teams
54
- def teams(attrs = {})
55
- Dribbble::Team.batch_new token, html_get('/user/teams', attrs)
56
- end
57
-
58
33
  # Get a single User or the authenticated one
59
34
  def user
60
35
  Dribbble::User.new @token, html_get('/user')
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Error
3
- ISSUES_URL = 'https://github.com/Calyhre/dribbble/issues/new'
4
-
5
5
  # Standard error we will inherit
6
6
  class Standard < StandardError
7
7
  def initialize(message = nil)
8
- if message && message.response
8
+ if message&.response
9
9
  super message.response
10
10
  else
11
11
  super(message || self.message)
@@ -1,11 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dribbble/utils/findable'
4
+ require 'dribbble/utils/creatable'
5
+ require 'dribbble/utils/updatable'
6
+ require 'dribbble/utils/deletable'
2
7
 
3
8
  module Dribbble
4
9
  class Project < Dribbble::Base
5
10
  include Dribbble::Utils::Findable
11
+ include Dribbble::Utils::Creatable
12
+ include Dribbble::Utils::Updatable
13
+ include Dribbble::Utils::Deletable
6
14
 
7
- def shots(attrs = {})
8
- Dribbble::Shot.batch_new token, html_get("/projects/#{id}/shots", attrs)
15
+ def self.available_fields
16
+ %i[name description]
9
17
  end
10
18
  end
11
19
  end
data/lib/dribbble/shot.rb CHANGED
@@ -1,10 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dribbble/utils/findable'
2
4
  require 'dribbble/utils/creatable'
3
5
  require 'dribbble/utils/updatable'
4
6
  require 'dribbble/utils/deletable'
5
- require 'dribbble/attachment'
6
- require 'dribbble/comment'
7
- require 'dribbble/like'
8
7
 
9
8
  module Dribbble
10
9
  class Shot < Dribbble::Base
@@ -13,41 +12,12 @@ module Dribbble
13
12
  include Dribbble::Utils::Updatable
14
13
  include Dribbble::Utils::Deletable
15
14
 
16
- has_many :attachments, :buckets, :comments, :likes, :projects
17
- has_many :rebounds, as: Dribbble::Shot
18
-
19
- def self.all(token, attrs = {})
20
- @token = token
21
- batch_new token, html_get('/shots', attrs)
22
- end
23
-
24
15
  def self.available_fields
25
- %i(title image description tags team_id rebound_source_id)
16
+ %i[image title description low_profile rebound_source_id scheduled_for tags team_id]
26
17
  end
27
18
 
28
19
  def self.after_create(res)
29
20
  res.code == 202 ? res.headers[:location].split('/').last : false
30
21
  end
31
-
32
- def like?
33
- html_get "/shots/#{id}/like"
34
- true
35
- rescue RestClient::ResourceNotFound
36
- false
37
- end
38
-
39
- def like!
40
- res = html_post "/shots/#{id}/like"
41
- res.code == 201 ? true : false
42
- end
43
-
44
- def unlike!
45
- res = html_delete "/shots/#{id}/like"
46
- res.code == 204 ? true : false
47
- end
48
-
49
- def rebounds(attrs = {})
50
- Dribbble::Shot.batch_new token, html_get("/shots/#{id}/rebounds", attrs)
51
- end
52
22
  end
53
23
  end
data/lib/dribbble/user.rb CHANGED
@@ -1,56 +1,6 @@
1
- require 'dribbble/utils/findable'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dribbble
4
4
  class User < Dribbble::Base
5
- include Dribbble::Utils::Findable
6
-
7
- def buckets(attrs = {})
8
- Dribbble::Bucket.batch_new token, html_get("/users/#{id}/buckets", attrs)
9
- end
10
-
11
- def followers(attrs = {})
12
- Dribbble::User.batch_new token, html_get("/users/#{id}/followers", attrs)
13
- end
14
-
15
- def following(attrs = {})
16
- Dribbble::User.batch_new token, html_get("/users/#{id}/following", attrs), 'followee'
17
- end
18
-
19
- def following?(other_user_id = nil)
20
- if other_user_id
21
- html_get "/users/#{id}/following/#{other_user_id}"
22
- else
23
- html_get "/user/following/#{id}"
24
- end
25
- true
26
- rescue RestClient::ResourceNotFound
27
- false
28
- end
29
-
30
- def follow!
31
- res = html_put "/users/#{id}/follow"
32
- res.code == 204 ? true : false
33
- end
34
-
35
- def unfollow!
36
- res = html_delete "/users/#{id}/follow"
37
- res.code == 204 ? true : false
38
- end
39
-
40
- def likes(attrs = {})
41
- Dribbble::Shot.batch_new token, html_get("/users/#{id}/likes", attrs), 'shot'
42
- end
43
-
44
- def projects(attrs = {})
45
- Dribbble::Project.batch_new token, html_get("/users/#{id}/projects", attrs)
46
- end
47
-
48
- def shots(attrs = {})
49
- Dribbble::Shot.batch_new token, html_get("/users/#{id}/shots", attrs)
50
- end
51
-
52
- def teams(attrs = {})
53
- Dribbble::Team.batch_new token, html_get("/users/#{id}/teams", attrs)
54
- end
55
5
  end
56
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Dribbble
@@ -5,14 +7,14 @@ module Dribbble
5
7
  DEFAULT_ATTRIBUTES = {
6
8
  page: 1,
7
9
  per_page: 100
8
- }
10
+ }.freeze
9
11
 
10
12
  def class_name
11
- @_class_name ||= self.is_a?(Class) ? name.split('::').last.downcase : self.class.name.split('::').last.downcase
13
+ @class_name ||= is_a?(Class) ? name.split('::').last.downcase : self.class.name.split('::').last.downcase
12
14
  end
13
15
 
14
16
  def pluralized_class_name
15
- @_pluralized_class_name ||= "#{class_name}s"
17
+ @pluralized_class_name ||= "#{class_name}s"
16
18
  end
17
19
 
18
20
  def full_url(path, attrs = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Utils
3
5
  module Creatable
@@ -17,7 +19,7 @@ module Dribbble
17
19
 
18
20
  # Need to be redeclared in the model
19
21
  def available_fields
20
- fail "You need to redeclare this methods in your model"
22
+ raise 'You need to redeclare this methods in your model'
21
23
  end
22
24
 
23
25
  def after_create(res)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Utils
3
5
  module Deletable
4
6
  def delete
5
7
  res = html_delete "/#{self.class.api_endpoint}/#{id}"
6
- res.code == 204 ? true : false
8
+ res.code == 204 || res.code == 200
7
9
  end
8
10
 
9
11
  module ClassMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Utils
3
5
  module Findable
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Utils
3
5
  module HasChildren
4
6
  module ClassMethods
5
- def has_many(*fields)
7
+ def has_many(*fields) # rubocop:disable Naming/PredicateName
6
8
  if fields[1].is_a? Hash
7
- generate_methods fields[0], fields[1][:as]
9
+ generate_methods fields[0], fields[1][:as], fields[1][:key]
8
10
  else
9
11
  fields.each do |field|
10
12
  generate_methods field
@@ -12,27 +14,28 @@ module Dribbble
12
14
  end
13
15
  end
14
16
 
15
- def generate_methods(field, klass = nil)
17
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
18
+ def generate_methods(field, klass = nil, key = nil)
16
19
  singularized_field = field[0...-1]
17
20
 
18
21
  define_method field do |attrs = {}|
19
- klass ||= Object.const_get "Dribbble::#{__method__[0...-1].capitalize}"
22
+ klass ||= Object.const_get "Dribbble::#{singularized_field.capitalize}"
20
23
  url = "/#{pluralized_class_name}/#{id}/#{field}"
21
- klass.batch_new token, html_get(url, attrs), nil, url
24
+ klass.batch_new token, html_get(url, attrs), key, url
22
25
  end
23
26
 
24
27
  define_method "find_#{singularized_field}" do |child_id|
25
- klass ||= Object.const_get "Dribbble::#{__method__[0...-1].capitalize}"
28
+ klass ||= Object.const_get "Dribbble::#{singularized_field.capitalize}"
26
29
  url = "/#{pluralized_class_name}/#{id}/#{field}/#{child_id}"
27
30
  klass.new token, html_get(url), url
28
31
  end
29
32
 
30
33
  define_method "create_#{singularized_field}" do |attrs = {}|
31
- klass ||= Object.const_get "Dribbble::#{__method__[0...-1].capitalize}"
34
+ klass ||= Object.const_get "Dribbble::#{singularized_field.capitalize}"
32
35
  url = "/#{pluralized_class_name}/#{id}/#{field}"
33
36
  res = html_post url do |payload|
34
- klass.available_fields.each do |field|
35
- payload[field] = attrs[field]
37
+ klass.available_fields.each do |available_field|
38
+ payload[available_field] = attrs[available_field]
36
39
  end
37
40
  end
38
41
  case res.code
@@ -49,8 +52,8 @@ module Dribbble
49
52
  klass ||= Object.const_get "Dribbble::#{__method__[0...-1].capitalize}"
50
53
  url = "/#{pluralized_class_name}/#{id}/#{klass.pluralized_class_name}/#{child_id}"
51
54
  res = html_put url do |payload|
52
- klass.available_fields.each do |field|
53
- payload[field] = attrs[field]
55
+ klass.available_fields.each do |available_field|
56
+ payload[available_field] = attrs[available_field]
54
57
  end
55
58
  end
56
59
  klass.new token, res, url
@@ -59,10 +62,11 @@ module Dribbble
59
62
  define_method "delete_#{singularized_field}" do |child_id|
60
63
  klass ||= Object.const_get "Dribbble::#{__method__[0...-1].capitalize}"
61
64
  res = html_delete "/#{pluralized_class_name}/#{id}/#{klass.pluralized_class_name}/#{child_id}"
62
- res.code == 204 ? true : false
65
+ res.code == 204
63
66
  end
64
67
  end
65
68
  end
69
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
66
70
 
67
71
  def self.included(base)
68
72
  base.extend(ClassMethods)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dribbble
2
4
  module Utils
3
5
  module Updatable
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Dribbble Version
2
4
  module Dribbble
3
- VERSION = '1.0.1'
5
+ VERSION = '2.0.0'
4
6
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe Dribbble::Client do
4
- before :all do
5
- @base = Dribbble::Base.new 'valid_token', {}
5
+ describe Dribbble::Base do
6
+ before do
7
+ @base = described_class.new 'valid_token', {}
6
8
  end
7
9
 
8
10
  describe 'on #full_url_with_default_params' do
@@ -10,7 +12,7 @@ describe Dribbble::Client do
10
12
  subject { @base.full_url_with_default_params '/shots' }
11
13
 
12
14
  it 'return a valid url' do
13
- expect(subject).to eq('https://api.dribbble.com/v1/shots?page=1&per_page=100')
15
+ expect(subject).to eq('https://api.dribbble.com/v2/shots?page=1&per_page=100')
14
16
  end
15
17
  end
16
18
 
@@ -18,7 +20,7 @@ describe Dribbble::Client do
18
20
  subject { @base.full_url_with_default_params '/shots', page: 2, per_page: 10 }
19
21
 
20
22
  it 'return a valid url' do
21
- expect(subject).to eq('https://api.dribbble.com/v1/shots?page=2&per_page=10')
23
+ expect(subject).to eq('https://api.dribbble.com/v2/shots?page=2&per_page=10')
22
24
  end
23
25
  end
24
26
 
@@ -26,7 +28,7 @@ describe Dribbble::Client do
26
28
  subject { @base.full_url_with_default_params '/shots', params1: 'custom' }
27
29
 
28
30
  it 'return a valid url' do
29
- expect(subject).to eq('https://api.dribbble.com/v1/shots?page=1&per_page=100&params1=custom')
31
+ expect(subject).to eq('https://api.dribbble.com/v2/shots?page=1&per_page=100&params1=custom')
30
32
  end
31
33
  end
32
34
  end
@@ -36,7 +38,7 @@ describe Dribbble::Client do
36
38
  subject { @base.full_url '/shots' }
37
39
 
38
40
  it 'return a valid url' do
39
- expect(subject).to eq('https://api.dribbble.com/v1/shots?')
41
+ expect(subject).to eq('https://api.dribbble.com/v2/shots?')
40
42
  end
41
43
  end
42
44
 
@@ -44,7 +46,7 @@ describe Dribbble::Client do
44
46
  subject { @base.full_url '/shots', custom: 1 }
45
47
 
46
48
  it 'return a valid url' do
47
- expect(subject).to eq('https://api.dribbble.com/v1/shots?custom=1')
49
+ expect(subject).to eq('https://api.dribbble.com/v2/shots?custom=1')
48
50
  end
49
51
  end
50
52
  end