Sha256: 23facedd325416edfeb1922a41e92dd9f1fc2abd237946b3b4d82764ea060627

Contents?: true

Size: 647 Bytes

Versions: 1

Compression:

Stored size: 647 Bytes

Contents

module Socialcastr
  class Comment < Base
    def like!
      self.likes ||= []
      likes << Like.parse(api.post(element_path(:message_id => self.message_id) + "/likes"))
    end

    def unlike!
      self.likes.reject! do |l|
        l.unlikable_by?(self.user_id) && api.delete(element_path(:message_id => self.mesage_id) + "/likes/#{l.id}")
      end
    end

    def unlikable_by?(api_id)
      self.likes.map{|l| l.unlikable_by?(api_id)}.any?
    end
    
    def likable_by?(api_id)
      self.user_id  != api_id
    end
    
    def like_id(api_id)
      self.likes.select { |like| like.unlikable_by?(api_id) }.first.id
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
socialcastr-0.2.6 lib/socialcastr/comment.rb