Class: Omnom::Source::Twitter::Search
- Defined in:
- lib/omnom/source/twitter/search.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #feed_key, #key, #options, #settings, #source_id
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#after_initialize, config, cron, every, feed_url, full_key, guid_namespace, icon, icon_from_url, inherited, #initialize, key, required_config, required_options, #update, url
Methods included from ParserMethods
Constructor Details
This class inherits a constructor from Omnom::Source::Base
Class Method Details
.configure ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/omnom/source/twitter/search.rb', line 10 def self.configure if Omnom.config.twitter.present? && Omnom.config.twitter.base.present? ::Twitter.configure do |configure| configure.consumer_key = Omnom.config.twitter.base.consumer_key configure.consumer_secret = Omnom.config.twitter.base.consumer_secret configure.oauth_token = Omnom.config.twitter.base.oauth_token configure.oauth_token_secret = Omnom.config.twitter.base.oauth_token_secret end end end |
Instance Method Details
#get_raw_posts ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/omnom/source/twitter/search.rb', line 21 def get_raw_posts = { count: 100, result_type: 'recent' } .reverse_merge!(@options[:search_options]) if @options[:search_options] ::Twitter.search(@options[:term], ).results end |
#post_attributes(tweet) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/omnom/source/twitter/search.rb', line 30 def post_attributes(tweet) username = tweet.from_user media = nil if tweet.media.present? media = {} tweet.media.each do |medium| type = medium.class.name.demodulize media[type] ||= [] media[type] << medium.attrs end end geo = nil if tweet.geo geo = { lat: tweet.geo.lat, lng: tweet.geo.lng } end if tweet.source =~ /<a[^>]*>(.*?)<\/a>/ source = $1 else source = tweet.source end { title: "@#{username}: #{tweet.text}", guid: tweet.id.to_s, url: "https://twitter.com/#{username}/status/#{tweet.id}", published_at: tweet.created_at, author_name: username, author_url: "https://twitter.com/#{username}", other: { geo: geo, media: media, source: source, to_user: tweet.to_user } } end |