Class: Ragoon::Services::Schedule
Constant Summary
SERVICE_LOCATIONS
Instance Attribute Summary
#action_type, #client
Instance Method Summary
collapse
#endpoint, #initialize
Instance Method Details
#default_options(action_name) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/ragoon/services/schedule.rb', line 47
def default_options(action_name)
case action_name
when 'ScheduleGetEvents'
today = Date.today
{
start: Time.local(today.year, today.month, today.day, 0).utc,
end: Time.local(today.year, today.month, today.day + 1, 0).utc,
}
else
{}
end
end
|
#facility_names(event) ⇒ Object
27
28
29
30
31
|
# File 'lib/ragoon/services/schedule.rb', line 27
def facility_names(event)
event.xpath('ev:members', ev: "http://schemas.cybozu.co.jp/schedule/2008").
children.map { |c| c.xpath('ev:facility', ev: "http://schemas.cybozu.co.jp/schedule/2008").first }.
compact.map { |n| n[:name] }
end
|
#schedule_get_events(options = {}) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/ragoon/services/schedule.rb', line 2
def schedule_get_events(options = {})
action_name = 'ScheduleGetEvents'
options = default_options(action_name).merge(options)
body_node = Ragoon::XML.create_node(action_name)
parameter_node = Ragoon::XML.create_node(
'parameters',
start: options[:start].strftime('%FT%T'),
end: options[:end].strftime('%FT%T')
)
body_node.add_child(parameter_node)
client.request(action_name, body_node)
events = client.result_set.xpath('//schedule_event').find_all { |ev| ev[:event_type] == 'normal' }.map do |event|
public_event = event[:public_type] == 'public'
{
title: public_event ? event[:detail] : '予定あり',
period: start_and_end(event),
facility: public_event ? facility_names(event) : '',
}
end
end
|
#start_and_end(event) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ragoon/services/schedule.rb', line 33
def start_and_end(event)
if event[:allday] == 'true'
'終日'
else
period = event.children.xpath('ev:datetime', ev: "http://schemas.cybozu.co.jp/schedule/2008").first
return 'error' if period.nil?
start_time = Time.parse(period[:start]).localtime.strftime('%R')
end_time = event[:start_only] == 'true' ? '' : Time.parse(period[:end]).localtime.strftime('%R')
"#{start_time}〜#{end_time}"
end
end
|