class Shortdiary::Post

Attributes

api[RW]
date[RW]
id[RW]
location_lat[RW]
location_lon[RW]
location_verbose[RW]
mood[RW]
public[RW]
public_text[RW]
text[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/shortdiary.rb, line 38
def initialize(*args)
        # Should probably use a hash here
        @api = args[0]
end

Public Instance Methods

attrs() click to toggle source
# File lib/shortdiary.rb, line 43
def attrs
        instance_variables.map{|ivar| instance_variable_get ivar}
end
for_today?() click to toggle source
# File lib/shortdiary.rb, line 52
def for_today?
        @date == Date.today
end
save() click to toggle source
# File lib/shortdiary.rb, line 56
def save
        if not @text or not @date or not @mood
                raise MissingDataError
        end

        post_data = {
                :date => @date.to_s,
                :text => @text,
                :mood => @mood,
        }

        if @id
                new_post = @api.send_request("posts/#{@id}/", 'PUT', post_data)
        else
                new_post = @api.send_request("posts/", 'POST', post_data)
                @id = new_post['id']
        end
end
to_s() click to toggle source
# File lib/shortdiary.rb, line 47
def to_s
        return @text if @text.is_a?(String)
        ''
end