Class: Whisper

Inherits:
Object
  • Object
show all
Defined in:
lib/whisper/version.rb,
lib/whisper.rb

Overview

:nodoc:

Defined Under Namespace

Modules: VERSION Classes: Account, Message

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Whisper

Returns a new instance of Whisper.



10
11
12
13
14
15
16
17
# File 'lib/whisper.rb', line 10

def initialize(opts)
  %w(consumer_token consumer_secret access_token access_secret).each do |k|
    raise "parameter '#{k}' missed." unless opts.has_key?(k.to_sym)
  end
  
  @consumer = OAuth::Consumer.new opts[:consumer_token], opts[:consumer_secret], :site => 'http://whisper.playmaru.net'
  @access_token = OAuth::AccessToken.new @consumer, opts[:access_token], opts[:access_secret]
end

Instance Method Details

#get_messages(box = nil, params = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/whisper.rb', line 19

def get_messages(box = nil, params = {})
  url = '/messages'
  url += "/#{box}" if box
  url += "?#{parameters_for_get(params)}" if params.length > 0
  p url
  
  Message.parse_collection @access_token.get(url).body
end

#post_message(to, content) ⇒ Object



28
29
30
31
# File 'lib/whisper.rb', line 28

def post_message(to, content)
  body = "openid_to=#{CGI.escape(to)}&content=#{CGI.escape(content)}"
  @access_token.post('/messages', body).code.to_s == '200'
end