Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 0731bf7f9a
...
compare: d2e05db33a
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
View
6 TODO.md
@@ -10,8 +10,8 @@
* [DONE] Getting the list of the clip
* [DONE] Getting the original clip the clip was created via
* [DONE] Getting the comments of a clip
-* Getting the likes of a clip
-* Getting the saves of a clip
+* [DONE] Getting the likes 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
@@ -38,6 +38,6 @@
# Comment
-* Add support for comments
+* [DONE] Add support for comments
View
38 lib/kippt/clip.rb
@@ -2,6 +2,8 @@
require "kippt/user"
require "kippt/list"
require "kippt/comments"
+require "kippt/likes"
+require "kippt/saves"
class Kippt::Clip
include Kippt::Resource
@@ -48,4 +50,40 @@ def comments_count
def comments_data
attributes.comments["data"]
end
+
+ def likes
+ Kippt::Likes.new(client, self)
+ end
+
+ 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
+
+ def like
+ Kippt::Like.new(client, self).save
+ end
+
+ def unlike
+ Kippt::Like.new(client, self).destroy
+ end
end
View
3  lib/kippt/collection.rb
@@ -16,6 +16,9 @@ def initialize(data, client = nil)
@object_data = data.fetch("objects")
end
+ extend Forwardable
+ def_delegators :objects, :size, :length
+
def objects
@objects ||= @object_data.map {|data| object_class.new(data, client) }
end
View
4 lib/kippt/collection_resource.rb
@@ -9,6 +9,10 @@ def build(attributes = {})
object_class.new(attributes, client)
end
+ def create(attributes = {})
+ build(attributes).save
+ end
+
def [](resource_id)
response = client.get("#{base_uri}/#{resource_id}")
if response.success?
View
1  lib/kippt/comments.rb
@@ -1,6 +1,5 @@
require "kippt/comment_collection"
require "kippt/comment"
-require "kippt/comment_collection"
class Kippt::Comments
include Kippt::CollectionResource
View
48 lib/kippt/like.rb
@@ -0,0 +1,48 @@
+require "kippt/users"
+
+class Kippt::Like
+ def initialize(client, clip)
+ @client = client
+ @errors = []
+ @clip = clip
+ end
+
+ def id
+ nil
+ end
+
+ def collection_resource_class
+ Kippt::Likes
+ end
+
+ def writable_attributes_hash
+ nil
+ end
+
+ def save
+ @errors = []
+ response = collection_resource.save_resource(self)
+ if response[:error_message]
+ errors << response[:error_message]
+ end
+ response[:success]
+ end
+
+ def destroy
+ collection_resource.destroy_resource(self)
+ end
+
+ private
+
+ def collection_resource
+ @collection_resource ||= client.collection_resource_for(collection_resource_class, clip)
+ end
+
+ def client
+ @client
+ end
+
+ def clip
+ @clip
+ end
+end
View
48 lib/kippt/likes.rb
@@ -0,0 +1,48 @@
+require "kippt/user_collection"
+require "kippt/user"
+require "kippt/like"
+
+class Kippt::Likes
+ include Kippt::CollectionResource
+
+ attr_reader :clip
+
+ def initialize(client, clip)
+ @client = client
+ @clip = clip
+ end
+
+ def self.valid_filter_parameters
+ []
+ end
+
+ def object_class
+ Kippt::User
+ end
+
+ def collection_class
+ Kippt::UserCollection
+ end
+
+ def base_uri
+ "clips/#{clip.id}/likes"
+ end
+
+ def all(options = {})
+ validate_collection_options(options)
+
+ if options.empty? && @clip.all_likes_embedded?
+ collection_class.new({"objects" => @clip.likes_data}, client)
+ else
+ collection_class.new(client.get(base_uri, options).body, client)
+ end
+ end
+
+ def build
+ Kippt::Like.new(client, clip)
+ end
+
+ def destroy_resource(resource)
+ client.delete(base_uri).success?
+ end
+end
View
25 lib/kippt/saves.rb
@@ -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
20 spec/kippt/clip_spec.rb
@@ -84,4 +84,24 @@
end
end
end
+
+ describe "#like" do
+ let(:like) { stub :like }
+
+ it "instantiates a Kippt::Like and saves it" do
+ Kippt::Like.should_receive(:new).with(client, subject).and_return(like)
+ like.should_receive(:save)
+ subject.like
+ end
+ end
+
+ describe "#unlike" do
+ let(:like) { stub :like }
+
+ it "instantiates a Kippt::Like and destroys it" do
+ Kippt::Like.should_receive(:new).with(client, subject).and_return(like)
+ like.should_receive(:destroy)
+ subject.unlike
+ end
+ end
end
View
20 spec/kippt/saves_spec.rb
@@ -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

No commit comments for this range

Something went wrong with that request. Please try again.