Class: Meme::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/meme/search.rb

Constant Summary collapse

VARS =

:nodoc:

["category", "timestamp", "guid", "pubid", "url", "repost_count", "caption", "type", "content"]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Post

:nodoc:



9
10
11
12
13
14
15
# File 'lib/meme/search.rb', line 9

def initialize(data) #:nodoc:
  unless data.nil?
    VARS.each do |var|
      self.instance_variable_set("@#{var}", data[var])
    end
  end      
end

Class Method Details

.find(query, options = {}) ⇒ Object

Find posts

Example:

# type text
posts = Meme::Post.find('brhackday')

# type photo
posts = Meme::Post.find('brhackday', :type => :photo)

# type video
posts = Meme::Post.find('brhackday', :type => :video)

posts.first.content
=> "RT @codepo8: And I am off - plane leaves BR for London. Thanks to everybody...


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/meme/search.rb', line 33

def self.find(query, options = {})
  type  = " and type='#{options.delete(:type).to_s}'" if options.has_key?(:type)
  query = "SELECT * FROM meme.search WHERE query='#{query}'#{type}"
  parse = Request.parse(query)
  if parse
    results = parse['query']['results']
    results.nil? ? nil : results['post'].map {|m| Post.new(m)}
  else
    parse.error!
  end
end

Returns the top 10 posts on that moment. You can also set the locale that you want to retrieve:

  • “en” for English

  • “es” for Spanish

  • “pt” for Portuguese (Default)

  • “id” for Bahasa Indonesia



53
54
55
56
57
58
59
60
61
62
# File 'lib/meme/search.rb', line 53

def self.popular(locale='pt')
  query = "SELECT * FROM meme.popular WHERE locale='#{locale}'"
  parse = Request.parse(query)
  if parse
    results = parse['query']['results']
    results.nil? ? nil : results['post'].map {|m| Post.new(m)}
  else
    parse.error!
  end
end

Instance Method Details

#userObject



64
65
66
# File 'lib/meme/search.rb', line 64

def user
  Meme::Info.find_by_guid(self.guid)
end