dribbble 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,190 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RAW_USER = data_from_json 'user_success.json'
4
6
 
5
7
  describe Dribbble::User do
6
8
  describe 'on instance' do
7
- before :all do
8
- @user = Dribbble::User.new 'valid_token', RAW_USER
9
+ before do
10
+ @user = described_class.new 'valid_token', RAW_USER
9
11
  end
10
12
 
11
13
  describe 'after initialization' do
12
14
  RAW_USER.each do |field, value|
13
15
  it "respond to #{field}" do
14
- expect(@user.send field).to eq(value)
15
- end
16
- end
17
- end
18
-
19
- describe 'on #buckets' do
20
- subject do
21
- stub_dribbble :get, '/users/483195/buckets', DribbbleAPI::BucketsSuccess
22
- @user.buckets
23
- end
24
-
25
- it 'responds with buckets' do
26
- expect(subject.size).to eq 1
27
- expect(subject.first).to be_a Dribbble::Bucket
28
- end
29
- end
30
-
31
- describe '#followers' do
32
- subject do
33
- stub_dribbble :get, '/users/483195/followers', DribbbleAPI::FollowersSuccess
34
- @user.followers
35
- end
36
-
37
- it 'responds with users' do
38
- expect(subject.size).to eq 1
39
- expect(subject.first).to be_a Dribbble::User
40
- end
41
- end
42
-
43
- describe '#following' do
44
- subject do
45
- stub_dribbble :get, '/users/483195/following', DribbbleAPI::FollowingSuccess
46
- @user.following
47
- end
48
-
49
- it 'responds with users' do
50
- expect(subject.size).to eq 1
51
- expect(subject.first).to be_a Dribbble::User
52
- expect(subject.first.name).to eq('Dan Cederholm')
53
- end
54
- end
55
-
56
- describe 'on #following?' do
57
- describe 'for current logged user' do
58
- describe 'on a not followed user' do
59
- subject do
60
- stub_dribbble :get, '/user/following/483195', DribbbleAPI::UserFollowNotFound
61
- @user.following?
62
- end
63
-
64
- it 'return false' do
65
- expect(subject).to be_falsy
66
- end
16
+ expect(@user.send(field)).to eq(value)
67
17
  end
68
-
69
- describe 'on a followed user' do
70
- subject do
71
- stub_dribbble :get, '/user/following/483195', DribbbleAPI::UserFollowSuccess
72
- @user.following?
73
- end
74
-
75
- it 'return true' do
76
- expect(subject).to be_truthy
77
- end
78
- end
79
- end
80
-
81
- describe 'for another user' do
82
- describe 'on a not followed user' do
83
- subject do
84
- stub_dribbble :get, '/users/483195/following/1', DribbbleAPI::UserFollowNotFound
85
- @user.following? 1
86
- end
87
-
88
- it 'return false' do
89
- expect(subject).to be_falsy
90
- end
91
- end
92
-
93
- describe 'on a followed user' do
94
- subject do
95
- stub_dribbble :get, '/users/483195/following/1', DribbbleAPI::UserFollowSuccess
96
- @user.following? 1
97
- end
98
-
99
- it 'return true' do
100
- expect(subject).to be_truthy
101
- end
102
- end
103
- end
104
- end
105
-
106
- describe 'on #follow!' do
107
- subject do
108
- stub_dribbble :put, '/users/483195/follow', DribbbleAPI::UserFollowCreated
109
- @user.follow!
110
- end
111
-
112
- it 'return true' do
113
- expect(subject).to be_truthy
114
- end
115
- end
116
-
117
- describe 'on #unfollow!' do
118
- subject do
119
- stub_dribbble :delete, '/users/483195/follow', DribbbleAPI::UserFollowDeleted
120
- @user.unfollow!
121
- end
122
-
123
- it 'return true' do
124
- expect(subject).to be_truthy
125
- end
126
- end
127
-
128
- describe '#likes' do
129
- subject do
130
- stub_dribbble :get, '/users/483195/likes', DribbbleAPI::UserLikesSuccess
131
- @user.likes
132
- end
133
-
134
- it 'responds with shots' do
135
- expect(subject.size).to eq 1
136
- expect(subject.first).to be_a Dribbble::Shot
137
- expect(subject.first.title).to eq('Sasquatch')
138
- end
139
- end
140
-
141
- describe '#projects' do
142
- subject do
143
- stub_dribbble :get, '/users/483195/projects', DribbbleAPI::ProjectsSuccess
144
- @user.projects
145
- end
146
-
147
- it 'responds with projects' do
148
- expect(subject.size).to eq 1
149
- expect(subject.first).to be_a Dribbble::Project
150
- end
151
- end
152
-
153
- describe '#shots' do
154
- subject do
155
- stub_dribbble :get, '/users/483195/shots', DribbbleAPI::ShotsSuccess
156
- @user.shots
157
- end
158
-
159
- it 'responds with buckets' do
160
- expect(subject.size).to eq 2
161
- expect(subject.first).to be_a Dribbble::Shot
162
- end
163
- end
164
-
165
- describe '#teams' do
166
- subject do
167
- stub_dribbble :get, '/users/483195/teams', DribbbleAPI::TeamsSuccess
168
- @user.teams
169
- end
170
-
171
- it 'responds with teams' do
172
- expect(subject.size).to eq 1
173
- expect(subject.first).to be_a Dribbble::Team
174
- end
175
- end
176
- end
177
-
178
- describe 'on class' do
179
- describe 'on #find' do
180
- subject do
181
- stub_dribbble :get, '/users/483195', DribbbleAPI::UserSuccess
182
- Dribbble::User.find 'valid_token', 483_195
183
- end
184
-
185
- it 'return a user' do
186
- expect(subject).to be_a Dribbble::User
187
- expect(subject.id).to eq(483_195)
188
18
  end
189
19
  end
190
20
  end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dribbble'
2
4
  require 'webmock/rspec'
3
5
 
4
- Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
5
7
 
6
8
  # WebMock.disable_net_connect! allow_localhost: true, allow: 'codeclimate.com'
7
9
 
8
10
  RSpec.configure do |config|
9
- config.before :all do
11
+ config.before do
10
12
  WebMock.reset!
11
13
  end
12
14
  end
13
15
 
14
16
  def stub_dribbble(method, path, response_class)
15
- url = /api.dribbble.com\/v1#{Regexp.escape path}(\?.*)?$/
17
+ url = %r{api.dribbble.com/v2#{Regexp.escape path}(\?.*)?$}
16
18
  stub_request(method, url).to_rack(response_class)
17
19
  end
18
20
 
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
 
3
5
  class String
4
6
  def underscore
5
- self.gsub(/::/, '/').
6
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
7
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
8
- tr("-", "_").
9
- downcase
7
+ gsub(/::/, '/')
8
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
9
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
10
+ .tr('-', '_')
11
+ .downcase
10
12
  end
11
13
  end
12
14
 
@@ -105,9 +107,9 @@ module DribbbleAPI
105
107
  headers response_headers
106
108
 
107
109
  {
108
- message: "Validation failed.",
110
+ message: 'Validation failed.',
109
111
  errors: [
110
- { attribute: "user", message: "reached the daily limit of 5 shots" }
112
+ { attribute: 'user', message: 'reached the daily limit of 5 shots' }
111
113
  ]
112
114
  }.to_json
113
115
  end
@@ -122,80 +124,25 @@ module DribbbleAPI
122
124
  class AttachmentDeleted < Deleted
123
125
  end
124
126
 
125
- class CommentsSuccess < Found
126
- end
127
-
128
- class CommentSuccess < Found
129
- end
130
-
131
- class CommentCreated < Created
132
- end
133
-
134
- class CommentUpdated < Updated
135
- end
136
-
137
- class CommentDeleted < Deleted
138
- end
139
-
140
- class CommentLikesSuccess < Found
141
- end
142
-
143
- class CommentLikeSuccess < Found
144
- end
145
-
146
- class CommentLikeNotFound < NotFound
147
- end
148
-
149
- class CommentLikeCreated < Created
150
- end
151
-
152
- class CommentLikeDeleted < Deleted
153
- end
154
-
155
127
  class CurrentUserSuccess < Found
156
128
  end
157
129
 
158
- class BucketSuccess < Found
159
- end
160
-
161
- class BucketCreated < Created
162
- end
163
-
164
- class BucketUpdated < Updated
165
- end
166
-
167
- class BucketDeleted < Deleted
168
- end
169
-
170
- class BucketsSuccess < Found
171
- end
172
-
173
- class FollowersSuccess < Found
174
- end
175
-
176
- class FollowingSuccess < Found
177
- end
178
-
179
- class UserFollowSuccess < Found
130
+ class ProjectSuccess < Found
180
131
  end
181
132
 
182
- class UserFollowNotFound < NotFound
133
+ # TODO: pending
134
+ class ProjectsSuccess < Found
183
135
  end
184
136
 
185
- class UserFollowCreated < NoContent
137
+ class ProjectsAccepted < Found
186
138
  end
187
139
 
188
- class UserFollowDeleted < Deleted
140
+ class ProjectsDeleted < Found
189
141
  end
190
142
 
191
- class UserLikesSuccess < Found
192
- end
193
-
194
- class ProjectSuccess < Found
195
- end
196
-
197
- class ProjectsSuccess < Found
143
+ class ProjectsUpdated < Found
198
144
  end
145
+ # END
199
146
 
200
147
  class ShotUpdated < Updated
201
148
  end
@@ -209,32 +156,14 @@ module DribbbleAPI
209
156
  class ShotAccepted < Accepted
210
157
  def response_headers
211
158
  {
212
- 'Location' => 'https://api.dribbble.com/v1/shots/471756'
159
+ 'Location' => 'https://api.dribbble.com/v2/shots/471756'
213
160
  }
214
161
  end
215
162
  end
216
163
 
217
- class ShotLikeSuccess < Found
218
- end
219
-
220
- class ShotLikeNotFound < NotFound
221
- end
222
-
223
- class ShotLikeCreated < Created
224
- end
225
-
226
- class ShotLikeDeleted < Deleted
227
- end
228
-
229
- class ShotLikesSuccess < Found
230
- end
231
-
232
164
  class ShotsSuccess < Found
233
165
  end
234
166
 
235
- class TeamsSuccess < Found
236
- end
237
-
238
167
  class UserSuccess < Found
239
168
  end
240
169
 
@@ -1,25 +1,36 @@
1
1
  {
2
- "id" : 8008135,
3
- "name" : "Charley D.",
4
- "username" : "Calyhre",
5
- "html_url" : "https://dribbble.com/Calyhre",
6
- "avatar_url" : "https://d13yacurqjgara.cloudfront.net/users/483195/avatars/normal/493064787.png?1390292526",
7
- "bio" : "",
8
- "location" : null,
9
- "links" : {},
10
- "followers_count" : 1,
11
- "followings_count" : 4,
12
- "likes_count" : 4,
13
- "shots_count" : 0,
14
- "type" : "Player",
15
- "pro" : false,
16
- "buckets_url" : "https://api.dribbble.com/v1/users/483195/buckets",
17
- "followers_url" : "https://api.dribbble.com/v1/users/483195/followers",
18
- "following_url" : "https://api.dribbble.com/v1/users/483195/following",
19
- "likes_url" : "https://api.dribbble.com/v1/users/483195/likes",
20
- "projects_url" : "https://api.dribbble.com/v1/users/483195/projects",
21
- "shots_url" : "https://api.dribbble.com/v1/users/483195/shots",
22
- "teams_url" : "https://api.dribbble.com/v1/users/483195/teams",
23
- "created_at" : "2014-01-21T08:22:06Z",
24
- "updated_at" : "2014-09-29T19:39:00Z"
25
- }
2
+ "id" : 1,
3
+ "name" : "Dan Cederholm",
4
+ "login" : "simplebits",
5
+ "html_url" : "https://dribbble.com/simplebits",
6
+ "avatar_url" : "https://d13yacurqjgara.cloudfront.net/users/1/avatars/normal/dc.jpg?1371679243",
7
+ "bio" : "Co-founder &amp; designer of <a href=\"https://dribbble.com/dribbble\">@Dribbble</a>. Principal of SimpleBits. Aspiring clawhammer banjoist.",
8
+ "location" : "Salem, MA",
9
+ "links" : {
10
+ "web" : "http://simplebits.com",
11
+ "twitter" : "https://twitter.com/simplebits"
12
+ },
13
+ "can_upload_shot" : true,
14
+ "pro" : true,
15
+ "followers_count" : 66557,
16
+ "created_at" : "2009-07-08T02:51:22Z",
17
+ "type" : "User",
18
+ "teams" : [
19
+ {
20
+ "id" : 39,
21
+ "name" : "Dribbble",
22
+ "login" : "dribbble",
23
+ "html_url" : "https://dribbble.com/dribbble",
24
+ "avatar_url" : "https://d13yacurqjgara.cloudfront.net/users/39/avatars/normal/apple-flat-precomposed.png?1388527574",
25
+ "bio" : "Show and tell for designers. This is Dribbble on Dribbble.",
26
+ "location" : "Salem, MA",
27
+ "links" : {
28
+ "web" : "http://dribbble.com",
29
+ "twitter" : "https://twitter.com/dribbble"
30
+ },
31
+ "type" : "Team",
32
+ "created_at" : "2009-08-18T18:34:31Z",
33
+ "updated_at" : "2014-02-14T22:32:11Z"
34
+ }
35
+ ]
36
+ }
@@ -5,4 +5,4 @@
5
5
  "shots_count" : 4,
6
6
  "created_at" : "2011-04-14T03:43:47Z",
7
7
  "updated_at" : "2012-04-04T22:39:53Z"
8
- }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "id" : 3,
3
+ "name" : "Project title",
4
+ "description" : "Project description",
5
+ "shots_count" : 4,
6
+ "created_at" : "2011-04-14T03:43:47Z",
7
+ "updated_at" : "2012-04-04T22:39:53Z"
8
+ }