class TimeTree::Event

Model for TimeTree event or keep.

Constants

RELATIONSHIPS
TIME_FIELDS

Attributes

all_day[RW]

@return [Boolean]

attendees[RW]

@return [Array<TimeTree::User>]

calendar_id[RW]

calendar's id. @return [String]

category[RW]

@return [Striing]

created_at[RW]

@return [Time]

creator[R]

@return [TimeTree::User]

description[RW]

@return [String]

end_at[RW]

@return [Time]

end_timezone[RW]

@return [String]

label[RW]

@return [TimeTree::Label]

location[RW]

@return [String]

recurrence[RW]

@return [Array<String>]

recurring_uuid[RW]

@return [String]

start_at[RW]

@return [Time]

start_timezone[RW]

@return [Striing]

title[RW]

@return [Striing]

updated_at[RW]

@return [Time]

url[RW]

@return [String]

Public Instance Methods

create() click to toggle source

Creates an event to the associated calendar.

@return [TimeTree::Event] @raise [TimeTree::Error] if @client or @calendar_id is empty. @raise [TimeTree::ApiError] if the http response status will not success. @since 0.0.1

# File lib/timetree/models/event.rb, line 57
def create
  check_client
  _create_event
end
create_comment(message) click to toggle source

Creates comment to the event.

@return [TimeTree::Activity] @raise [TimeTree::Error] if @client, @calendar_id or @id is empty. @raise [TimeTree::ApiError] if the http response status will not success. @since 0.0.1

# File lib/timetree/models/event.rb, line 93
def create_comment(message)
  check_client
  params = {type: 'activity', attributes: {calendar_id: calendar_id, event_id: id, content: message}}
  activity = to_model params
  activity.create
end
data_params() click to toggle source

convert to a TimeTree request body format.

@return [Hash] @since 0.0.1

# File lib/timetree/models/event.rb, line 105
def data_params
  {
    data: {
      attributes: {
        category: category,
        title: title,
        all_day: all_day,
        start_at: start_at.iso8601,
        start_timezone: start_timezone,
        end_at: end_at.iso8601,
        end_timezone: end_timezone,
        description: description,
        location: location,
        url: url
      },
      relationships: relationships_params
    }
  }
end
delete() click to toggle source

Deletes the event.

@return [true] if the operation succeeded. @raise [TimeTree::Error] if @client, @calendar_id or @id is empty. @raise [TimeTree::ApiError] if the http response status will not success. @since 0.0.1

# File lib/timetree/models/event.rb, line 81
def delete
  check_client
  _delete_event
end
update() click to toggle source

Updates the event.

@return [TimeTree::Event] @raise [TimeTree::Error] if @client, @calendar_id or @id is empty. @raise [TimeTree::ApiError] if the http response status will not success. @since 0.0.1

# File lib/timetree/models/event.rb, line 69
def update
  check_client
  _update_event
end

Private Instance Methods

_create_event() click to toggle source
# File lib/timetree/models/event.rb, line 136
def _create_event
  if @client.is_a?(CalendarApp::Client)
    @client.create_event(data_params)
  else
    @client.create_event(calendar_id, data_params)
  end
end
_delete_event() click to toggle source
# File lib/timetree/models/event.rb, line 152
def _delete_event
  if @client.is_a?(CalendarApp::Client)
    @client.delete_event(id)
  else
    @client.delete_event(calendar_id, id)
  end
end
_update_event() click to toggle source
# File lib/timetree/models/event.rb, line 144
def _update_event
  if @client.is_a?(CalendarApp::Client)
    @client.update_event(id, data_params)
  else
    @client.update_event(calendar_id, id, data_params)
  end
end
relationships_params() click to toggle source
# File lib/timetree/models/event.rb, line 127
def relationships_params
  current_label = label ? {type: 'label', id: label.id} : relationships[:label]
  current_attendees = attendees ? attendees.map { |u| {type: 'user', id: u.id} } : relationships[:attendees]
  {
    label: {data: current_label},
    attendees: {data: current_attendees}
  }
end