Class: SocialcastApi::Message

Inherits:
Base
  • Object
show all
Defined in:
lib/socialcast-api/base.rb

Defined Under Namespace

Classes: Flag, Like

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(args = {}) ⇒ Object



18
19
20
# File 'lib/socialcast-api/base.rb', line 18

def self.search(args = {})
  get(:search, args).map {|message| Message.new(message)}
end

.search_all_pages(args = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/socialcast-api/base.rb', line 22

def self.search_all_pages(args = {})
  results = Array.new
  page = 1
  per_page = 500    
  
  begin
    messages = get(:search, :page => page, :per_page => per_page, :q => args[:q]).map {|message| Message.new(message)}
    page += 1
    results += messages
  end until messages.count < per_page

  return results
end

Instance Method Details

#flagObject



48
49
50
# File 'lib/socialcast-api/base.rb', line 48

def flag
  Message.post(id.to_s + '/flags')
end

#likeObject



36
37
38
# File 'lib/socialcast-api/base.rb', line 36

def like
  Message.post(id.to_s + '/likes')
end

#unflagObject



52
53
54
# File 'lib/socialcast-api/base.rb', line 52

def unflag
  Message.delete(id.to_s + '/flags/' + attributes[:flag].id)
end

#unlikeObject



40
41
42
43
44
45
46
# File 'lib/socialcast-api/base.rb', line 40

def unlike
  likedbyme = likes.select {|alike| alike.unlikable}.first
  if likedbyme
    likedbyme.prefix_options = {:message_id => self.id}
    likedbyme.destroy 
  end
end