Class: ImKayac::Message
- Inherits:
-
Object
- Object
- ImKayac::Message
- Defined in:
- lib/im-kayac/message.rb
Instance Method Summary collapse
- #handler(handler) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #password(str) ⇒ Object
- #post(message) ⇒ Object
- #secret(str) ⇒ Object
- #to(name) ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
5 6 7 8 9 10 |
# File 'lib/im-kayac/message.rb', line 5 def initialize @to = nil @secret = nil @password = nil @handler = nil end |
Instance Method Details
#handler(handler) ⇒ Object
27 28 29 30 |
# File 'lib/im-kayac/message.rb', line 27 def handler(handler) @handler = handler return self end |
#password(str) ⇒ Object
22 23 24 25 |
# File 'lib/im-kayac/message.rb', line 22 def password(str) @password = str return self end |
#post(message) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/im-kayac/message.rb', line 32 def post() params = {:message => } params[:sig] = Digest::SHA1.hexdigest "#{}#{@secret}" if @secret params[:password] = @password if @password params[:handler] = @handler if @handler res = HTTParty.post "http://im.kayac.com/api/post/#{@to}", :body => params raise Error.new "response error (#{res.code})" unless res.code == 200 data = JSON.parse res.body unless data['result'].to_s == 'posted' and res['error'].to_s == '' raise Error.new(data['error'] || 'unknown error') end data end |
#secret(str) ⇒ Object
17 18 19 20 |
# File 'lib/im-kayac/message.rb', line 17 def secret(str) @secret = str return self end |
#to(name) ⇒ Object
12 13 14 15 |
# File 'lib/im-kayac/message.rb', line 12 def to(name) @to = name return self end |