Class: Strawman::TwitterSource
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/strawman/source.rb
Overview
A source that parses a twitter feed for urls which points to proxies, like twitter.com/proxy_lists. The class is deferable itself and fires its callback once the feed has been fetched and parsed.
By default it caches the feed to disk (cache/twitter-username.json), and fetches a new copy after that file is an hour old. To disable this, simply pass in false to the constructor.
Constant Summary collapse
- ONE_HOUR =
60*60
Instance Attribute Summary collapse
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
Instance Method Summary collapse
-
#initialize(twitter_username, cache = true) ⇒ TwitterSource
constructor
- twitter_username
-
Just the twitter user’s username.
Constructor Details
#initialize(twitter_username, cache = true) ⇒ TwitterSource
- twitter_username
-
Just the twitter user’s username. Not the full url.
- cache
-
Whether to enable or disable caching. Defaults to enabling caching.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/strawman/source.rb', line 25 def initialize(twitter_username, cache=true) @id = twitter_username @cache = cache if cache fetched = update_cache else fetched = fetch end fetched.callback do if @cache data = read_cache else data = fetched.response end @proxies = parse(data) succeed end end |
Instance Attribute Details
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
17 18 19 |
# File 'lib/strawman/source.rb', line 17 def proxies @proxies end |