kippt 2.0.1 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +15 -0
  2. data/.travis.yml +1 -4
  3. data/CHANGELOG.md +24 -0
  4. data/Gemfile +4 -0
  5. data/README.md +14 -4
  6. data/TODO.md +16 -0
  7. data/lib/kippt.rb +8 -3
  8. data/lib/kippt/client.rb +6 -6
  9. data/lib/kippt/clip.rb +17 -9
  10. data/lib/kippt/clip_collection.rb +2 -2
  11. data/lib/kippt/clip_likes.rb +29 -0
  12. data/lib/kippt/clips.rb +8 -37
  13. data/lib/kippt/collection.rb +1 -2
  14. data/lib/kippt/collection_resource.rb +39 -55
  15. data/lib/kippt/comment.rb +2 -4
  16. data/lib/kippt/comment_collection.rb +1 -2
  17. data/lib/kippt/comments.rb +5 -3
  18. data/lib/kippt/connection.rb +7 -3
  19. data/lib/kippt/favorite.rb +46 -0
  20. data/lib/kippt/favorites.rb +20 -0
  21. data/lib/kippt/followers.rb +6 -4
  22. data/lib/kippt/following.rb +6 -4
  23. data/lib/kippt/helpers.rb +17 -0
  24. data/lib/kippt/like.rb +4 -6
  25. data/lib/kippt/like_collection.rb +11 -0
  26. data/lib/kippt/likes.rb +2 -30
  27. data/lib/kippt/list.rb +8 -2
  28. data/lib/kippt/list_collection.rb +2 -2
  29. data/lib/kippt/lists.rb +2 -4
  30. data/lib/kippt/read_collection_resource.rb +43 -0
  31. data/lib/kippt/root_clips.rb +39 -0
  32. data/lib/kippt/saves.rb +4 -3
  33. data/lib/kippt/user.rb +10 -6
  34. data/lib/kippt/user_clips.rb +6 -26
  35. data/lib/kippt/user_collection.rb +0 -3
  36. data/lib/kippt/user_likes.rb +29 -0
  37. data/lib/kippt/user_lists.rb +0 -5
  38. data/lib/kippt/users.rb +3 -8
  39. data/lib/kippt/version.rb +1 -1
  40. data/spec/kippt/client_spec.rb +36 -2
  41. data/spec/kippt/clip_likes_spec.rb +14 -0
  42. data/spec/kippt/clip_spec.rb +89 -3
  43. data/spec/kippt/clips_spec.rb +27 -5
  44. data/spec/kippt/comment_spec.rb +1 -1
  45. data/spec/kippt/comments_spec.rb +30 -5
  46. data/spec/kippt/favorite_spec.rb +38 -0
  47. data/spec/kippt/favorites_spec.rb +18 -0
  48. data/spec/kippt/follow_relationship_spec.rb +30 -0
  49. data/spec/kippt/followers_spec.rb +6 -9
  50. data/spec/kippt/following_spec.rb +6 -9
  51. data/spec/kippt/like_spec.rb +38 -0
  52. data/spec/kippt/likes_spec.rb +21 -0
  53. data/spec/kippt/list_spec.rb +43 -10
  54. data/spec/kippt/lists_spec.rb +12 -0
  55. data/spec/kippt/saves_spec.rb +3 -3
  56. data/spec/kippt/user_clips_spec.rb +14 -2
  57. data/spec/kippt/user_likes_spec.rb +14 -0
  58. data/spec/kippt/user_lists_spec.rb +12 -0
  59. data/spec/kippt/user_spec.rb +11 -0
  60. data/spec/kippt/users_spec.rb +2 -1
  61. data/spec/shared_examples/collection.rb +117 -0
  62. data/spec/shared_examples/collection_resource.rb +13 -0
  63. data/spec/shared_examples/read_collection_resource.rb +77 -0
  64. data/spec/shared_examples/resource.rb +80 -0
  65. data/spec/spec_helper.rb +2 -298
  66. metadata +33 -26
  67. data/lib/core_ext/open_struct.rb +0 -5
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe Kippt::Favorite do
4
+ describe "#save" do
5
+ let(:client) { double :client }
6
+ let(:clip) { double :clip }
7
+ let(:collection) { double :likes_collection_resource }
8
+ let(:favorite) { Kippt::Favorite.new(clip, client) }
9
+
10
+ it "tells collection resource to save itself" do
11
+ collection.should_receive(:save_resource).with(favorite).and_return({success: true})
12
+ client.should_receive(:collection_resource_for).with(Kippt::Favorites, clip).and_return(collection)
13
+
14
+ favorite.save.should be_true
15
+ end
16
+
17
+ it "sets errors if there is any" do
18
+ collection.stub(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
+ client.stub(:collection_resource_for).and_return(collection)
20
+
21
+ favorite.save.should be_false
22
+ favorite.errors.should eq ["PROBLEM"]
23
+ end
24
+ end
25
+
26
+ describe "#destroy" do
27
+ let(:client) { double :client }
28
+ let(:clip) { double :clip }
29
+ let(:collection) { double :likes_collection_resource }
30
+ let(:favorite) { Kippt::Favorite.new(clip, client) }
31
+
32
+ it "tells collection resource to destroy itself" do
33
+ client.stub(:collection_resource_for).and_return(collection)
34
+ collection.should_receive(:destroy_resource).with(favorite).and_return(true)
35
+ favorite.destroy.should be_true
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+ require "kippt/favorites"
3
+
4
+ describe Kippt::Favorites do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ let(:clip) { stub :user, :id => 100, :all_favorites_embedded? => false }
7
+ subject { Kippt::Favorites.new(client, clip) }
8
+ let(:base_uri) { "clips/#{clip.id}/favorites" }
9
+
10
+ describe "#destroy_resource" do
11
+ it "uses only the base_uri" do
12
+ favorite = double :favorite
13
+ response = double :response, success?: true
14
+ client.should_receive(:delete).with("clips/100/favorites").and_return(response)
15
+ subject.destroy_resource(favorite).should be_true
16
+ end
17
+ end
18
+ end
@@ -12,6 +12,16 @@ describe Kippt::FollowRelationship do
12
12
  to_return(:status => 200, :body => '{"following": true}')
13
13
  subject.following?.should be_true
14
14
  end
15
+
16
+ context "when request is not successful" do
17
+ it "raises an exception" do
18
+ fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
19
+ client.stub(:get).and_return(fail_response)
20
+ expect {
21
+ subject.following?
22
+ }.to raise_exception Kippt::APIError, "Resource could not be loaded: NOT FOUND"
23
+ end
24
+ end
15
25
  end
16
26
 
17
27
  describe "#follow" do
@@ -21,6 +31,16 @@ describe Kippt::FollowRelationship do
21
31
  to_return(:status => 200, :body => "", :headers => {})
22
32
  subject.follow.should be_true
23
33
  end
34
+
35
+ context "when request is not successful" do
36
+ it "raises an exception" do
37
+ fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
38
+ client.stub(:post).and_return(fail_response)
39
+ expect {
40
+ subject.follow
41
+ }.to raise_exception Kippt::APIError, "Problem with following: NOT FOUND"
42
+ end
43
+ end
24
44
  end
25
45
 
26
46
  describe "#unfollow" do
@@ -30,5 +50,15 @@ describe Kippt::FollowRelationship do
30
50
  to_return(:status => 200, :body => "", :headers => {})
31
51
  subject.unfollow.should be_true
32
52
  end
53
+
54
+ context "when request is not successful" do
55
+ it "raises an exception" do
56
+ fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
57
+ client.stub(:post).and_return(fail_response)
58
+ expect {
59
+ subject.unfollow
60
+ }.to raise_exception Kippt::APIError, "Problem with unfollowing: NOT FOUND"
61
+ end
62
+ end
33
63
  end
34
64
  end
@@ -4,14 +4,11 @@ require "kippt/followers"
4
4
  describe Kippt::Followers do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
6
  subject { Kippt::User.new({:id => 10}, client).followers }
7
+ let(:base_uri) { "users/10/followers" }
8
+ let(:singular_fixture) { "user" }
9
+ let(:collection_fixture) { "users" }
10
+ let(:resource_class) { Kippt::User }
11
+ let(:collection_class) { Kippt::UserCollection }
7
12
 
8
- it "is a collection resource" do
9
- subject.should be_a Kippt::CollectionResource
10
- end
11
-
12
- it "uses the correct base uri" do
13
- stub_get("/users/10/followers").
14
- to_return(:status => 200, :body => fixture("users.json"))
15
- subject.all
16
- end
13
+ it_behaves_like "read collection resource"
17
14
  end
@@ -4,14 +4,11 @@ require "kippt/following"
4
4
  describe Kippt::Following do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
6
  subject { Kippt::User.new({:id => 10}, client).following }
7
+ let(:base_uri) { "users/10/following" }
8
+ let(:singular_fixture) { "user" }
9
+ let(:collection_fixture) { "users" }
10
+ let(:resource_class) { Kippt::User }
11
+ let(:collection_class) { Kippt::UserCollection }
7
12
 
8
- it "is a collection resource" do
9
- subject.should be_a Kippt::CollectionResource
10
- end
11
-
12
- it "uses the correct base uri" do
13
- stub_get("/users/10/following").
14
- to_return(:status => 200, :body => fixture("users.json"))
15
- subject.all
16
- end
13
+ it_behaves_like "read collection resource"
17
14
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe Kippt::Like do
4
+ describe "#save" do
5
+ let(:client) { double :client }
6
+ let(:clip) { double :clip }
7
+ let(:collection) { double :likes_collection_resource }
8
+ let(:like) { Kippt::Like.new(clip, client) }
9
+
10
+ it "tells collection resource to save itself" do
11
+ collection.should_receive(:save_resource).with(like).and_return({success: true})
12
+ client.should_receive(:collection_resource_for).with(Kippt::Likes, clip).and_return(collection)
13
+
14
+ like.save.should be_true
15
+ end
16
+
17
+ it "sets errors if there is any" do
18
+ collection.stub(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
+ client.stub(:collection_resource_for).and_return(collection)
20
+
21
+ like.save.should be_false
22
+ like.errors.should eq ["PROBLEM"]
23
+ end
24
+ end
25
+
26
+ describe "#destroy" do
27
+ let(:client) { double :client }
28
+ let(:clip) { double :clip }
29
+ let(:collection) { double :likes_collection_resource }
30
+ let(:like) { Kippt::Like.new(clip, client) }
31
+
32
+ it "tells collection resource to destroy itself" do
33
+ client.stub(:collection_resource_for).and_return(collection)
34
+ collection.should_receive(:destroy_resource).with(like).and_return(true)
35
+ like.destroy.should be_true
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ require "kippt/likes"
3
+
4
+ describe Kippt::Likes do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ let(:clip) { stub :user, :id => 100, :all_likes_embedded? => false }
7
+ subject { Kippt::Likes.new(client, clip) }
8
+ let(:base_uri) { "clips/#{clip.id}/likes" }
9
+ let(:singular_fixture) { "user" }
10
+ let(:collection_class) { Kippt::UserCollection }
11
+ let(:resource_class) { Kippt::User }
12
+
13
+ describe "#destroy_resource" do
14
+ it "uses only the base_uri" do
15
+ like = double :like
16
+ response = double :response, success?: true
17
+ client.should_receive(:delete).with("clips/100/likes").and_return(response)
18
+ subject.destroy_resource(like).should be_true
19
+ end
20
+ end
21
+ end
@@ -37,29 +37,62 @@ describe Kippt::List do
37
37
  subject { Kippt::List.new({ "id" => 10 }, client).clips }
38
38
 
39
39
  it "returns the clips for the list" do
40
- stub_get("/lists/#{10}/clips").
40
+ stub_get("/lists/10/clips").
41
41
  to_return(:status => 200, :body => fixture("clips.json"))
42
- subject.should be_a Kippt::ClipCollection
42
+ subject.should be_a Kippt::Clips
43
+ subject.base_uri.should eq "lists/10/clips"
43
44
  end
44
45
  end
45
46
 
46
- describe "#follow" do
47
+ describe "#following?" do
47
48
  context "when request is successful" do
48
49
  let(:client) { Kippt::Client.new(valid_user_credentials) }
49
50
 
51
+ it "returns value from the response" do
52
+ response = stub(:success? => true, body: {"following" => false})
53
+ client.should_receive(:get).with("/api/lists/10/relationship").and_return(response)
54
+ list = Kippt::List.new(json_fixture("list.json"), client)
55
+ list.following?.should be_false
56
+ end
57
+
50
58
  it "makes a request" do
59
+ stub_request(:get, "https://kippt.com/api/lists/10/relationship").
60
+ to_return(:status => 200, :body => "{\"following\":true}")
61
+ list = Kippt::List.new(json_fixture("list.json"), client)
62
+ list.following?
63
+ end
64
+ end
65
+
66
+ context "when request is unsuccessful" do
67
+ it "raises an exception" do
68
+ response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
69
+ client.should_receive(:get).with("/api/lists/10/relationship").and_return(response)
70
+ list = Kippt::List.new(json_fixture("list.json"), client)
71
+
72
+ expect {
73
+ list.following?
74
+ }.to raise_error(Kippt::APIError, "There was an error with the request: Weird issue going on.")
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "#follow" do
80
+ context "when request is successful" do
81
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
82
+
83
+ it "returns true" do
51
84
  response = stub(:success? => true)
52
85
  client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
53
86
  list = Kippt::List.new(json_fixture("list.json"), client)
54
- list.follow
87
+ list.follow.should eq true
55
88
  end
56
89
 
57
- it "returns true" do
90
+ it "makes a request" do
58
91
  stub_request(:post, "https://kippt.com/api/lists/10/relationship").
59
92
  with(:body => "{\"action\":\"follow\"}").
60
93
  to_return(:status => 200, :body => "{\"folloring\":true}")
61
94
  list = Kippt::List.new(json_fixture("list.json"), client)
62
- list.follow.should eq true
95
+ list.follow
63
96
  end
64
97
  end
65
98
 
@@ -80,19 +113,19 @@ describe Kippt::List do
80
113
  context "when request is successful" do
81
114
  let(:client) { Kippt::Client.new(valid_user_credentials) }
82
115
 
83
- it "makes a request" do
116
+ it "returns true" do
84
117
  response = stub(:success? => true)
85
118
  client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
86
119
  list = Kippt::List.new(json_fixture("list.json"), client)
87
- list.unfollow
120
+ list.unfollow.should eq true
88
121
  end
89
122
 
90
- it "returns true" do
123
+ it "makes a request" do
91
124
  stub_request(:post, "https://kippt.com/api/lists/10/relationship").
92
125
  with(:body => "{\"action\":\"unfollow\"}").
93
126
  to_return(:status => 200, :body => "{\"folloring\":false}")
94
127
  list = Kippt::List.new(json_fixture("list.json"), client)
95
- list.unfollow.should eq true
128
+ list.unfollow
96
129
  end
97
130
  end
98
131
 
@@ -6,8 +6,20 @@ describe Kippt::Lists do
6
6
  subject { client.lists }
7
7
  let(:base_uri) { "lists" }
8
8
  let(:singular_fixture) { "list" }
9
+ let(:collection_fixture) { "lists" }
9
10
  let(:collection_class) { Kippt::ListCollection }
10
11
  let(:resource_class) { Kippt::List }
11
12
 
12
13
  it_behaves_like "collection resource"
14
+
15
+ describe "#build" do
16
+ it "returns new resource" do
17
+ subject.build.should be_a(resource_class)
18
+ end
19
+
20
+ it "accepts parameters" do
21
+ subject.object_class.should_receive(:new).with({:an => "attribute"}, client)
22
+ subject.build(:an => "attribute")
23
+ end
24
+ end
13
25
  end
@@ -6,15 +6,15 @@ describe Kippt::Saves do
6
6
  let(:clip) { stub :clip, :saves_data => fixture("users.json") }
7
7
  subject { Kippt::Saves.new(client, clip) }
8
8
 
9
- describe "#all" do
9
+ describe "#fetch" do
10
10
  it "returns collection class" do
11
- all_resources = subject.all
11
+ all_resources = subject.fetch
12
12
  all_resources.is_a? Kippt::UserCollection
13
13
  end
14
14
 
15
15
  it "uses the clip saves data" do
16
16
  Kippt::UserCollection.should_receive(:new).with({"objects" => clip.saves_data}, client)
17
- subject.all
17
+ subject.fetch
18
18
  end
19
19
  end
20
20
  end
@@ -6,16 +6,28 @@ describe Kippt::UserClips do
6
6
  subject { Kippt::User.new({:id => 10}, client).clips }
7
7
  let(:base_uri) { "users/#{10}/clips" }
8
8
  let(:singular_fixture) { "clip" }
9
+ let(:collection_fixture) { "clips" }
9
10
  let(:collection_class) { Kippt::ClipCollection }
10
11
  let(:resource_class) { Kippt::Clip }
11
12
 
12
13
  it_behaves_like "collection resource"
13
14
 
15
+ describe "#build" do
16
+ it "returns new resource" do
17
+ subject.build.should be_a(resource_class)
18
+ end
19
+
20
+ it "accepts parameters" do
21
+ subject.object_class.should_receive(:new).with({:an => "attribute"}, client)
22
+ subject.build(:an => "attribute")
23
+ end
24
+ end
25
+
14
26
  describe "#favorites" do
15
27
  it "returns ClipCollection" do
16
28
  stub_get("/#{base_uri}/favorites").
17
29
  to_return(:status => 200, :body => fixture("clips.json"))
18
- subject.favorites.should be_a Kippt::ClipCollection
30
+ subject.favorites.should be_a Kippt::Clips
19
31
  end
20
32
  end
21
33
 
@@ -23,7 +35,7 @@ describe Kippt::UserClips do
23
35
  it "returns ClipCollection" do
24
36
  stub_get("/#{base_uri}/likes").
25
37
  to_return(:status => 200, :body => fixture("clips.json"))
26
- subject.likes.should be_a Kippt::ClipCollection
38
+ subject.likes.should be_a Kippt::Clips
27
39
  end
28
40
  end
29
41
  end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ require "kippt/user_likes"
3
+
4
+ describe Kippt::UserLikes do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { Kippt::User.new({:id => 10}, client).likes }
7
+ let(:base_uri) { "users/10/clips/likes" }
8
+ let(:singular_fixture) { "clip" }
9
+ let(:collection_fixture) { "clips" }
10
+ let(:collection_class) { Kippt::ClipCollection }
11
+ let(:resource_class) { Kippt::Clip }
12
+
13
+ it_behaves_like "read collection resource"
14
+ end
@@ -6,8 +6,20 @@ describe Kippt::UserLists do
6
6
  subject { Kippt::User.new({:id => 10}, client).lists }
7
7
  let(:base_uri) { "users/#{10}/lists" }
8
8
  let(:singular_fixture) { "list" }
9
+ let(:collection_fixture) { "lists" }
9
10
  let(:collection_class) { Kippt::ListCollection }
10
11
  let(:resource_class) { Kippt::List }
11
12
 
12
13
  it_behaves_like "collection resource"
14
+
15
+ describe "#build" do
16
+ it "returns new resource" do
17
+ subject.build.should be_a(resource_class)
18
+ end
19
+
20
+ it "accepts parameters" do
21
+ subject.object_class.should_receive(:new).with({:an => "attribute"}, client)
22
+ subject.build(:an => "attribute")
23
+ end
24
+ end
13
25
  end
@@ -25,6 +25,17 @@ describe Kippt::User do
25
25
  end
26
26
  end
27
27
 
28
+ describe "#likes" do
29
+ it "returns correctly configured user likes proxy" do
30
+ client = double :client
31
+ user = Kippt::User.new(nil, client)
32
+
33
+ likes = user.likes
34
+ likes.should be_a(Kippt::UserLikes)
35
+ likes.user.should eq user
36
+ end
37
+ end
38
+
28
39
  describe "#following?" do
29
40
  it "uses Kippt::FollowRelationship to get the information" do
30
41
  follow_relationship = mock(:follow_relationship,
@@ -6,10 +6,11 @@ describe Kippt::Users do
6
6
  subject { client.users }
7
7
  let(:base_uri) { "users" }
8
8
  let(:singular_fixture) { "user" }
9
+ let(:collection_fixture) { "users" }
9
10
  let(:collection_class) { Kippt::UserCollection }
10
11
  let(:resource_class) { Kippt::User }
11
12
 
12
- it_behaves_like "collection resource"
13
+ it_behaves_like "read collection resource"
13
14
 
14
15
  describe "#search" do
15
16
  subject { Kippt::Client.new(valid_user_credentials).users }