Class: OwncloudCalDAV::Client
- Inherits:
-
Object
- Object
- OwncloudCalDAV::Client
- Includes:
- Icalendar
- Defined in:
- lib/owncloud_caldav/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #__create_http ⇒ Object
- #add_alarm(tevent, altCal = "Calendar") ⇒ Object
- #create_event(event) ⇒ Object
- #create_todo ⇒ Object
- #delete_event(uuid) ⇒ Object
- #find_event(uuid) ⇒ Object
- #find_events(data) ⇒ Object
- #find_todo(uuid) ⇒ Object
- #format ⇒ Object
- #format=(fmt) ⇒ Object
-
#initialize(data) ⇒ Client
constructor
A new instance of Client.
- #update_event(event) ⇒ Object
Constructor Details
#initialize(data) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/owncloud_caldav/client.rb', line 14 def initialize( data ) unless data[:proxy_uri].nil? proxy_uri = URI(data[:proxy_uri]) @proxy_host = proxy_uri.host @proxy_port = proxy_uri.port.to_i end uri = URI(data[:uri]) @host = uri.host @port = uri.port.to_i @url = uri.path @user = data[:user] @password = data[:password] @ssl = uri.scheme == 'https' end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def port @port end |
#ssl ⇒ Object
Returns the value of attribute ssl.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def ssl @ssl end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/owncloud_caldav/client.rb', line 4 def user @user end |
Instance Method Details
#__create_http ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/owncloud_caldav/client.rb', line 29 def __create_http if @proxy_uri.nil? http = Net::HTTP.new(@host, @port) else http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) end if @ssl http.use_ssl = @ssl http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http end |
#add_alarm(tevent, altCal = "Calendar") ⇒ Object
134 135 136 |
# File 'lib/owncloud_caldav/client.rb', line 134 def add_alarm tevent, altCal="Calendar" end |
#create_event(event) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/owncloud_caldav/client.rb', line 97 def create_event event c = Calendar.new uuid = UUID.new.generate raise DuplicateError if entry_with_uuid_exists?(uuid) c.event do |e| e.uid = uuid e.dtstart = DateTime.parse(event[:start]) e.dtend = DateTime.parse(event[:end]) e.categories = event[:categories]# Array e.duration = event[:duration] e.summary = event[:title] e.description = event[:description] e.status = event[:status] end cstring = c.to_ical res = nil http = Net::HTTP.new(@host, @port) __create_http.start { |http| req = Net::HTTP::Put.new("#{@url}/#{uuid}.ics") req['Content-Type'] = 'text/calendar' req.basic_auth @user, @password req.body = cstring res = http.request( req ) } errorhandling res find_event uuid end |
#create_todo ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/owncloud_caldav/client.rb', line 150 def create_todo todo c = Calendar.new uuid = UUID.new.generate raise DuplicateError if entry_with_uuid_exists?(uuid) c.todo do uid uuid start DateTime.parse(todo[:start]) duration todo[:duration] summary todo[:title] description todo[:description] klass todo[:accessibility] #PUBLIC, PRIVATE, CONFIDENTIAL location todo[:location] percent todo[:percent] priority todo[:priority] url todo[:url] geo todo[:geo_location] status todo[:status] end c.todo.uid = uuid cstring = c.to_ical res = nil http = Net::HTTP.new(@host, @port) __create_http.start { |http| req = Net::HTTP::Put.new("#{@url}/#{uuid}.ics") req['Content-Type'] = 'text/calendar' req.basic_auth @user, @password req.body = cstring res = http.request( req ) } errorhandling res find_todo uuid end |
#delete_event(uuid) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/owncloud_caldav/client.rb', line 82 def delete_event uuid res = nil __create_http.start {|http| req = Net::HTTP::Delete.new("#{@url}/#{uuid}.ics") req.basic_auth @user, @password res = http.request( req ) } errorhandling res if res.code.to_i == 200 return true else return false end end |
#find_event(uuid) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/owncloud_caldav/client.rb', line 64 def find_event uuid res = nil __create_http.start {|http| req = Net::HTTP::Get.new("#{@url}/#{uuid}.ics") req.basic_auth @user, @password res = http.request( req ) } errorhandling res r = Icalendar.parse(res.body) unless r.empty? r.first.events.first else return false end end |
#find_events(data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/owncloud_caldav/client.rb', line 42 def find_events data result = "" events = [] res = nil __create_http.start do |http| req = Net::HTTP::Report.new(@url, initheader = {'Content-Type'=>'application/xml', 'depth' => '1'} ) req.basic_auth @user, @password req.body = OwncloudCalDAV::Request::ReportVEVENT.new(DateTime.parse(data[:start]).strftime("%Y%m%dT%H%M%S"), DateTime.parse(data[:end]).strftime("%Y%m%dT%H%M%S")).to_xml res = http.request(req) end errorhandling res result = "" xml = REXML::Document.new(res.body) REXML::XPath.each( xml, '//d:response/') do |c| event = Icalendar.parse(c.elements['//cal:calendar-data'].text).first.events.first uid = c.elements['d:href'].text.split('/').last.split('.').first event.uid = uid events << event end return events end |
#find_todo(uuid) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/owncloud_caldav/client.rb', line 138 def find_todo uuid res = nil __create_http.start {|http| req = Net::HTTP::Get.new("#{@url}/#{uuid}.ics") req.basic_auth @user, @password res = http.request( req ) } errorhandling res r = Icalendar.parse(res.body) r.first.todos.first end |
#format ⇒ Object
10 11 12 |
# File 'lib/owncloud_caldav/client.rb', line 10 def format @format ||= Format::Debug.new end |
#format=(fmt) ⇒ Object
6 7 8 |
# File 'lib/owncloud_caldav/client.rb', line 6 def format=( fmt ) @format = fmt end |
#update_event(event) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/owncloud_caldav/client.rb', line 125 def update_event event #TODO... fix me if delete_event event[:uid] create_event event else return false end end |