Class: Clitwitter::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/clitwitter/twit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTwitter

Returns a new instance of Twitter.



10
11
12
13
14
15
16
17
18
19
# File 'lib/clitwitter/twit.rb', line 10

def initialize
  @tw = Pit.get("twitter.com")

  if ENV.include?('HTTP_PROXY')
    host,port= ENV['HTTP_PROXY'].sub(/^http:\/\//,"").split /:/
    ::Twitter::HTTPAuth.http_proxy( host, port)
  end

  authorize
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/clitwitter/twit.rb', line 8

def message
  @message
end

Instance Method Details

#close_friendsObject



59
60
61
62
63
64
65
# File 'lib/clitwitter/twit.rb', line 59

def close_friends
  if @tw["close_friends"]
    @tw["close_friends"]
  else
    {}
  end
end

#friends_timeline(query = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/clitwitter/twit.rb', line 37

def friends_timeline(query={})
  query[:since_id] = @last_id if @last_id

  begin
    result = @twitter.friends_timeline(query).reverse
  rescue ::Twitter::Unavailable
    warn "Twitter Service Unavailable #{Time.now}"
    result = []
  rescue ::Timeout::Error
    warn "Twitter Timeout #{Time.now}"
    result = []
  rescue ::Twitter::Unauthorized
    reenterAuth
    authorize
    retry
  end

  @last_id = result.last.id unless result.empty?

  result
end

#post(message) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/clitwitter/twit.rb', line 21

def post message
  begin
    @twitter.update(message)
  rescue ::Twitter::Unavailable
    warn "Twitter Service Unavailable #{Time.now}"
    retry
  rescue ::Timeout::Error
    warn "Twitter Timeout #{Time.now}"
    retry
  rescue ::Twitter::Unauthorized
    reenterAuth
    authorize
    retry
  end
end