Class: Zm::Client::AppointmentJsnsInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/appointment/appointment_jsns_initializer.rb

Overview

class for account appointment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, json) ⇒ AppointmentJsnsInitializer

Returns a new instance of AppointmentJsnsInitializer.



9
10
11
12
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 9

def initialize(parent, json)
  @parent = parent
  @json = json
end

Instance Attribute Details

#appointmentObject

Returns the value of attribute appointment.



7
8
9
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 7

def appointment
  @appointment
end

Instance Method Details

#attendeesObject



127
128
129
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 127

def attendees
  @attendees ||= comp[:at] || []
end

#compObject



109
110
111
112
113
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 109

def comp
  raise Zm::Client::ZmError, 'invalid appointment received' if inv[:comp].nil?

  @comp ||= inv[:comp].first
end

#comp_end_hObject



101
102
103
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 101

def comp_end_h
  @comp_end_h ||= comp[:e].first
end

#comp_make_dateObject



87
88
89
90
91
92
93
94
95
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 87

def comp_make_date
  if comp_start_h[:u].nil?
    @appointment.start_at = Time.parse(comp_start_h[:d])
    @appointment.end_at = Time.parse(comp_end_h[:d])
  else
    @appointment.start_at = Time.at(comp_start_h[:u] / 1000)
    @appointment.end_at = Time.at(comp_end_h[:u] / 1000)
  end
end

#comp_organizer_nameObject



115
116
117
118
119
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 115

def comp_organizer_name
  return nil if comp[:or].nil?

  @comp_organizer_name ||= comp[:or][:a]
end

#comp_start_hObject



97
98
99
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 97

def comp_start_h
  @comp_start_h ||= comp[:s].first
end

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 26

def create
  @appointment ||= Appointment.new(@parent)

  @appointment.id = @json[:id]
  @appointment.tn = @json[:tn]
  @appointment.l = @json[:l].to_i
  @appointment.uid = @json[:uid]

  if inv.nil?
    init_from_search
  else
    init_from_inv
  end

  @appointment
end

#init_from_invObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 58

def init_from_inv
  @appointment.uid = comp[:uid]
  @appointment.fb = comp[:fb]
  @appointment.transp = comp[:transp]
  @appointment.timezone = tz[:id]
  @appointment.name = comp[:name]
  @appointment.desc = comp[:desc].first[:_content] unless comp[:desc].nil?
  @appointment.apptId = comp[:apptId]
  @appointment.allDay = comp[:allDay] unless comp[:allDay].nil?

  unless comp_organizer_name.nil?
    @appointment.organizer = Zm::Client::Appointment::Organizer.new(comp_organizer_name)
  end

  attendees.each do |attendee|
    @appointment.attendees.add(Zm::Client::Appointment::Attendee.new(attendee[:a]))
  end

  comp_make_date
end

#init_from_searchObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 47

def init_from_search
  unless search_organizer_name.nil?
    @appointment.organizer = Zm::Client::Appointment::Organizer.new(search_organizer_name)
  end
  @appointment.name = @json[:name]
  @appointment.id = @json[:invId]
  @appointment.desc = @json[:fr]
  @appointment.allDay = @json[:allDay] unless @json[:allDay].nil?
  search_make_date
end

#invObject



43
44
45
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 43

def inv
  @inv ||= @json[:inv]&.first
end

#search_make_dateObject



79
80
81
82
83
84
85
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 79

def search_make_date
  return if @json[:inst].nil? || @json[:inst].first.empty? || @json[:dur].nil?

  @appointment.start_at = Time.at(@json[:inst].first[:s] / 1000)
  @appointment.end_at = Time.at((@json[:inst].first[:s] + @json[:dur]) / 1000)
  @appointment.dur = @json[:dur] / 1000
end

#search_organizer_nameObject



121
122
123
124
125
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 121

def search_organizer_name
  return nil if @json[:or].nil?

  @search_organizer_name ||= @json[:or][:a]
end

#tzObject



105
106
107
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 105

def tz
  @tz ||= inv[:tz]&.first || { id: 'Europe/Berlin' }
end

#updateObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zm/client/appointment/appointment_jsns_initializer.rb', line 14

def update
  return false if @appointment.nil?

  @appointment.calItemId = @json[:calItemId]
  @appointment.apptId = @json[:apptId]
  @appointment.invId = @json[:invId]
  @appointment.id = @json[:invId]
  @appointment.rev = @json[:rev]

  true
end