Class: LyreBird::Response
- Inherits:
-
Object
- Object
- LyreBird::Response
- Defined in:
- lib/lyre_bird/response.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#request_tweet ⇒ Object
Returns the value of attribute request_tweet.
-
#text ⇒ Object
Returns the value of attribute text.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #post(live = false) ⇒ Object
- #register_response(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lyre_bird/response.rb', line 9 def initialize(={}) self.params = [:params] self.to = [:to] self.request_tweet = [:request_tweet] if self.params.nil? error return end history = $responses[self.to] klass = self.params['class'] || $lyrebird_default_class method = self.params['method'] || $lyrebird_default_method klass_obj = eval '::' + klass + '.new' self.text = klass_obj.send method.to_sym, self, history, self.params end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/lyre_bird/response.rb', line 6 def params @params end |
#request_tweet ⇒ Object
Returns the value of attribute request_tweet.
7 8 9 |
# File 'lib/lyre_bird/response.rb', line 7 def request_tweet @request_tweet end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/lyre_bird/response.rb', line 5 def text @text end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/lyre_bird/response.rb', line 4 def to @to end |
Instance Method Details
#error ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lyre_bird/response.rb', line 34 def error $no_responses.push(self.request_tweet) msg = "Don't know what you're asking for" self.text = msg if $lyre_debug puts "-" * 50 puts puts "From @#{self.request_tweet['user']['screen_name']} - \"#{self.request_tweet['text']}\"" puts puts "POSTING Don't get it - \"#{msg}\"" puts puts "-" * 50 end end |
#post(live = false) ⇒ Object
49 50 51 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 |
# File 'lib/lyre_bird/response.rb', line 49 def post(live=false) history = $responses[self.to] msg = self.text puts puts "-" * 50 puts puts "From @#{self.request_tweet['user']['screen_name']} - \"#{self.request_tweet['text']}\"" puts puts "Reply - \"@#{self.request_tweet['user']['screen_name']} #{msg}\"" puts puts "-" * 50 puts if $lyre_debug puts puts "Params - #{self.params.inspect}" puts puts "History - #{history.inspect}" puts puts "-" * 50 end if live $twitter.post("@#{self.request_tweet['user']['screen_name']} #{msg}") end end |
#register_response(params) ⇒ Object
29 30 31 32 |
# File 'lib/lyre_bird/response.rb', line 29 def register_response(params) $responses[self.to] = {} if $responses[self.to].nil? $responses[self.to] = $responses[self.to].merge(params) end |