Class: Pork::Puller

Inherits:
Object
  • Object
show all
Defined in:
lib/pork_sandwich/puller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_object = nil) ⇒ Puller

Returns a new instance of Puller.



14
15
16
# File 'lib/pork_sandwich/puller.rb', line 14

def initialize(auth_object = nil)
  @auth_object = auth_object ? auth_object.auth : auth_object
end

Instance Attribute Details

#auth_objectObject

Returns the value of attribute auth_object.



3
4
5
# File 'lib/pork_sandwich/puller.rb', line 3

def auth_object
  @auth_object
end

Class Method Details

.rate_checkObject



5
6
7
8
9
10
11
12
# File 'lib/pork_sandwich/puller.rb', line 5

def self.rate_check
    rate_hash = JSON.parse(Net::HTTP.get(URI.parse("http://twitter.com/account/rate_limit_status.json")))
    if rate_hash["remaining_hits"] == 0
      $PORK_LOG.write("You've hit your rate limit, sleeping for 2 mins then checking the rate limit again. Should reset at #{rate_hash['reset_time']}") if $PORK_LOG
      sleep 120    
      Pork::Puller.rate_check    
    end
end

Instance Method Details

#pull(user_object, &pull_type) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pork_sandwich/puller.rb', line 18

def pull(user_object, &pull_type)
  Pork::Puller.rate_check
  @user = user_object
  begin
    pull_type.call(@user, @auth_object)
  rescue Errno::ECONNRESET   
    $PORK_LOG.write("ERROR: Connection reset by peer, probably because you tried to access an unauthorized page. Moving on.") if $PORK_LOG  
  rescue Twitter::Unavailable
    $PORK_LOG.write("ERROR: Twitter unavailable, trying in 60") if $PORK_LOG
    sleep 60
    retry
  rescue Twitter::NotFound
    $PORK_LOG.write("ERROR: Info target not found, trying to skip") if $PORK_LOG
  # rescue Twitter::Unauthorized 
  # rescue Crack::ParseError
  #   raise Crack::ParseError
  rescue Errno::ETIMEDOUT
    $PORK_LOG.write("ERROR: Puller timed out, retrying in 10") if $PORK_LOG
    sleep 10
    retry
  rescue Twitter::InformTwitter
    $PORK_LOG.write("ERROR: Twitter internal error, retrying in 30") if $PORK_LOG
    sleep 30
    retry
  rescue Timeout::Error
    if $PORK_LOG
      $PORK_LOG.write("ERROR: Request Timed out. Retrying in 30")
    end
    sleep 30 
    retry
  end
end