Class: Meme::Post
- Inherits:
-
Object
- Object
- Meme::Post
- 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
-
.find(query, options = {}) ⇒ Object
Find posts.
-
.popular(locale = 'pt') ⇒ Object
Returns the top 10 posts on that moment.
Instance Method Summary collapse
-
#initialize(data) ⇒ Post
constructor
:nodoc:.
- #user ⇒ Object
Constructor Details
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, = {}) type = " and type='#{.delete(:type).to_s}'" if .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 |
.popular(locale = 'pt') ⇒ Object
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
#user ⇒ Object
64 65 66 |
# File 'lib/meme/search.rb', line 64 def user Meme::Info.find_by_guid(self.guid) end |