Class: Gaah::Calendar::Api
- Inherits:
-
Object
- Object
- Gaah::Calendar::Api
- Defined in:
- lib/gaah/calendar/api.rb
Class Method Summary collapse
-
.calendars(xoauth_requestor_id, options = {}) ⇒ Object
API: CalendarList: list.
-
.create_event(xoauth_requestor_id, options) ⇒ Object
API: Events#insert.
- .delete_event(xoauth_requestor_id, options) ⇒ Object
-
.event(xoauth_requestor_id, options) ⇒ Object
API: Events#get.
-
.events(xoauth_requestor_id, options) ⇒ Object
API: Events#list.
Class Method Details
.calendars(xoauth_requestor_id, options = {}) ⇒ Object
API: CalendarList: list
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gaah/calendar/api.rb', line 11 def calendars(xoauth_requestor_id, = {}) url = "https://www.googleapis.com/calendar/v3/users/me/calendarList" params = { xoauth_requestor_id: xoauth_requestor_id, minAccessRole: [:min_access_role] || 'writer', showHidden: [:show_hidden] || false, } calendars = JSON.load(ApiClient.instance.get(url, params)) Calendar.batch_create(calendars['items']) end |
.create_event(xoauth_requestor_id, options) ⇒ Object
API: Events#insert
32 33 34 35 36 37 38 39 |
# File 'lib/gaah/calendar/api.rb', line 32 def create_event(xoauth_requestor_id, ) url = build_api_url(.delete(:email)) params = { xoauth_requestor_id: xoauth_requestor_id } body = build_create_api_body() json = ApiClient.instance.post(url, params, body) Gaah::Calendar::Event.new(JSON.load(json)) end |
.delete_event(xoauth_requestor_id, options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gaah/calendar/api.rb', line 52 def delete_event(xoauth_requestor_id, ) base = build_api_url(.delete(:email)) id = .delete(:event_id) url = "#{base}/#{id}" params = { xoauth_requestor_id: xoauth_requestor_id } ApiClient.instance.delete(url, params) { success: true } rescue Gaah::UnknownHTTPException => exception case exception. when '404' { success: false, error: "Event was not found." } when '410' { success: false, error: "Event is already canceled." } end end |
.event(xoauth_requestor_id, options) ⇒ Object
API: Events#get
42 43 44 45 46 47 48 49 50 |
# File 'lib/gaah/calendar/api.rb', line 42 def event(xoauth_requestor_id, ) base = build_api_url(.delete(:email)) id = .delete(:event_id) url = "#{base}/#{id}" params = { xoauth_requestor_id: xoauth_requestor_id } json = ApiClient.instance.get(url, params) Gaah::Calendar::Event.new(JSON.load(json)) end |
.events(xoauth_requestor_id, options) ⇒ Object
API: Events#list
23 24 25 26 27 28 29 |
# File 'lib/gaah/calendar/api.rb', line 23 def events(xoauth_requestor_id, ) url = build_api_url([:email]) params = build_events_api_params(xoauth_requestor_id, ) json = ApiClient.instance.get(url, params) events = JSON.load(json) Event.batch_create(events['items']) end |