Class: Powncer::Note
- Inherits:
-
Base
- Object
- Base
- Powncer::Note
show all
- Defined in:
- lib/powncer/note.rb
Constant Summary
Constants inherited
from Base
Base::FORMAT
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
extract_options, #id, instantiate, parse, #post, post, request, #request
Constructor Details
#initialize(options = {}) ⇒ Note
Returns a new instance of Note.
5
6
7
8
9
|
# File 'lib/powncer/note.rb', line 5
def initialize(options = {})
@attributes ||= {}
@attributes["body"] = options[:body] if options[:body]
@attributes["to"] = options[:to] || default_send_to
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Powncer::Base
Class Method Details
.create(attributes) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/powncer/note.rb', line 54
def create(attributes)
attributes.symbolize_keys!
note = self.new(attributes)
unless note.to.is_a?(Symbol)
target_key = ensure_send_to(:friend, note.to)
end
url = "/send/message.#{self.superclass::FORMAT}"
Note.instantiate post(url, {:body => note.body, :to => target_key || note.to})
end
|
.ensure_send_to(type, target) ⇒ Object
64
65
66
67
|
# File 'lib/powncer/note.rb', line 64
def ensure_send_to(type, target)
ensure_send_to_friends(target) if type.to_s == "friend"
end
|
.find(*args) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/powncer/note.rb', line 44
def find(*args)
options = (args)
case args.first
when :public
find_all_public(options)
else
find_by_id(args.first, options)
end
end
|
Instance Method Details
#is_public? ⇒ Boolean
28
29
30
|
# File 'lib/powncer/note.rb', line 28
def is_public?
self.is_public
end
|
#link ⇒ Object
24
25
26
|
# File 'lib/powncer/note.rb', line 24
def link
@attributes["url"] || @attributes["link"]["url"]
end
|
#recipients ⇒ Object
15
16
17
18
|
# File 'lib/powncer/note.rb', line 15
def recipients
url = "/notes/#{self.id}/recipients.#{FORMAT}"
request(url)["recipients"]["users"].collect!{|user| User.instantiate(user)}
end
|
#save ⇒ Object
11
12
13
|
# File 'lib/powncer/note.rb', line 11
def save
self.class.create(@attributes)
end
|
#sender ⇒ Object
32
33
34
|
# File 'lib/powncer/note.rb', line 32
def sender
User.instantiate(@attributes["sender"])
end
|
#type ⇒ Object
20
21
22
|
# File 'lib/powncer/note.rb', line 20
def type
@attributes["type"] || nil
end
|