Permalink
Browse files

Adds support for clip saves

  • Loading branch information...
1 parent f37ef23 commit 455b160fb07cb9acb10a963ea7281918dd922260 @vesan committed with Apr 1, 2013
Showing with 59 additions and 2 deletions.
  1. +1 −1 TODO.md
  2. +13 −1 lib/kippt/clip.rb
  3. +25 −0 lib/kippt/saves.rb
  4. +20 −0 spec/kippt/saves_spec.rb
View
@@ -11,7 +11,7 @@
* [DONE] Getting the original clip the clip was created via
* [DONE] Getting the comments of a clip
* [DONE] Getting the likes of a clip
-* Getting the saves of a clip
+* [DONE] Getting the saves of a clip
* [DONE] Getting and setting is favorited (How does is starred work with it?)
* [DONE] Getting the media of the clip (experimental)
* [DONE] Getting the type of the clip
View
@@ -3,6 +3,7 @@
require "kippt/list"
require "kippt/comments"
require "kippt/likes"
+require "kippt/saves"
class Kippt::Clip
include Kippt::Resource
@@ -58,12 +59,23 @@ def all_likes_embedded?
likes_count == likes_data.size
end
-
def likes_count
attributes.likes["count"]
end
def likes_data
attributes.likes["data"]
end
+
+ def saves
+ Kippt::Saves.new(client, self)
+ end
+
+ def saves_count
+ attributes.saves["count"]
+ end
+
+ def saves_data
+ attributes.saves["data"]
+ end
end
View
@@ -0,0 +1,25 @@
+require "kippt/user_collection"
+require "kippt/user"
+
+class Kippt::Saves
+ attr_reader :clip
+
+ def initialize(client, clip)
+ @client = client
+ @clip = clip
+ end
+
+ def collection_class
+ Kippt::UserCollection
+ end
+
+ def all(options = {})
+ collection_class.new({"objects" => @clip.saves_data}, client)
+ end
+
+ private
+
+ def client
+ @client
+ end
+end
View
@@ -0,0 +1,20 @@
+require "spec_helper"
+require "kippt/saves"
+
+describe Kippt::Saves do
+ let(:client) { Kippt::Client.new(valid_user_credentials) }
+ let(:clip) { stub :clip, :saves_data => fixture("users.json") }
+ subject { Kippt::Saves.new(client, clip) }
+
+ describe "#all" do
+ it "returns collection class" do
+ all_resources = subject.all
+ all_resources.is_a? Kippt::UserCollection
+ end
+
+ it "uses the clip saves data" do
+ Kippt::UserCollection.should_receive(:new).with({"objects" => clip.saves_data}, client)
+ subject.all
+ end
+ end
+end

0 comments on commit 455b160

Please sign in to comment.