Class: Trumpet::Message

Inherits:
Object show all
Defined in:
lib/trumpet/message.rb

Constant Summary collapse

@@attributes =
[
  :url        , :created_by_id,
  :author     , :author_name,
  :avatar_url , :authored_at,
  :title      , :description,
  :tags       , :location_string,
  :lat        , :lng,
  :radius     , :channel,
  :public     , :authorized_receiver_owners,
  :content    , :id,
  :created_at , :updated_at
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Message

Returns a new instance of Message.



21
22
23
24
25
26
# File 'lib/trumpet/message.rb', line 21

def initialize(options)
  parameters = options[:parameters] ? options[:parameters] : options
  @@attributes.each do |attr|
    self.send "#{attr.to_s}=".to_sym, (parameters[attr] || parameters[attr.to_s])
  end
end

Class Method Details

.create(request, attributes) ⇒ Object



28
29
30
# File 'lib/trumpet/message.rb', line 28

def self.create(request, attributes)
  !!request.post('/messages', :parameters => self.to_h, :parse_response => false)
end

Instance Method Details

#to_hObject



32
33
34
# File 'lib/trumpet/message.rb', line 32

def to_h
  @@attributes.inject({}) { |hash, attribute| hash[attribute] = self.send(attribute); hash }
end