Class: Wuclan::Twitter::Scrape::Base
- Inherits:
-
Object
- Object
- Wuclan::Twitter::Scrape::Base
- Includes:
- Monkeyshines::RawJsonContents, Monkeyshines::ScrapeRequest::Paginated, Monkeyshines::ScrapeRequestCore, Model
- Defined in:
- lib/wuclan/twitter/scrape/base.rb
Overview
Base class for twitter API requests
Direct Known Subclasses
TimelineRequest, TwitterFavoritesRequest, TwitterFollowersIdsRequest, TwitterFollowersRequest, TwitterFriendsIdsRequest, TwitterFriendsRequest
Constant Summary collapse
- BAD_CHARS =
Characters to scrub from contents. !! FIXME !! – destructive.
{ "\r" => " ", "\n" => " ", "\t" => "	" }
Instance Method Summary collapse
- #healthy? ⇒ Boolean
- #key ⇒ Object
-
#make_url ⇒ Object
Generate request URL from other attributes.
-
#num_items ⇒ Object
Number of items.
-
#request_for_page(page, pageinfo = nil) ⇒ Object
creates the paginated request.
-
#response=(response) ⇒ Object
Set the contents from the fetch payload.
-
#set_total_items(from_result) ⇒ Object
if from_result has something to say about the max_total_items, fix the value appropriately.
Instance Method Details
#healthy? ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 32 def healthy? (! url.blank) && ( # has a URL and either: scraped_at.blank? || # hasn't been scraped, (! response_code.blank?) || # or has, with response code (! contents.blank?) ) # or has, with response end |
#key ⇒ Object
45 46 47 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 45 def key [twitter_user_id, page||1].join('-') end |
#make_url ⇒ Object
Generate request URL from other attributes
40 41 42 43 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 40 def make_url # This works for most of the twitter calls "http://twitter.com/#{resource_path}/#{twitter_user_id}.json?page=#{page||1}" end |
#num_items ⇒ Object
Number of items
69 70 71 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 69 def num_items parsed_contents.length rescue 0 end |
#request_for_page(page, pageinfo = nil) ⇒ Object
creates the paginated request
64 65 66 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 64 def request_for_page page, pageinfo=nil (page.to_i > 1) ? self.class.new(twitter_user_id, page) : self end |
#response=(response) ⇒ Object
Set the contents from the fetch payload
55 56 57 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 55 def response= response self.contents = response.body.gsub(/[\r\n\t]/){|c| BAD_CHARS[c]} end |
#set_total_items(from_result) ⇒ Object
if from_result has something to say about the max_total_items, fix the value appropriately. (For example, a twitter_user’s :statuses_count sets the max_total_items for a TwitterUserTimelineRequest)
76 77 |
# File 'lib/wuclan/twitter/scrape/base.rb', line 76 def set_total_items from_result end |