Class: Capistrano::Calendar::Client::Google
- Inherits:
-
Base
- Object
- Base
- Capistrano::Calendar::Client::Google
show all
- Defined in:
- lib/capistrano/calendar/client/google.rb
Constant Summary
collapse
- OWN_CALENDARS_URL =
"https://www.google.com/calendar/feeds/default/owncalendars/full"
- CALENDAR_EVENTS_URL =
"https://www.google.com/calendar/feeds/default/private/full"
Instance Attribute Summary
Attributes inherited from Base
#configuration
Instance Method Summary
collapse
Methods inherited from Base
#calendar_password, #calendar_username, #initialize
Instance Method Details
#authenticate ⇒ Object
19
20
21
|
# File 'lib/capistrano/calendar/client/google.rb', line 19
def authenticate
client.clientlogin(calendar_username, calendar_password)
end
|
#create_calendar(calendar_name) ⇒ Object
48
49
50
51
|
# File 'lib/capistrano/calendar/client/google.rb', line 48
def create_calendar(calendar_name)
response = client.post(OWN_CALENDARS_URL, json_calendar_entity)
JSON.parse(response.body)['data']
end
|
#create_event ⇒ Object
23
24
25
26
|
# File 'lib/capistrano/calendar/client/google.rb', line 23
def create_event
response = client.post(events_url, json_event_entity)
JSON.parse(response.body)['data']
end
|
#delete_calendar(calendar) ⇒ Object
53
54
55
56
57
|
# File 'lib/capistrano/calendar/client/google.rb', line 53
def delete_calendar(calendar)
calendar.is_a?(Hash) or calendar = find_calendar(calendar)
calendar or raise Capistrano::Error, "Calendar #{calendar.inspect} not found"
client.delete(calendar['selfLink'])
end
|
#events_url ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/capistrano/calendar/client/google.rb', line 28
def events_url
if configuration[:calendar_name]
calendar = find_or_create_calendar(configuration[:calendar_name])
calendar['eventFeedLink']
else
CALENDAR_EVENTS_URL
end
end
|
#find_calendar(calendar_name) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/capistrano/calendar/client/google.rb', line 41
def find_calendar(calendar_name)
response = client.get(OWN_CALENDARS_URL + '?alt=jsonc')
JSON.parse(response.body)['data']['items'].find { |item|
item['title'] == calendar_name
}
end
|
#find_or_create_calendar(calendar_name) ⇒ Object
37
38
39
|
# File 'lib/capistrano/calendar/client/google.rb', line 37
def find_or_create_calendar(calendar_name)
find_calendar(calendar_name) || create_calendar(calendar_name)
end
|