Sha256: 6ee9101dd4e1aaec4078def5e813644859fccbecf78b93568c2c99ebd4444b77

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module Socialcastr

  class Message < Base

    def flag!
      return true if flagged?
      Socialcastr::Flag.new({}, :message_id => id).save
      refresh
    end

    def flagged?
      self.flag && !self.flag.id.nil?
    end

    def unflag!
      return unless flagged?
      self.flag.destroy
      refresh  
    end

    def like!
      Socialcastr::Like.new({}, :message_id => id).save
      refresh
    end

    def likable_by?(api_id)
      return false if self.user.id == api_id
      like_for(api_id).nil?
    end

    def like_for(api_id)
      return nil if (self.likes.nil? || self.likes.empty?)
      self.likes.select { |like| like.unlikable_by?(api_id) }.first
    end

    def unlike!
      self.likes.reject! do |l|
        l.unlikable && l.destroy
      end
    end

    def comment!(arguments={})
      Socialcastr::Comment.new(arguments, :message_id => id).save
      refresh
    end
    

    def self.search(query, arguments={})
      xml = api.get(collection_path + "/search", { :q => query}.merge(arguments))
      return parse(xml)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
socialcastr-0.2.19 lib/socialcastr/message.rb
socialcastr-0.2.18 lib/socialcastr/message.rb
socialcastr-0.2.17 lib/socialcastr/message.rb
socialcastr-0.2.16 lib/socialcastr/message.rb
socialcastr-0.2.15 lib/socialcastr/message.rb
socialcastr-0.2.14 lib/socialcastr/message.rb