lib/socialcastr/message.rb in socialcastr-0.0.1 vs lib/socialcastr/message.rb in socialcastr-0.1.0
- old
+ new
@@ -1,52 +1,86 @@
module Socialcastr
class Message < Base
+ id_element :id
element :title
element :body
element :url
element :permalink_url
element :action
element :external_url
element :icon
- element :id
element :likable
element :created_at
element :updated_at
element :last_interacted_at
element :player_url
element :thumbnail_url
element :player_params
element :user, :class => Socialcastr::User
- element :group, :class => Socialcastr::Group
- element :groups, :as => :group_list, :class => Socialcastr::GroupList
+ #element :group, :class => Socialcastr::Group
+ elements :group, :as => :groups, :class => Socialcastr::Group
element :source, :class => Socialcastr::Source
element :editable
element :rating
element :category_id
element :subscribed
# element :ratings_average
- element :flag
+ element :flag, :class => Socialcastr::Flag
element :deletable
element :comments_count
element :verb
element :in_reply_to
element :watchable
element :contains_url_only
# element :target_user
element :ratable
element :message_type
- element :recipients, :as => :recipient_list, :class => Socialcastr::RecipientList
+ elements :recipient, :as => :recipients, :class => Socialcastr::Recipient
- element :attachments, :as => :attachment_list, :class => Socialcastr::AttachmentList
- element :tags, :as => :tag_list, :class => Socialcastr::TagList
- element :likes, :as => :like_list, :class => Socialcastr::LikeList
- element :external_resources, :as => :external_resource_list, :class => Socialcastr::ExternalResourceList
- element :media_files, :as => :media_file_list, :class => Socialcastr::MediaFileList
+ elements :attachment, :as => :attachments, :class => Socialcastr::Attachment
+ elements :tag, :as => :tags, :class => Socialcastr::Tag
+ elements :like, :as => :likes, :class => Socialcastr::Like
+ elements :external_resource, :as => :external_resources, :class => Socialcastr::ExternalResource
+ elements :media_files, :as => :media_file, :class => Socialcastr::MediaFile
element :likes_count
element :hidden
- element :comments, :as => :comment_list, :class => Socialcastr::CommentList
+ elements :comment, :as => :comments, :class => Socialcastr::Comment
+ def flag!
+ return true if flagged?
+ flag.copy_attributes_from_object(Flag.parse(api.post(element_path + "/flags")))
+ end
+
+ def flagged?
+ !flag.id.nil?
+ end
+
+ def unflag!
+ return unless flagged?
+ api.delete(element_path + "/flags/#{flag.id}")
+ @flag = Flag.new
+ end
+
+ def like!
+ likes << Like.parse(api.post(element_path + "/likes"))
+ end
+
+ def unlike!
+ likes.reject! do |l|
+ l.unlikable && api.delete(element_path + "/likes/#{l.id}")
+ end
+ end
+
+ def comment!(arguments={})
+ comment = Socialcastr::Comment.new(arguments)
+ api.post(element_path + "/comments", comment.to_params)
+ end
+
+
+ def self.search(arguments={})
+ parse_collection(api.get(collection_path + "/search", arguments))
+ end
end
end