Class: TwitterAutoPoster::User
- Inherits:
-
Object
- Object
- TwitterAutoPoster::User
- Defined in:
- lib/user.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#login ⇒ Object
Returns the value of attribute login.
-
#message_length ⇒ Object
Returns the value of attribute message_length.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#password ⇒ Object
Returns the value of attribute password.
-
#separator ⇒ Object
Returns the value of attribute separator.
Instance Method Summary collapse
-
#initialize(consumer_key, consumer_secret, access_token, access_token_secret, login, password, message_length = 100, separator = " ", delay = 5) ⇒ User
constructor
A new instance of User.
- #prepare_access_token(oauth_token, oauth_token_secret) ⇒ Object
- #prepare_messages(array) ⇒ Object
- #send_message(text) ⇒ Object
- #send_messages_from_file(file) ⇒ Object
Constructor Details
#initialize(consumer_key, consumer_secret, access_token, access_token_secret, login, password, message_length = 100, separator = " ", delay = 5) ⇒ User
Returns a new instance of User.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/user.rb', line 9 def initialize(consumer_key, consumer_secret, access_token, access_token_secret, login, password, =100, separator=" ", delay=5) @messages=Array.new @consumer_key=consumer_key @consumer_secret=consumer_secret @access_token=access_token @access_token_secret=access_token_secret @login=login @password=password @message_length= @separator=separator @delay=delay end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/user.rb', line 6 def access_token @access_token end |
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
6 7 8 |
# File 'lib/user.rb', line 6 def access_token_secret @access_token_secret end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
6 7 8 |
# File 'lib/user.rb', line 6 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
6 7 8 |
# File 'lib/user.rb', line 6 def consumer_secret @consumer_secret end |
#delay ⇒ Object
Returns the value of attribute delay.
6 7 8 |
# File 'lib/user.rb', line 6 def delay @delay end |
#login ⇒ Object
Returns the value of attribute login.
6 7 8 |
# File 'lib/user.rb', line 6 def login @login end |
#message_length ⇒ Object
Returns the value of attribute message_length.
6 7 8 |
# File 'lib/user.rb', line 6 def @message_length end |
#messages ⇒ Object
Returns the value of attribute messages.
6 7 8 |
# File 'lib/user.rb', line 6 def @messages end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/user.rb', line 6 def password @password end |
#separator ⇒ Object
Returns the value of attribute separator.
6 7 8 |
# File 'lib/user.rb', line 6 def separator @separator end |
Instance Method Details
#prepare_access_token(oauth_token, oauth_token_secret) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/user.rb', line 61 def prepare_access_token(oauth_token, oauth_token_secret) consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {:site => "http://api.twitter.com", :scheme => :header }) token_hash = {:oauth_token => @access_token, :oauth_token_secret => @access_token_secret } access_token = OAuth::AccessToken.from_hash(consumer, token_hash) end |
#prepare_messages(array) ⇒ Object
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 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/user.rb', line 25 def (array) sep_size=@separator.to_s.length if array.nil? else =0 ="" i=0 while i<array.size if + array[i].to_s.length<=@message_length +=array[i].to_s +=array[i].to_s.length if +sep_size<@message_length-1 and i!=array.size-1 and +sep_size+array[i+1].to_s.length<=@message_length +=@separator +=sep_size else @messages<< ="" =0 end i+=1 if i==array.size && !="" @messages<< end else if array[i].to_s.length>@message_length raise Exception.new("message length too small!!") end end end end end |
#send_message(text) ⇒ Object
73 74 75 76 77 |
# File 'lib/user.rb', line 73 def (text) access_token = prepare_access_token(@login, @password) response = access_token.request(:post, "http://api.twitter.com/1/statuses/update.json?status="+URI.escape(text)) response.code end |
#send_messages_from_file(file) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/user.rb', line 80 def (file) parser=Parser.new parser.parse_file(file) (parser.words) q=@messages.length thread= Thread.start do @messages.each do |m| (m.to_s) q-=1 puts "[#{file}]: Message \""+m.to_s+"\" was sent. #{q} messages left.\n" sleep @delay end puts "[#{file}]: All messages were sent.\n\n" thread.exit! end end |