Class: TwitterFakeFetcher

Inherits:
Monkeyshines::Fetcher::FakeFetcher
  • Object
show all
Defined in:
lib/wuclan/twitter/scrape/twitter_fake_fetcher.rb

Overview

returns json for a hash / array as appropriate

Instance Method Summary collapse

Instance Method Details

#fake_contents(req) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wuclan/twitter/scrape/twitter_fake_fetcher.rb', line 7

def fake_contents req
  case req
  when TwitterFollowersIdsRequest, TwitterFriendsIdsRequest
    (1 .. rand(50)).map{ rand(1e6) }.to_json
  when TwitterUserRequest
    { :id => (req.twitter_user_id.to_i == 0 ? rand(1e6) : req.twitter_user_id),
      :created_at => Time.parse('08-08-2008 12:45'), :name => req.url, :protected => false,
      :followers_count => rand(2001), :friends_count => rand(401), :statuses_count => rand(120), :favourites_count => rand(50) }.to_json
  when TwitterFollowersRequest, TwitterFriendsRequest, TwitterFavoritesRequest
    (0..req.max_items).map{|i| { :fetched => req.url, :id => i } }.to_json
  else
    if (req[:page].to_i > 1) && (rand(8) == 0)
      [].to_json
    else
      (0..req.max_items).map{|i| { :fetched => req.url, :id => i } }.to_json
    end
  end
end

#get(req) ⇒ Object



26
27
28
29
30
# File 'lib/wuclan/twitter/scrape/twitter_fake_fetcher.rb', line 26

def get req
  super req
  req.contents = fake_contents(req)
  req
end