agcaldav 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  caldaver-test.sh
2
+ *.gem
data/lib/caldav.rb CHANGED
@@ -6,7 +6,7 @@ require 'date'
6
6
  require 'icalendar'
7
7
  require 'time'
8
8
 
9
- ['client.rb', 'request.rb', 'net.rb', 'query.rb', 'filter.rb', 'caldaver.rb', 'format.rb'].each do |f|
9
+ ['client.rb', 'request.rb', 'net.rb', 'query.rb', 'filter.rb', 'format.rb'].each do |f|
10
10
  require File.join( File.dirname(__FILE__), 'caldav', f )
11
11
  end
12
12
 
data/lib/caldav/client.rb CHANGED
@@ -49,12 +49,13 @@ module CalDAV
49
49
  http
50
50
  end
51
51
 
52
- def report start, stop
52
+ def report datetime_start, datetime_stop
53
53
  res = nil
54
54
  __create_http.start {|http|
55
55
  req = Net::HTTP::Report.new(@url, initheader = {'Content-Type'=>'application/xml'} )
56
56
  req.basic_auth @user, @password
57
- req.body = CalDAV::Request::ReportVEVENT.new( start, stop ).to_xml
57
+ req.body = CalDAV::Request::ReportVEVENT.new(DateTime.parse(datetime_start).strftime("%Y%m%dT%H%M"),
58
+ DateTime.parse(datetime_stop).strftime("%Y%m%dT%H%M") ).to_xml
58
59
  res = http.request( req )
59
60
  }
60
61
  format.parse_calendar( res.body )
@@ -81,30 +82,23 @@ module CalDAV
81
82
  end
82
83
 
83
84
  def create event
84
- nowstr = DateTime.now.strftime "%Y%m%dT%H%M%SZ"
85
- uuid = UUID.generate
86
- dings = """BEGIN:VCALENDAR
87
- PRODID:Caldav.rb
88
- VERSION:2.0
89
- BEGIN:VEVENT
90
- CREATED:#{nowstr}
91
- UID:#{uuid}
92
- SUMMARY:#{event.summary}
93
- DTSTART:#{event.dtstart.strftime("%Y%m%dT%H%M%S")}
94
- DTEND:#{event.dtend.strftime("%Y%m%dT%H%M%S")}
95
- END:VEVENT
96
- END:VCALENDAR"""
97
-
85
+ event.uid = UUID.generate
86
+ event.dtstamp = DateTime.now.strftime "%Y%m%dT%H%M%SZ"
87
+ event.dtstart = event.dtstart.strftime("%Y%m%dT%H%M%S")
88
+ event.dtend = event.dtend.strftime("%Y%m%dT%H%M%S")
89
+ cal = Calendar.new
90
+ cal.event = Event.new(event)
91
+ c = cal.to_ical
98
92
  res = nil
99
93
  http = Net::HTTP.new(@host, @port)
100
94
  __create_http.start { |http|
101
- req = Net::HTTP::Put.new("#{@url}/#{uuid}.ics")
95
+ req = Net::HTTP::Put.new("#{@url}/#{event.uid}.ics")
102
96
  req['Content-Type'] = 'text/calendar'
103
97
  req.basic_auth @user, @password
104
98
  req.body = dings
105
99
  res = http.request( req )
106
100
  }
107
- return uuid, res
101
+ return event.uid, res
108
102
  end
109
103
 
110
104
  def add_alarm tevent, altCal="Calendar"
@@ -1,3 +1,3 @@
1
1
  module CalDAV
2
- VERSION=0.1
2
+ VERSION = "0.1.1"
3
3
  end
data/ruby-caldav.gemspec CHANGED
@@ -1,20 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require File.expand_path('../lib/caldav/version', __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "agcaldav"
5
6
  s.version = CalDAV::VERSION
6
- s.summary = "Ruby CalDAV client"
7
- s.description = "Ruby client for CalDAV calendar and tasks."
8
- s.homepage = "https://github.com/agilastic/ruby-caldav"
9
- s.authors = ["Alex Ebeling-Hoppe"]
10
- s.email = ["ebeling-hoppe@agilastic.de"]
11
-
12
- s.add_runtime_dependency 'nokogiri'
7
+ s.summary = "new Ruby CalDAV client"
8
+ s.description = "yet another new Ruby client for CalDAV calendar and tasks."
9
+
10
+ s.required_ruby_version = '>= 1.9.2'
11
+
12
+ s.license = 'MIT'
13
+
14
+ s.homepage = 'https://github.com/agilastic/caldav2'
15
+ s.authors = "Alex Ebeling-Hoppe"
16
+ s.email = "ebeling-hoppe@agilastic.de"
17
+ # forked from "Martin Povolny" => "https://github.com/martinpovolny",
18
+ # "Cannon Matthews" => "https://github.com/loosecannon93",
19
+ # "Bradley McCrorey" => "https://github.com/4fthawaiian"
20
+
13
21
  s.add_runtime_dependency 'icalendar'
14
22
  s.add_runtime_dependency 'uuid'
15
23
  s.add_runtime_dependency 'builder'
24
+ #s.add_dependency "json"
25
+ #s.add_development_dependency "rspec"
16
26
 
17
27
  s.files = `git ls-files`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
28
  s.require_paths = ["lib"]
20
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agcaldav
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: nokogiri
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: icalendar
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -75,20 +59,15 @@ dependencies:
75
59
  - - ! '>='
76
60
  - !ruby/object:Gem::Version
77
61
  version: '0'
78
- description: Ruby client for CalDAV calendar and tasks.
79
- email:
80
- - ebeling-hoppe@agilastic.de
81
- executables:
82
- - caldav
62
+ description: yet another new Ruby client for CalDAV calendar and tasks.
63
+ email: ebeling-hoppe@agilastic.de
64
+ executables: []
83
65
  extensions: []
84
66
  extra_rdoc_files: []
85
67
  files:
86
68
  - .gitignore
87
69
  - README.rdoc
88
- - bin/caldav
89
- - caldavtest.rb
90
70
  - lib/caldav.rb
91
- - lib/caldav/caldaver.rb
92
71
  - lib/caldav/client.rb
93
72
  - lib/caldav/filter.rb
94
73
  - lib/caldav/format.rb
@@ -97,8 +76,9 @@ files:
97
76
  - lib/caldav/request.rb
98
77
  - lib/caldav/version.rb
99
78
  - ruby-caldav.gemspec
100
- homepage: https://github.com/agilastic/ruby-caldav
101
- licenses: []
79
+ homepage: https://github.com/agilastic/caldav2
80
+ licenses:
81
+ - MIT
102
82
  post_install_message:
103
83
  rdoc_options: []
104
84
  require_paths:
@@ -108,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
88
  requirements:
109
89
  - - ! '>='
110
90
  - !ruby/object:Gem::Version
111
- version: '0'
91
+ version: 1.9.2
112
92
  required_rubygems_version: !ruby/object:Gem::Requirement
113
93
  none: false
114
94
  requirements:
@@ -120,5 +100,5 @@ rubyforge_project:
120
100
  rubygems_version: 1.8.24
121
101
  signing_key:
122
102
  specification_version: 3
123
- summary: Ruby CalDAV client
103
+ summary: new Ruby CalDAV client
124
104
  test_files: []
data/bin/caldav DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'caldav'
4
-
5
- prg = CalDAV::CalDAVer.new
6
- prg.run_args( ARGV )
7
-
data/caldavtest.rb DELETED
@@ -1,100 +0,0 @@
1
- require './lib/caldav.rb'
2
-
3
- class CalDAVTester
4
-
5
- def initialize
6
- $caldav = {
7
- :host => 'localhost',
8
- :port => 5232,
9
- :url => '/user/calendar/',
10
- :user => 'user',
11
- :password => 'yourpassword'
12
- }
13
- begin
14
- require '~/.caldav_cred.rb'
15
- rescue LoadError
16
- end
17
-
18
- @cal = CalDAV::Client.new $caldav[:host], $caldav[:port], $caldav[:url], $caldav[:user], $caldav[:password]
19
- end
20
-
21
- attr :cal
22
-
23
- def test_create_event
24
- myevent = Event.new
25
- myevent.dtstart = DateTime.parse( '2012/08/11 09:45')
26
- myevent.dtend = DateTime.parse( '2012/08/11 10:45')
27
- myevent.summary = "Jo?"
28
-
29
- uuid, response = cal.create myevent
30
-
31
- puts "CREATE Response #{response.code} #{response.message}: #{response.body}"
32
- puts "UUID: #{uuid}"
33
-
34
- return uuid
35
- end
36
-
37
- def test_delete_event( uuid )
38
- response = cal.delete uuid
39
- puts "DETELE Response #{response.code} #{response.message}: #{response.body}"
40
- end
41
-
42
- def test_get_event( uuid )
43
- #ev, response = cal.get uuid
44
- ev = cal.get( uuid )
45
- #puts "GET Response #{response.code} #{response.message}: #{response.body}"
46
- puts ev
47
- end
48
-
49
- def test_read_todo
50
- puts '*' * 20 + ' TODO ' + '*' * 20
51
- res = cal.todo
52
-
53
- res.each{ |todo|
54
- p todo
55
- }
56
- end
57
-
58
- def test_report
59
- puts '*' * 20 + ' EVENTS ' + '*' * 20
60
- p cal.report "20111201T000000", "20131231T000000"
61
- end
62
-
63
- def test_query0
64
- puts CalDAV::Query.event.to_xml
65
-
66
- time1 = DateTime.parse('2011/08/08 09:45')
67
- time2 = DateTime.parse('2012/08/08 10:45')
68
- puts CalDAV::Query.event(time1..time2).to_xml
69
- puts CalDAV::Query.event.uid( UUID.generate ).to_xml
70
- #puts CalDAV::Query.todo.alarm(time1..time2).to_xml
71
- #puts CalDAV::Query.event.attendee(email).partstat('NEEDS-ACTION').to_xml
72
- #puts CalDAV::Query.todo.completed(false).status(:cancelled => false).to_xml
73
- end
74
-
75
- def test_query
76
- p cal.query( CalDAV::Query.event ) #=> All events
77
- p cal.query( CalDAV::Query.event(time1..time2) )
78
- p cal.query( CalDAV::Query.event.uid("UID") )
79
- p cal.query( CalDAV::Query.todo.alarm(time1..time2) )
80
- p cal.query( CalDAV::Query.event.attendee(email).partstat('NEEDS-ACTION') )
81
- p cal.query( CalDAV::Query.todo.completed(false).status(:cancelled => false) )
82
- end
83
- end
84
-
85
- #r = CalDAV::Request::Report.new( "20111201T000000", "20131231T000000" )
86
- #puts r.to_xml
87
- #exit
88
-
89
- t = CalDAVTester.new
90
-
91
- t.test_query0
92
-
93
- uuid = t.test_create_event
94
- t.test_get_event( uuid )
95
- t.test_delete_event( uuid )
96
-
97
- t.test_report
98
- t.test_read_todo
99
- #t.test_query
100
-
@@ -1,103 +0,0 @@
1
- require 'optparse'
2
-
3
- # caldav --user USER --password PASSWORD --uri URI --command COMMAND
4
- # caldav --user martin@solnet.cz --password test --uri https://mail.solnet.cz/caldav.php/martin.povolny@solnet.cz/test --command create_event
5
-
6
- # caldav report --begin 2012-01-01 --end 2012-07-01 --format raw --user USER --password PASSWORD --uri https://in.solnet.cz/caldav.php/martin.povolny@solnet.cz/public
7
- # caldav get --user USER --password PASSWD --uri https://mail.solnet.cz/caldav.php/martin.povolny%40solnet.cz/public/ --uuid 64d0b933-e916-4755-9e56-2f4d0d9068cb
8
-
9
- module CalDAV
10
-
11
- class CalDAVer
12
-
13
- def create_object( options )
14
- if options[:raw]
15
- # STDIN
16
- return STDIN.read(nil)
17
- else
18
- # options[:subject]
19
- # options[:login]
20
- # options[:summary]
21
- # options[:begin]
22
- # options[:end]
23
- # options[:due]
24
- case options[:what].intern
25
- when :task
26
- # FIXME
27
- when :event
28
- # FIXME
29
- when :contact
30
- # FIXME
31
- else
32
- print_help_and_exit if options[:command].to_s.empty? or options[:uri].to_s.empty?
33
- end
34
- end
35
- end
36
-
37
- def print_help_and_exit
38
- puts @o.help
39
- exit 1
40
- end
41
-
42
- def run_args( args )
43
- options = {}
44
- @o = OptionParser.new do |o|
45
- o.banner = "Usage: caldaver [command] [options]"
46
- o.on('-p', '--password [STRING]', String, 'Password') { |p| options[:password] = p }
47
- o.on('-u', '--user [STRING}', String, 'User (login)') { |l| options[:login] = l }
48
- o.on('--uri [STRING]', String, 'Calendar URI') { |uri| options[:uri] = uri }
49
- o.on('--format [STRING]', String, 'Format of output: raw,pretty,[debug]') {
50
- |fmt| options[:fmt] = fmt }
51
- ##o.on('--command [STRING]', String, 'Command') { |c| options[:command] = c }
52
- o.on('--uuid [STRING]', String, 'UUID') { |u| options[:uuid] = u }
53
- # what to create
54
- o.on('--what [STRING]', String, 'Event/task/contact') { |c| options[:command] = command }
55
- o.on('--raw', 'Read raw data (event/task/contact) from STDIN') { |raw| options[:raw] = true }
56
- # report and event options
57
- o.on('--begin [DATETIME]', String, 'Start time') { |dt| options[:begin] = dt }
58
- o.on('--end [DATETIME]', String, 'End time') { |dt| options[:end] = dt }
59
- o.on('--due [DATETIME]', String, 'Due time') { |dt| options[:due] = dt }
60
- #o.on('--begin [DATETIME]', DateTime, 'Start time') { |dt| options[:begin] = dt }
61
- #o.on('--end [DATETIME]', DateTime, 'End time') { |dt| options[:end] = dt }
62
- # event options
63
- o.on('--summary [string]', String, 'summary of event/task') { |s| options[:summary] = s }
64
- o.on('--location [string]', String, 'location of event/task') { |s| options[:location] = s }
65
- o.on('--subject [string]', String, 'subject of event/task') { |s| options[:subject] = s }
66
- o.on('-h') { print_help_and_exit }
67
- end
68
-
69
- options[:command] = @o.parse( args )[0]
70
-
71
- print_help_and_exit if options[:command].to_s.empty? or options[:uri].to_s.empty?
72
- cal = CalDAV::Client.new( options[:uri], options[:login], options[:password] )
73
-
74
- if options[:format]
75
- cal.format = case options[:format].intern
76
- when :raw
77
- CalDAV::Format::Raw.new
78
- when :pretty
79
- CalDAV::Format::Pretty.new
80
- when :debug
81
- CalDAV::Format::Debug.new
82
- else
83
- nil
84
- end
85
- end
86
-
87
- case options[:command].intern
88
- when :create
89
- obj = create_object( options )
90
- when :delete
91
- when :modify
92
- obj = create_object( options )
93
- when :get
94
- puts cal.get( options[:uuid] )
95
- when :report
96
- puts cal.report( options[:begin], options[:end] )
97
- else
98
- print_help_and_exit
99
- end
100
- end
101
- end
102
-
103
- end