kippt 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +2 -0
  4. data/README.md +20 -3
  5. data/TODO.md +43 -0
  6. data/kippt.gemspec +6 -6
  7. data/lib/kippt/client.rb +46 -8
  8. data/lib/kippt/clip.rb +83 -4
  9. data/lib/kippt/clip_collection.rb +4 -0
  10. data/lib/kippt/clips.rb +8 -4
  11. data/lib/kippt/collection.rb +22 -9
  12. data/lib/kippt/collection_resource.rb +25 -8
  13. data/lib/kippt/comment.rb +25 -0
  14. data/lib/kippt/comment_collection.rb +10 -0
  15. data/lib/kippt/comments.rb +43 -0
  16. data/lib/kippt/connection.rb +14 -8
  17. data/lib/kippt/follow_relationship.rb +50 -0
  18. data/lib/kippt/followers.rb +26 -0
  19. data/lib/kippt/following.rb +26 -0
  20. data/lib/kippt/like.rb +48 -0
  21. data/lib/kippt/likes.rb +48 -0
  22. data/lib/kippt/list.rb +29 -4
  23. data/lib/kippt/list_collection.rb +4 -0
  24. data/lib/kippt/resource.rb +106 -9
  25. data/lib/kippt/saves.rb +25 -0
  26. data/lib/kippt/user.rb +59 -0
  27. data/lib/kippt/user_clips.rb +39 -0
  28. data/lib/kippt/user_collection.rb +14 -0
  29. data/lib/kippt/user_lists.rb +32 -0
  30. data/lib/kippt/users.rb +51 -0
  31. data/lib/kippt/version.rb +1 -1
  32. data/spec/fixtures/clip.json +1 -1
  33. data/spec/fixtures/comment.json +1 -0
  34. data/spec/fixtures/comments.json +1 -0
  35. data/spec/fixtures/feed.json +1 -0
  36. data/spec/fixtures/list.json +1 -1
  37. data/spec/fixtures/user.json +1 -0
  38. data/spec/fixtures/users.json +2 -0
  39. data/spec/fixtures/users_with_multiple_pages.json +1 -0
  40. data/spec/kippt/client_spec.rb +63 -8
  41. data/spec/kippt/clip_collection_spec.rb +3 -3
  42. data/spec/kippt/clip_spec.rb +109 -4
  43. data/spec/kippt/clips_spec.rb +18 -7
  44. data/spec/kippt/comment_spec.rb +25 -0
  45. data/spec/kippt/comments_spec.rb +103 -0
  46. data/spec/kippt/follow_relationship_spec.rb +34 -0
  47. data/spec/kippt/followers_spec.rb +17 -0
  48. data/spec/kippt/following_spec.rb +17 -0
  49. data/spec/kippt/list_collection_spec.rb +3 -3
  50. data/spec/kippt/list_spec.rb +92 -6
  51. data/spec/kippt/lists_spec.rb +2 -1
  52. data/spec/kippt/saves_spec.rb +20 -0
  53. data/spec/kippt/user_clips_spec.rb +29 -0
  54. data/spec/kippt/user_collection_spec.rb +14 -0
  55. data/spec/kippt/user_lists_spec.rb +13 -0
  56. data/spec/kippt/user_spec.rb +71 -0
  57. data/spec/kippt/users_spec.rb +59 -0
  58. data/spec/spec_helper.rb +60 -4
  59. metadata +106 -24
  60. data/lib/kippt/account.rb +0 -10
  61. data/spec/kippt/account_spec.rb +0 -28
@@ -2,7 +2,8 @@ require "spec_helper"
2
2
  require "kippt/clips"
3
3
 
4
4
  describe Kippt::Clips do
5
- subject { Kippt::Client.new(valid_user_credentials).clips }
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { client.clips }
6
7
  let(:base_uri) { "clips" }
7
8
  let(:singular_fixture) { "clip" }
8
9
  let(:collection_class) { Kippt::ClipCollection }
@@ -10,6 +11,16 @@ describe Kippt::Clips do
10
11
 
11
12
  it_behaves_like "collection resource"
12
13
 
14
+ describe "#feed" do
15
+ subject { Kippt::Client.new(valid_user_credentials).clips }
16
+
17
+ it "returns ClipCollection" do
18
+ stub_get("/clips/feed").
19
+ to_return(:status => 200, :body => fixture("feed.json"))
20
+ subject.feed.should be_a Kippt::ClipCollection
21
+ end
22
+ end
23
+
13
24
  describe "#search" do
14
25
  subject { Kippt::Client.new(valid_user_credentials).clips }
15
26
 
@@ -45,7 +56,7 @@ describe Kippt::Clips do
45
56
  stub_get("/search/clips?q=bunny").
46
57
  to_return(:status => 200, :body => fixture("clips.json"))
47
58
  clips = subject.search("bunny")
48
- clips.is_a? Kippt::ClipCollection
59
+ clips.should be_a Kippt::ClipCollection
49
60
  end
50
61
  end
51
62
 
@@ -54,7 +65,7 @@ describe Kippt::Clips do
54
65
 
55
66
  context "successful request" do
56
67
  it "returns hash with success boolean" do
57
- stub_request(:post, "https://kippt.com/api/clips").
68
+ stub_post("/clips").
58
69
  with(:body => "{\"url\":\"http://kiskolabs.com\"}").
59
70
  to_return(:status => 200, :body => "{}", :headers => {})
60
71
 
@@ -66,7 +77,7 @@ describe Kippt::Clips do
66
77
 
67
78
  context "unsuccessful request" do
68
79
  it "returns hash with success boolean and error message" do
69
- stub_request(:post, "https://kippt.com/api/clips").
80
+ stub_post("/clips").
70
81
  with(:body => "{\"url\":\"http://kiskolabs.com\"}").
71
82
  to_return(:status => 400, :body => "{\"message\": \"No good.\"}", :headers => {})
72
83
 
@@ -79,7 +90,7 @@ describe Kippt::Clips do
79
90
 
80
91
  context "when object doesn't have an id" do
81
92
  it "POSTs new resource to the API" do
82
- stub_request(:post, "https://kippt.com/api/clips").
93
+ stub_post("/clips").
83
94
  with(:body => "{\"url\":\"http://kiskolabs.com\"}").
84
95
  to_return(:status => 200, :body => "{}", :headers => {})
85
96
 
@@ -90,7 +101,7 @@ describe Kippt::Clips do
90
101
 
91
102
  context "when object has an id" do
92
103
  it "PUTs new version of the resource to the API" do
93
- stub_request(:put, "https://kippt.com/api/clips/22").
104
+ stub_put("/clips/22").
94
105
  with(:body => "{\"url\":\"http://kiskolabs.com\"}").
95
106
  to_return(:status => 200, :body => "{}", :headers => {})
96
107
 
@@ -105,7 +116,7 @@ describe Kippt::Clips do
105
116
 
106
117
  context "successful request" do
107
118
  it "returns boolean" do
108
- stub_request(:delete, "https://kippt.com/api/clips/100").
119
+ stub_delete("/clips/100").
109
120
  to_return(:status => 200, :headers => {})
110
121
 
111
122
  clip = Kippt::Clip.new(:id => 100)
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "kippt/comment"
3
+
4
+ describe Kippt::Comment do
5
+ subject { Kippt::Comment.new(data, client, clip) }
6
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
7
+ let(:clip) { stub(:clip) }
8
+ let(:collection_resource_class) { Kippt::Comments }
9
+
10
+ let(:data) { MultiJson.load(fixture("comment.json").read) }
11
+ let(:attributes) {
12
+ [:body, :id, :resource_uri]
13
+ }
14
+ let(:mapped_attributes) {
15
+ {:created => "Time", :user => "Kippt::User"}
16
+ }
17
+
18
+ it_behaves_like "resource"
19
+
20
+ describe "#clip" do
21
+ it "returns the clip passed to it" do
22
+ subject.clip.should eq clip
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+ require "kippt/comments"
3
+
4
+ describe Kippt::Comments do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ let(:clip) { stub :clip, :id => 100, :all_comments_embedded? => false }
7
+ subject { Kippt::Comments.new(client, clip) }
8
+ let(:base_uri) { "clips/#{clip.id}/comments" }
9
+ let(:singular_fixture) { "comment" }
10
+ let(:collection_class) { Kippt::CommentCollection }
11
+ let(:resource_class) { Kippt::Comment }
12
+
13
+ def collection_fixture
14
+ base_uri.split("/").last
15
+ end
16
+
17
+ describe "#all" do
18
+ it "returns collection class" do
19
+ stub_get("/#{base_uri}").
20
+ to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
21
+ all_resources = subject.all
22
+ all_resources.is_a? collection_class
23
+ end
24
+
25
+ it "accepts limit and offset options" do
26
+ stub_get("/#{base_uri}?limit=10&offset=100").
27
+ to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
28
+ resources = subject.all(:limit => 10, :offset => 100)
29
+ end
30
+
31
+ context "when passed unrecognized arguments" do
32
+ it "raises error" do
33
+ lambda {
34
+ subject.all(:foobar => true)
35
+ }.should raise_error(
36
+ ArgumentError, "Unrecognized argument: foobar")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#[]" do
42
+ it "fetches single resource" do
43
+ stub_get("/#{base_uri}/10").
44
+ to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
45
+ subject[10].id.should eq 10
46
+ end
47
+
48
+ it "returns resource" do
49
+ stub_get("/#{base_uri}/10").
50
+ to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
51
+ subject[10].should be_a(resource_class)
52
+ end
53
+
54
+ context "when resource is not found" do
55
+ it "raises exception" do
56
+ stub_get("/#{base_uri}/10").
57
+ to_return(:status => 404, :body => {"message" => "Resource not found."})
58
+ lambda {
59
+ subject[10]
60
+ subject.all(:foobar => true)
61
+ }.should raise_error(
62
+ Kippt::APIError, "Resource could not be loaded: Resource not found.")
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "#find" do
68
+ it "exists" do
69
+ subject.respond_to?(:find).should be_true
70
+ end
71
+ end
72
+
73
+ describe "#collection_from_url" do
74
+ it "returns a new collection" do
75
+ stub_get("/#{base_uri}/?limit=20&offset=20").
76
+ to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
77
+ collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
78
+ collection.should be_a(collection_class)
79
+ end
80
+
81
+ context "when passed URL is blank" do
82
+ it "raises ArgumentError" do
83
+ lambda {
84
+ subject.collection_from_url("")
85
+ }.should raise_error(ArgumentError, "The parameter URL can't be blank")
86
+ lambda {
87
+ subject.collection_from_url(nil)
88
+ }.should raise_error(ArgumentError, "The parameter URL can't be blank")
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#build" do
94
+ it "returns new resource" do
95
+ subject.build.should be_a(resource_class)
96
+ end
97
+
98
+ it "accepts parameters" do
99
+ subject.object_class.should_receive(:new).with({:an => "attribute"}, client, clip)
100
+ subject.build(:an => "attribute")
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ require "kippt/follow_relationship"
3
+
4
+ describe Kippt::FollowRelationship do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ let(:user) { stub :user, :id => 10 }
7
+ subject { Kippt::FollowRelationship.new(client, user) }
8
+
9
+ describe "#following?" do
10
+ it "returns boolean" do
11
+ stub_get("/users/10/relationship/").
12
+ to_return(:status => 200, :body => '{"following": true}')
13
+ subject.following?.should be_true
14
+ end
15
+ end
16
+
17
+ describe "#follow" do
18
+ it "updates the value on the server" do
19
+ stub_post("/users/10/relationship/").
20
+ with(:body => "{\"action\":\"follow\"}").
21
+ to_return(:status => 200, :body => "", :headers => {})
22
+ subject.follow.should be_true
23
+ end
24
+ end
25
+
26
+ describe "#unfollow" do
27
+ it "updates the value on the server" do
28
+ stub_post("/users/10/relationship/").
29
+ with(:body => "{\"action\":\"unfollow\"}").
30
+ to_return(:status => 200, :body => "", :headers => {})
31
+ subject.unfollow.should be_true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+ require "kippt/followers"
3
+
4
+ describe Kippt::Followers do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { Kippt::User.new({:id => 10}, client).followers }
7
+
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
17
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+ require "kippt/following"
3
+
4
+ describe Kippt::Following do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { Kippt::User.new({:id => 10}, client).following }
7
+
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
17
+ end
@@ -5,9 +5,9 @@ describe Kippt::ListCollection do
5
5
  let(:data_with_multiple_pages) {
6
6
  MultiJson.load(fixture("lists_with_multiple_pages.json").read)
7
7
  }
8
- subject { Kippt::ListCollection.new(data) }
9
- let(:subject_with_multiple_pages) { Kippt::ListCollection.new(data_with_multiple_pages, collection_resource) }
10
- let(:collection_resource) { nil }
8
+ let(:client) { stub }
9
+ subject { Kippt::ListCollection.new(data, client) }
10
+ let(:subject_with_multiple_pages) { Kippt::ListCollection.new(data_with_multiple_pages, client) }
11
11
 
12
12
  it_behaves_like "collection"
13
13
  end
@@ -2,14 +2,100 @@ require "spec_helper"
2
2
  require "kippt/list"
3
3
 
4
4
  describe Kippt::List do
5
- subject { Kippt::List.new(data, collection_resource) }
6
- let(:collection_resource) { Kippt::Client.new(valid_user_credentials).lists }
5
+ subject { Kippt::List.new(data, client) }
6
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
7
+ let(:collection_resource_class) { Kippt::Lists }
7
8
 
8
- let(:data) { MultiJson.load(fixture("list.json").read) }
9
- let(:attributes) {
10
- [:id, :rss_url, :updated, :title,
11
- :created, :slug, :resource_uri]
9
+ let(:data) { json_fixture("list.json") }
10
+ let(:attributes) {
11
+ [:id, :rss_url, :title,
12
+ :slug, :resource_uri]
12
13
  }
14
+ let(:mapped_attributes) {
15
+ {:updated => "Time", :created => "Time",
16
+ :user => "Kippt::User"}
17
+ }
13
18
 
14
19
  it_behaves_like "resource"
20
+
21
+ describe "#private?" do
22
+ it "gets data from is_private" do
23
+ list = Kippt::List.new({"is_private" => true}, nil)
24
+ list.private?.should be_true
25
+ end
26
+ end
27
+
28
+ describe "#collaborators" do
29
+ it "returns the users generated from the data" do
30
+ list = Kippt::List.new({"collaborators" => {"count" => 1, "data" => [json_fixture("user.json")]}}, nil)
31
+ list.collaborators.size.should eq 1
32
+ list.collaborators.first.should be_a Kippt::User
33
+ end
34
+ end
35
+
36
+ describe "#follow" do
37
+ context "when request is successful" do
38
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
39
+
40
+ it "makes a request" do
41
+ response = stub(:success? => true)
42
+ client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
43
+ list = Kippt::List.new(json_fixture("list.json"), client)
44
+ list.follow
45
+ end
46
+
47
+ it "returns true" do
48
+ stub_request(:post, "https://kippt.com/api/lists/10/relationship").
49
+ with(:body => "{\"action\":\"follow\"}").
50
+ to_return(:status => 200, :body => "{\"folloring\":true}")
51
+ list = Kippt::List.new(json_fixture("list.json"), client)
52
+ list.follow.should eq true
53
+ end
54
+ end
55
+
56
+ context "when request is unsuccessful" do
57
+ it "raises an exception" do
58
+ response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
59
+ client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
60
+ list = Kippt::List.new(json_fixture("list.json"), client)
61
+
62
+ expect {
63
+ list.follow
64
+ }.to raise_error(Kippt::APIError, "There was an error with the request: Weird issue going on.")
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#unfollow" do
70
+ context "when request is successful" do
71
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
72
+
73
+ it "makes a request" do
74
+ response = stub(:success? => true)
75
+ client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
76
+ list = Kippt::List.new(json_fixture("list.json"), client)
77
+ list.unfollow
78
+ end
79
+
80
+ it "returns true" do
81
+ stub_request(:post, "https://kippt.com/api/lists/10/relationship").
82
+ with(:body => "{\"action\":\"unfollow\"}").
83
+ to_return(:status => 200, :body => "{\"folloring\":false}")
84
+ list = Kippt::List.new(json_fixture("list.json"), client)
85
+ list.unfollow.should eq true
86
+ end
87
+ end
88
+
89
+ context "when request is unsuccessful" do
90
+ it "raises an exception" do
91
+ response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
92
+ client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
93
+ list = Kippt::List.new(json_fixture("list.json"), client)
94
+
95
+ expect {
96
+ list.unfollow
97
+ }.to raise_error(Kippt::APIError, "There was an error with the request: Weird issue going on.")
98
+ end
99
+ end
100
+ end
15
101
  end
@@ -2,7 +2,8 @@ require "spec_helper"
2
2
  require "kippt/lists"
3
3
 
4
4
  describe Kippt::Lists do
5
- subject { Kippt::Client.new(valid_user_credentials).lists }
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { client.lists }
6
7
  let(:base_uri) { "lists" }
7
8
  let(:singular_fixture) { "list" }
8
9
  let(:collection_class) { Kippt::ListCollection }
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+ require "kippt/saves"
3
+
4
+ describe Kippt::Saves do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ let(:clip) { stub :clip, :saves_data => fixture("users.json") }
7
+ subject { Kippt::Saves.new(client, clip) }
8
+
9
+ describe "#all" do
10
+ it "returns collection class" do
11
+ all_resources = subject.all
12
+ all_resources.is_a? Kippt::UserCollection
13
+ end
14
+
15
+ it "uses the clip saves data" do
16
+ Kippt::UserCollection.should_receive(:new).with({"objects" => clip.saves_data}, client)
17
+ subject.all
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require "kippt/user_clips"
3
+
4
+ describe Kippt::UserClips do
5
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
6
+ subject { Kippt::User.new({:id => 10}, client).clips }
7
+ let(:base_uri) { "users/#{10}/clips" }
8
+ let(:singular_fixture) { "clip" }
9
+ let(:collection_class) { Kippt::ClipCollection }
10
+ let(:resource_class) { Kippt::Clip }
11
+
12
+ it_behaves_like "collection resource"
13
+
14
+ describe "#favorites" do
15
+ it "returns ClipCollection" do
16
+ stub_get("/#{base_uri}/favorites").
17
+ to_return(:status => 200, :body => fixture("clips.json"))
18
+ subject.favorites.should be_a Kippt::ClipCollection
19
+ end
20
+ end
21
+
22
+ describe "#likes" do
23
+ it "returns ClipCollection" do
24
+ stub_get("/#{base_uri}/likes").
25
+ to_return(:status => 200, :body => fixture("clips.json"))
26
+ subject.likes.should be_a Kippt::ClipCollection
27
+ end
28
+ end
29
+ end