Class: TimeTree::Event

Inherits:
BaseModel show all
Defined in:
lib/timetree/event.rb

Overview

Model for TimeTree event or keep.

Constant Summary collapse

TIME_FIELDS =
i[start_at end_at updated_at created_at].freeze
RELATIONSHIPS =
i[creator label attendees].freeze

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#id, #relationships, #type

Instance Method Summary collapse

Methods inherited from BaseModel

#initialize, #inspect, to_model

Constructor Details

This class inherits a constructor from TimeTree::BaseModel

Instance Attribute Details

#all_dayBoolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/timetree/event.rb', line 11

def all_day
  @all_day
end

#attendeesArray<TimeTree::User> (readonly)

Returns:



43
44
45
# File 'lib/timetree/event.rb', line 43

def attendees
  @attendees
end

#calendar_idString

calendar’s id.

Returns:

  • (String)


36
37
38
# File 'lib/timetree/event.rb', line 36

def calendar_id
  @calendar_id
end

#categoryStriing

Returns:

  • (Striing)


7
8
9
# File 'lib/timetree/event.rb', line 7

def category
  @category
end

#created_atTime

Returns:

  • (Time)


33
34
35
# File 'lib/timetree/event.rb', line 33

def created_at
  @created_at
end

#creatorTimeTree::User (readonly)

Returns:



39
40
41
# File 'lib/timetree/event.rb', line 39

def creator
  @creator
end

#descriptionString

Returns:

  • (String)


25
26
27
# File 'lib/timetree/event.rb', line 25

def description
  @description
end

#end_atTime

Returns:

  • (Time)


17
18
19
# File 'lib/timetree/event.rb', line 17

def end_at
  @end_at
end

#end_timezoneString

Returns:

  • (String)


19
20
21
# File 'lib/timetree/event.rb', line 19

def end_timezone
  @end_timezone
end

#labelTimeTree::Label (readonly)

Returns:



41
42
43
# File 'lib/timetree/event.rb', line 41

def label
  @label
end

#locationString

Returns:

  • (String)


27
28
29
# File 'lib/timetree/event.rb', line 27

def location
  @location
end

#recurrenceArray<String>

Returns:

  • (Array<String>)


21
22
23
# File 'lib/timetree/event.rb', line 21

def recurrence
  @recurrence
end

#recurring_uuidString

Returns:

  • (String)


23
24
25
# File 'lib/timetree/event.rb', line 23

def recurring_uuid
  @recurring_uuid
end

#start_atTime

Returns:

  • (Time)


13
14
15
# File 'lib/timetree/event.rb', line 13

def start_at
  @start_at
end

#start_timezoneStriing

Returns:

  • (Striing)


15
16
17
# File 'lib/timetree/event.rb', line 15

def start_timezone
  @start_timezone
end

#titleStriing

Returns:

  • (Striing)


9
10
11
# File 'lib/timetree/event.rb', line 9

def title
  @title
end

#updated_atTime

Returns:

  • (Time)


31
32
33
# File 'lib/timetree/event.rb', line 31

def updated_at
  @updated_at
end

#urlString

Returns:

  • (String)


29
30
31
# File 'lib/timetree/event.rb', line 29

def url
  @url
end

Instance Method Details

#createTimeTree::Event

Creates an event to the associated calendar.

Returns:

Raises:

Since:

  • 0.0.1



55
56
57
58
59
# File 'lib/timetree/event.rb', line 55

def create
  raise Error, 'client is required.' if @client.nil?

  @client.create_event calendar_id, data_params
end

#create_comment(message) ⇒ TimeTree::Activity

Creates comment to the event.

Returns:

Raises:

Since:

  • 0.0.1



68
69
70
71
72
73
74
75
76
# File 'lib/timetree/event.rb', line 68

def create_comment(message)
  raise Error, '@client is nil.' if @client.nil?

  params = { type: 'activity', attributes: { calendar_id: calendar_id, event_id: id, content: message } }
  activity = to_model params
  return if activity.nil?

  activity.create
end

#data_paramsHash

convert to a TimeTree request body format.

Returns:

  • (Hash)

Since:

  • 0.0.1



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/timetree/event.rb', line 113

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

#deletetrue

Deletes the event.

Returns:

  • (true)

    if the operation succeeded.

Raises:

Since:

  • 0.0.1



101
102
103
104
105
106
# File 'lib/timetree/event.rb', line 101

def delete
  raise Error, '@client is nil.' if @client.nil?
  raise Error, 'id is required.' if id.nil?

  @client.delete_event calendar_id, id
end

#updateTimeTree::Event

Updates the event.

Returns:

Raises:

Since:

  • 0.0.1



86
87
88
89
90
91
# File 'lib/timetree/event.rb', line 86

def update
  raise Error, '@client is nil.' if @client.nil?
  raise Error, 'id is required.' if id.nil?

  @client.update_event calendar_id, id, data_params
end