Class: Calendav::Clients::EventsClient
- Inherits:
-
Object
- Object
- Calendav::Clients::EventsClient
- Defined in:
- lib/calendav/clients/events_client.rb
Instance Method Summary collapse
- #create(calendar_url, event_identifier, ics) ⇒ Object
- #delete(event_url, etag: nil) ⇒ Object
- #find(event_url) ⇒ Object
-
#initialize(client, endpoint, credentials) ⇒ EventsClient
constructor
A new instance of EventsClient.
- #list(calendar_url, from: nil, to: nil) ⇒ Object
- #update(event_url, ics, etag: nil) ⇒ Object
Constructor Details
#initialize(client, endpoint, credentials) ⇒ EventsClient
Returns a new instance of EventsClient.
10 11 12 13 14 |
# File 'lib/calendav/clients/events_client.rb', line 10 def initialize(client, endpoint, credentials) @client = client @endpoint = endpoint @credentials = credentials end |
Instance Method Details
#create(calendar_url, event_identifier, ics) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/calendav/clients/events_client.rb', line 16 def create(calendar_url, event_identifier, ics) event_url = merged_url(calendar_url, event_identifier) result = endpoint.put(ics, url: event_url, content_type: :ics) Event.new( url: result.headers["Location"] || event_url, etag: result.headers["ETag"] ) end |
#delete(event_url, etag: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/calendav/clients/events_client.rb', line 26 def delete(event_url, etag: nil) endpoint.delete(url: event_url, etag: etag) rescue PreconditionError false end |
#find(event_url) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/calendav/clients/events_client.rb', line 32 def find(event_url) response = endpoint.get(url: event_url) Event.new( url: event_url, calendar_data: response.body.to_s, etag: response.headers["ETag"] ) end |
#list(calendar_url, from: nil, to: nil) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/calendav/clients/events_client.rb', line 42 def list(calendar_url, from: nil, to: nil) request = Requests::ListEvents.call(from: from, to: to) endpoint .report(request.to_xml, url: calendar_url, depth: 1) .reject { |node| node.xpath(".//caldav:calendar-data").text.empty? } .collect { |node| Event.from_xml(calendar_url, node) } end |
#update(event_url, ics, etag: nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/calendav/clients/events_client.rb', line 51 def update(event_url, ics, etag: nil) result = endpoint.put( ics, url: event_url, content_type: :ics, etag: etag ) Event.new( url: event_url, etag: result.headers["ETag"] ) rescue PreconditionError nil end |