Class: Pft::Base
- Inherits:
-
Object
- Object
- Pft::Base
- Defined in:
- lib/pft/base.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#message ⇒ Object
Returns the value of attribute message.
-
#oauth ⇒ Object
Returns the value of attribute oauth.
Class Method Summary collapse
- .input ⇒ Object
- .options(file = nil) ⇒ Object
- .tweet(*options) ⇒ Object
- .version ⇒ Object
- .write_options ⇒ Object
Instance Method Summary collapse
- #direct_message(user, message) ⇒ Object
- #get_user(user) ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #message_for(type, user = nil) ⇒ Object
- #parse_urls(message) ⇒ Object
- #reply_to(user, message) ⇒ Object
- #retweet(user) ⇒ Object
Constructor Details
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/pft/base.rb', line 3 def configuration @configuration end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/pft/base.rb', line 3 def @message end |
#oauth ⇒ Object
Returns the value of attribute oauth.
3 4 5 |
# File 'lib/pft/base.rb', line 3 def oauth @oauth end |
Class Method Details
.input ⇒ Object
102 103 104 |
# File 'lib/pft/base.rb', line 102 def self.input @@input ||= IO.new(2,"r") end |
.options(file = nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/pft/base.rb', line 85 def self.(file=nil) @@options ||= begin @@file = File.(file || "~/.pftrc") configuration = [] File.open(@@file).each do |line| configuration << [$1.to_sym, $2.chomp] if line =~ /(\w+)=(.+)/ end rescue nil Hash[*configuration.flatten] end end |
.tweet(*options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pft/base.rb', line 52 def self.tweet(*) base = self.new = .pop || [] = base.parse_urls(.join(" ")) = .pop || {} if [:authorize] base.oauth. elsif [:reply] puts base.reply_to([:reply], ) elsif [:rt] puts base.retweet([:rt]) elsif [:dm] puts base.([:dm], ) elsif .size > 0 base.oauth.client.update() puts base.('tweet') else raise "Please provide a message" # class HighLine # public :get_character # end # input = HighLine.new # while (c = input.get_character) != ?\e do # puts "You typed #{c.chr.inspect}" # end end end |
.version ⇒ Object
81 82 83 |
# File 'lib/pft/base.rb', line 81 def self.version "0.1" end |
.write_options ⇒ Object
96 97 98 99 100 |
# File 'lib/pft/base.rb', line 96 def self. File.open(@@file, "w") do |f| .each { |key, value| f.puts "#{key}=#{value}" } end end |
Instance Method Details
#direct_message(user, message) ⇒ Object
22 23 24 25 26 |
# File 'lib/pft/base.rb', line 22 def (user, ) user = get_user(user).screen_name @oauth.client.(user, ) ('direct message', user) end |
#get_user(user) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/pft/base.rb', line 28 def get_user(user) user = @oauth.client.user(user) rescue false if !user || !user.status raise "User or last tweet not found" end user end |
#message_for(type, user = nil) ⇒ Object
48 49 50 |
# File 'lib/pft/base.rb', line 48 def (type, user = nil) "pft! successfully sent a #{type}#{" to #{user}" if user}" end |
#parse_urls(message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pft/base.rb', line 36 def parse_urls() return unless .=~(/(?:http:\/\/|ftp:\/\/|https:\/\/|www\.|ftp\.[\w]+)(?:[\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])/) = "" .each(" ") do |word| if word.=~(/(?:http:\/\/|ftp:\/\/|https:\/\/|www\.|ftp\.[\w]+)(?:[\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])/) word = "#{TinyUrl.compact(word.delete(' '))} " end << word end end |
#reply_to(user, message) ⇒ Object
10 11 12 13 14 |
# File 'lib/pft/base.rb', line 10 def reply_to(user, ) user = get_user(user) @oauth.client.update("@#{user.screen_name} #{}", :in_reply_to_status_id => user.status.id) ('reply', user) end |
#retweet(user) ⇒ Object
16 17 18 19 20 |
# File 'lib/pft/base.rb', line 16 def retweet(user) user = get_user(user) @oauth.client.update("RT @#{user.screen_name} #{user.status.text}") ('retweet', user) end |