dribbble 1.2.0 → 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 -3
  4. data/CHANGELOG.md +40 -12
  5. data/Gemfile +10 -0
  6. data/Guardfile +4 -2
  7. data/README.md +38 -283
  8. data/Rakefile +2 -0
  9. data/dribbble.gemspec +9 -7
  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 +4 -29
  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 -28
  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 +10 -6
  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 -176
  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 +28 -66
  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,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Dribbble::Client do
4
- before :all do
5
- @client = Dribbble::Client.new 'valid_token'
6
+ before do
7
+ @client = described_class.new 'valid_token'
6
8
  end
7
9
 
8
10
  describe 'without token' do
9
11
  it 'raises Dribbble::Error::MissingToken' do
10
12
  expect do
11
- Dribbble::Client.new
13
+ described_class.new
12
14
  end.to raise_error(Dribbble::Error::MissingToken)
13
15
  end
14
16
  end
@@ -17,7 +19,7 @@ describe Dribbble::Client do
17
19
  describe 'with an invalid token' do
18
20
  subject do
19
21
  stub_dribbble :get, '/user', DribbbleAPI::Unauthorized
20
- Dribbble::Client.new(token: 'fake_invalid_token')
22
+ described_class.new(token: 'fake_invalid_token')
21
23
  end
22
24
 
23
25
  it 'raise Dribbble::Error::Unauthorized' do
@@ -30,7 +32,7 @@ describe Dribbble::Client do
30
32
  describe 'with a valid token' do
31
33
  subject do
32
34
  stub_dribbble :get, '/user', DribbbleAPI::UserSuccess
33
- Dribbble::Client.new(token: 'valid_token')
35
+ described_class.new(token: 'valid_token')
34
36
  end
35
37
 
36
38
  it 'return a Dribbble::User' do
@@ -38,38 +40,17 @@ describe Dribbble::Client do
38
40
  expect(subject.user.name).to be_a String
39
41
  end
40
42
  end
41
- end
42
-
43
- describe 'on #buckets' do
44
- subject do
45
- stub_dribbble :get, '/user/buckets', DribbbleAPI::BucketsSuccess
46
- @client.buckets
47
- end
48
-
49
- it 'return buckets' do
50
- expect(subject.first).to be_a Dribbble::Bucket
51
- end
52
- end
53
-
54
- describe 'on #followers' do
55
- subject do
56
- stub_dribbble :get, '/user/followers', DribbbleAPI::FollowersSuccess
57
- @client.followers
58
- end
59
43
 
60
- it 'return users' do
61
- expect(subject.first).to be_a Dribbble::User
62
- end
63
- end
64
-
65
- describe 'on #likes' do
66
- subject do
67
- stub_dribbble :get, '/user/likes', DribbbleAPI::UserLikesSuccess
68
- @client.likes
69
- end
44
+ describe 'with current user' do
45
+ subject do
46
+ stub_dribbble :get, '/user', DribbbleAPI::CurrentUserSuccess
47
+ @client.user
48
+ end
70
49
 
71
- it 'return shots' do
72
- expect(subject.first).to be_a Dribbble::Shot
50
+ it 'return current user' do
51
+ expect(subject).to be_a Dribbble::User
52
+ expect(subject.id).to eq(1)
53
+ end
73
54
  end
74
55
  end
75
56
 
@@ -94,38 +75,4 @@ describe Dribbble::Client do
94
75
  expect(subject.first).to be_a Dribbble::Shot
95
76
  end
96
77
  end
97
-
98
- describe 'on #following_shots' do
99
- subject do
100
- stub_dribbble :get, '/user/following/shots', DribbbleAPI::ShotsSuccess
101
- @client.following_shots
102
- end
103
-
104
- it 'return shots' do
105
- expect(subject.first).to be_a Dribbble::Shot
106
- end
107
- end
108
-
109
- describe 'on #teams' do
110
- subject do
111
- stub_dribbble :get, '/user/teams', DribbbleAPI::TeamsSuccess
112
- @client.teams
113
- end
114
-
115
- it 'return teams' do
116
- expect(subject.first).to be_a Dribbble::Team
117
- end
118
- end
119
-
120
- describe 'on #user' do
121
- subject do
122
- stub_dribbble :get, '/user', DribbbleAPI::CurrentUserSuccess
123
- @client.user
124
- end
125
-
126
- it 'return current user' do
127
- expect(subject).to be_a Dribbble::User
128
- expect(subject.id).to eq(8_008_135)
129
- end
130
- end
131
78
  end
@@ -1,44 +1,80 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RAW_PROJECT = data_from_json 'project_success.json'
4
6
 
5
7
  describe Dribbble::Project do
6
8
  describe 'on instance' do
7
- before :all do
8
- @project = Dribbble::Project.new 'valid_token', RAW_PROJECT
9
+ before do
10
+ @project = described_class.new 'valid_token', RAW_PROJECT
9
11
  end
10
12
 
11
13
  describe 'after initialization' do
12
14
  RAW_PROJECT.each do |field, value|
13
15
  it "respond to #{field}" do
14
- expect(@project.send field).to eq(value)
16
+ expect(@project.send(field)).to eq(value)
15
17
  end
16
18
  end
17
19
  end
20
+ end
18
21
 
19
- describe 'on #shots' do
22
+ describe 'on class' do
23
+ describe 'on #find' do
20
24
  subject do
21
- stub_dribbble :get, '/projects/3/shots', DribbbleAPI::ShotsSuccess
22
- @project.shots
25
+ stub_dribbble :get, '/projects/3', DribbbleAPI::ProjectSuccess
26
+ described_class.find 'valid_token', 3
23
27
  end
24
28
 
25
- it 'responds with shots' do
26
- expect(subject.size).to eq 2
27
- expect(subject.first).to be_a Dribbble::Shot
29
+ it 'return a shot' do
30
+ expect(subject).to be_a described_class
31
+ expect(subject.id).to eq(3)
28
32
  end
29
33
  end
30
- end
31
34
 
32
- describe 'on class' do
33
- describe 'on #find' do
35
+ describe 'on #create' do
34
36
  subject do
35
- stub_dribbble :get, '/projects/3', DribbbleAPI::ProjectSuccess
36
- Dribbble::Project.find 'valid_token', 3
37
+ stub_dribbble :post, '/projects', DribbbleAPI::ProjectsAccepted
38
+ data = {
39
+ name: 'Project title',
40
+ desciption: 'Project description'
41
+ }
42
+ described_class.create 'valid_token', data
37
43
  end
38
44
 
39
- it 'return a project' do
40
- expect(subject).to be_a Dribbble::Project
45
+ it 'create the project' do
46
+ expect(subject).to be_truthy
41
47
  expect(subject.id).to eq(3)
48
+ expect(subject.name).to eq('Project title')
49
+ expect(subject.description).to eq('Project description')
50
+ end
51
+ end
52
+
53
+ describe 'on #delete' do
54
+ subject do
55
+ stub_dribbble :get, '/projects/3', DribbbleAPI::ProjectSuccess
56
+ stub_dribbble :delete, '/projects/3', DribbbleAPI::ProjectsDeleted
57
+ described_class.delete 'valid_token', 3
58
+ end
59
+
60
+ it 'return true' do
61
+ expect(subject).to eq(true)
62
+ end
63
+ end
64
+
65
+ describe 'on #update' do
66
+ subject do
67
+ stub_dribbble :get, '/projects/3', DribbbleAPI::ProjectSuccess
68
+ stub_dribbble :put, '/projects/3', DribbbleAPI::ProjectsUpdated
69
+ data = {
70
+ name: 'Project title',
71
+ description: 'Project description'
72
+ }
73
+ described_class.update 'valid_token', 3, data
74
+ end
75
+
76
+ it 'update data' do
77
+ expect(subject.name).to eq('Project title')
42
78
  end
43
79
  end
44
80
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RAW_SHOT = data_from_json 'shot_success.json'
4
6
 
5
7
  describe Dribbble::Shot do
6
8
  describe 'on instance' do
7
- before :all do
8
- @shot = Dribbble::Shot.new 'valid_token', RAW_SHOT
9
+ before do
10
+ @shot = described_class.new 'valid_token', RAW_SHOT
9
11
  end
10
12
 
11
13
  describe 'after initialization' do
12
14
  RAW_SHOT.each do |field, value|
13
15
  it "respond to #{field}" do
14
- expect(@shot.send field).to eq(value)
16
+ expect(@shot.send(field)).to eq(value)
15
17
  end
16
18
  end
17
19
  end
@@ -42,18 +44,7 @@ describe Dribbble::Shot do
42
44
  end
43
45
  end
44
46
 
45
- describe 'on #attachments' do
46
- describe 'all' do
47
- subject do
48
- stub_dribbble :get, '/shots/471756/attachments', DribbbleAPI::AttachmentsSuccess
49
- @shot.attachments
50
- end
51
-
52
- it 'return a shot' do
53
- expect(subject.first).to be_a Dribbble::Attachment
54
- end
55
- end
56
-
47
+ skip 'on #attachments' do
57
48
  describe 'create' do
58
49
  describe 'when shot is accepted' do
59
50
  subject do
@@ -78,18 +69,6 @@ describe Dribbble::Shot do
78
69
  end
79
70
  end
80
71
 
81
- describe 'find' do
82
- subject do
83
- stub_dribbble :get, '/shots/471756/attachments/206165', DribbbleAPI::AttachmentSuccess
84
- @shot.find_attachment 206_165
85
- end
86
-
87
- it 'return an attachment' do
88
- expect(subject).to be_a Dribbble::Attachment
89
- expect(subject.id).to eq(206_165)
90
- end
91
- end
92
-
93
72
  describe 'delete' do
94
73
  subject do
95
74
  stub_dribbble :delete, '/shots/471756/attachments/206165', DribbbleAPI::AttachmentDeleted
@@ -101,157 +80,6 @@ describe Dribbble::Shot do
101
80
  end
102
81
  end
103
82
  end
104
-
105
- describe 'on #buckets' do
106
- subject do
107
- stub_dribbble :get, '/shots/471756/buckets', DribbbleAPI::BucketsSuccess
108
- @shot.buckets
109
- end
110
-
111
- it 'return a shot' do
112
- expect(subject.first).to be_a Dribbble::Bucket
113
- end
114
- end
115
-
116
- describe 'on #comments' do
117
- describe 'all' do
118
- subject do
119
- stub_dribbble :get, '/shots/471756/comments', DribbbleAPI::CommentsSuccess
120
- @shot.comments
121
- end
122
-
123
- it 'return comments' do
124
- expect(subject.first).to be_a Dribbble::Comment
125
- end
126
- end
127
-
128
- describe 'create' do
129
- subject do
130
- stub_dribbble :post, '/shots/471756/comments', DribbbleAPI::CommentCreated
131
- @shot.create_comment body: "<p>Could he somehow make the shape of an \"S\" with his arms? I feel like i see potential for some hidden shapes in here...</p>\n\n<p>Looks fun!\n</p>"
132
- end
133
-
134
- it 'return a comment' do
135
- expect(subject).to be_a Dribbble::Comment
136
- expect(subject.body).to eq("<p>Could he somehow make the shape of an \"S\" with his arms? I feel like i see potential for some hidden shapes in here...</p>\n\n<p>Looks fun!\n</p>")
137
- end
138
- end
139
-
140
- describe 'find' do
141
- subject do
142
- stub_dribbble :get, '/shots/471756/comments/1145736', DribbbleAPI::CommentSuccess
143
- @shot.find_comment 1_145_736
144
- end
145
-
146
- it 'return a comment' do
147
- expect(subject).to be_a Dribbble::Comment
148
- expect(subject.id).to eq(1_145_736)
149
- end
150
- end
151
-
152
- describe 'update' do
153
- subject do
154
- stub_dribbble :put, '/shots/471756/comments/1145736', DribbbleAPI::CommentUpdated
155
- @shot.update_comment 1_145_736, body: "New body"
156
- end
157
-
158
- it 'return a comment' do
159
- expect(subject).to be_a Dribbble::Comment
160
- expect(subject.body).to eq("New body")
161
- end
162
- end
163
-
164
- describe 'delete' do
165
- subject do
166
- stub_dribbble :delete, '/shots/471756/comments/1145736', DribbbleAPI::CommentDeleted
167
- @shot.delete_comment 1_145_736
168
- end
169
-
170
- it 'return true' do
171
- expect(subject).to eq(true)
172
- end
173
- end
174
- end
175
-
176
- describe 'on #likes' do
177
- subject do
178
- stub_dribbble :get, '/shots/471756/likes', DribbbleAPI::ShotLikesSuccess
179
- @shot.likes
180
- end
181
-
182
- it 'return a user' do
183
- expect(subject.first).to be_a Dribbble::Like
184
- expect(subject.first.user).to be_a Dribbble::User
185
- end
186
- end
187
-
188
- describe 'on #like?' do
189
- describe 'on a not liked shot' do
190
- subject do
191
- stub_dribbble :get, '/shots/471756/like', DribbbleAPI::ShotLikeNotFound
192
- @shot.like?
193
- end
194
-
195
- it 'return a user' do
196
- expect(subject).to be_falsy
197
- end
198
- end
199
-
200
- describe 'on a liked shot' do
201
- subject do
202
- stub_dribbble :get, '/shots/471756/like', DribbbleAPI::ShotLikeSuccess
203
- @shot.like?
204
- end
205
-
206
- it 'return a user' do
207
- expect(subject).to be_truthy
208
- end
209
- end
210
- end
211
-
212
- describe 'on #like!' do
213
- subject do
214
- stub_dribbble :post, '/shots/471756/like', DribbbleAPI::ShotLikeCreated
215
- @shot.like!
216
- end
217
-
218
- it 'return true' do
219
- expect(subject).to be_truthy
220
- end
221
- end
222
-
223
- describe 'on #unlike!' do
224
- subject do
225
- stub_dribbble :delete, '/shots/471756/like', DribbbleAPI::ShotLikeDeleted
226
- @shot.unlike!
227
- end
228
-
229
- it 'return true' do
230
- expect(subject).to be_truthy
231
- end
232
- end
233
-
234
- describe 'on #projects' do
235
- subject do
236
- stub_dribbble :get, '/shots/471756/projects', DribbbleAPI::ProjectsSuccess
237
- @shot.projects
238
- end
239
-
240
- it 'return a list of project' do
241
- expect(subject.first).to be_a Dribbble::Project
242
- end
243
- end
244
-
245
- describe 'on #rebounds' do
246
- subject do
247
- stub_dribbble :get, '/shots/471756/rebounds', DribbbleAPI::ShotsSuccess
248
- @shot.rebounds
249
- end
250
-
251
- it 'return a list of shots' do
252
- expect(subject.first).to be_a Dribbble::Shot
253
- end
254
- end
255
83
  end
256
84
 
257
85
  describe 'on class' do
@@ -262,9 +90,9 @@ describe Dribbble::Shot do
262
90
  title: 'Shot title',
263
91
  desciption: 'Shot description',
264
92
  image: File.new("#{Dir.pwd}/spec/support/fixtures/image.jpg", 'rb'),
265
- tags: %w(tag1 tag2)
93
+ tags: %w[tag1 tag2]
266
94
  }
267
- Dribbble::Shot.create 'valid_token', shot
95
+ described_class.create 'valid_token', shot
268
96
  end
269
97
 
270
98
  it 'create the shot' do
@@ -277,14 +105,14 @@ describe Dribbble::Shot do
277
105
  subject do
278
106
  stub_dribbble :get, '/shots/471756', DribbbleAPI::ShotSuccess
279
107
  stub_dribbble :put, '/shots/471756', DribbbleAPI::ShotUpdated
280
- bucket = {
108
+ data = {
281
109
  name: 'Shot title',
282
110
  description: 'Shot description'
283
111
  }
284
- Dribbble::Shot.update 'valid_token', 471_756, bucket
112
+ described_class.update 'valid_token', 471_756, data
285
113
  end
286
114
 
287
- it 'update bucket' do
115
+ it 'update data' do
288
116
  expect(subject.title).to eq('Shot title')
289
117
  end
290
118
  end
@@ -293,7 +121,7 @@ describe Dribbble::Shot do
293
121
  subject do
294
122
  stub_dribbble :get, '/shots/471756', DribbbleAPI::ShotSuccess
295
123
  stub_dribbble :delete, '/shots/471756', DribbbleAPI::ShotDeleted
296
- Dribbble::Shot.delete 'valid_token', 471_756
124
+ described_class.delete 'valid_token', 471_756
297
125
  end
298
126
 
299
127
  it 'return true' do
@@ -304,24 +132,13 @@ describe Dribbble::Shot do
304
132
  describe 'on #find' do
305
133
  subject do
306
134
  stub_dribbble :get, '/shots/471756', DribbbleAPI::ShotSuccess
307
- Dribbble::Shot.find 'valid_token', 471_756
135
+ described_class.find 'valid_token', 471_756
308
136
  end
309
137
 
310
138
  it 'return a shot' do
311
- expect(subject).to be_a Dribbble::Shot
139
+ expect(subject).to be_a described_class
312
140
  expect(subject.id).to eq(471_756)
313
141
  end
314
142
  end
315
-
316
- describe 'on #all' do
317
- subject do
318
- stub_dribbble :get, '/shots', DribbbleAPI::ShotsSuccess
319
- Dribbble::Shot.all 'valid_token'
320
- end
321
-
322
- it 'return a shot' do
323
- expect(subject.first).to be_a Dribbble::Shot
324
- end
325
- end
326
143
  end
327
144
  end