kerio-ical 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +16 -0
- data/PostInstall.txt +3 -0
- data/README.rdoc +64 -0
- data/Rakefile +25 -0
- data/config/template_config.yml +4 -0
- data/lib/kerio-ical.rb +25 -0
- data/lib/kerio-ical/config.rb +25 -0
- data/lib/kerio-ical/date_time.rb +7 -0
- data/lib/kerio-ical/get.rb +17 -0
- data/lib/kerio-ical/transport.rb +55 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_kerio_ical.rb +25 -0
- metadata +134 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
config/template_config.yml
|
7
|
+
lib/kerio-ical/config.rb
|
8
|
+
lib/kerio-ical/date_time.rb
|
9
|
+
lib/kerio-ical/get.rb
|
10
|
+
lib/kerio-ical/transport.rb
|
11
|
+
lib/kerio-ical.rb
|
12
|
+
script/console
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
test/test_kerio_ical.rb
|
16
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= kerio-ical
|
2
|
+
|
3
|
+
http://github.com/athlite/kerio-ical
|
4
|
+
|
5
|
+
== DESCRIPTION
|
6
|
+
|
7
|
+
A Ruby interface to Kerio Mail server calendars
|
8
|
+
|
9
|
+
== FEATURES
|
10
|
+
|
11
|
+
* List a user calendars.
|
12
|
+
|
13
|
+
== SYNOPSIS
|
14
|
+
Setup
|
15
|
+
|
16
|
+
KerioIcal::Config.config = {
|
17
|
+
'url' => 'https://mail.example.com/path/to-calendars',
|
18
|
+
'username' => 'username',
|
19
|
+
'password' => 'password'
|
20
|
+
}
|
21
|
+
|
22
|
+
To get calendars of a specific user
|
23
|
+
|
24
|
+
calendars = KerioIcal::Get.calendars('username')
|
25
|
+
|
26
|
+
calendars.each do |cal|
|
27
|
+
cal.events.each do |event|
|
28
|
+
p event
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
== REQUIREMENTS
|
33
|
+
|
34
|
+
* icalendar
|
35
|
+
* curl must be installed
|
36
|
+
|
37
|
+
== INSTALL
|
38
|
+
|
39
|
+
* sudo gem install kerio-ical
|
40
|
+
|
41
|
+
== LICENSE:
|
42
|
+
|
43
|
+
(The MIT License)
|
44
|
+
|
45
|
+
Copyright (c) 2010 Thomas T. Eng
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/kerio-ical'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'kerio-ical' do
|
14
|
+
self.developer 'Thomas Tinnesand Eng', 'thomas.tinnesand.eng@gmail.com'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
self.extra_deps = [['icalendar', '>= 1.1.5']]
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'newgem/tasks'
|
21
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
22
|
+
|
23
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
24
|
+
# remove_task :default
|
25
|
+
# task :default => [:spec, :features]
|
data/lib/kerio-ical.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
# *Author*:: Thomas T. Eng (mailto:thomas.tinnesand.eng@gmail.com)
|
5
|
+
# *Copyright*:: Copyright (c) 2010 Thomas T. Eng
|
6
|
+
# *License*:: The MIT License
|
7
|
+
module KerioIcal
|
8
|
+
|
9
|
+
# Gem version
|
10
|
+
VERSION = '0.0.1'
|
11
|
+
|
12
|
+
# Base dir of lib.
|
13
|
+
ROOT_DIR = File.expand_path( File.dirname(__FILE__) )
|
14
|
+
|
15
|
+
require 'yaml'
|
16
|
+
require 'date'
|
17
|
+
require 'net/http'
|
18
|
+
require 'net/https'
|
19
|
+
require 'rubygems'
|
20
|
+
require 'icalendar'
|
21
|
+
require 'kerio-ical/config'
|
22
|
+
require 'kerio-ical/date_time.rb'
|
23
|
+
require 'kerio-ical/transport'
|
24
|
+
require 'kerio-ical/get'
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module KerioIcal
|
2
|
+
# Holds config parameters.
|
3
|
+
class Config
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# set config hash
|
7
|
+
def config=(c)
|
8
|
+
@config = c
|
9
|
+
end
|
10
|
+
|
11
|
+
# access config params
|
12
|
+
def [](key)
|
13
|
+
@config ||= YAML::load_file( File.join(ROOT_DIR, "..", "config", "config.yml") )
|
14
|
+
@config[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
# access to config params through class methods
|
18
|
+
# i.e *Config.url*
|
19
|
+
def method_missing(name, *options, &block)
|
20
|
+
self[name.to_s] or super
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module KerioIcal
|
2
|
+
# Gets the calendar objects
|
3
|
+
class Get
|
4
|
+
class << self
|
5
|
+
# *user* must be under a directory on mail server.
|
6
|
+
# i.e. _http://mail.example.com/ical/example.com/john.doe_
|
7
|
+
#
|
8
|
+
# returns an array *Icalendar* objects
|
9
|
+
def calendars(user)
|
10
|
+
Transport::url = Config.url
|
11
|
+
transport = Transport::url.match(/^https:/) ? :net_https : :net_http
|
12
|
+
result = Transport::get(Config.username, Config.password, user, transport)
|
13
|
+
Icalendar.parse(result)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module KerioIcal
|
2
|
+
# Methods for accessing curl transport
|
3
|
+
module Transport
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# sets path to calendar service.
|
7
|
+
def url=(u)
|
8
|
+
@url = u
|
9
|
+
end
|
10
|
+
# gets path to calendar service.
|
11
|
+
def url
|
12
|
+
@url
|
13
|
+
end
|
14
|
+
|
15
|
+
# _parameters_:
|
16
|
+
# *username*:: an authorized user
|
17
|
+
# *password*:: with password
|
18
|
+
# *user*:: the user we wish to list
|
19
|
+
# *transport*:: \:net_http or \:net_https
|
20
|
+
def get(username, password, user, transport = :net_http)
|
21
|
+
return net_http(username, password, user, false) if transport == :net_http
|
22
|
+
return net_http(username, password, user, true) if transport == :net_https
|
23
|
+
""
|
24
|
+
end
|
25
|
+
|
26
|
+
# http transport
|
27
|
+
def net_http(username, password, user, ssl = true)
|
28
|
+
uri = URI.parse( inject_username_password("#{@url}/#{user}", username, password) )
|
29
|
+
@http=Net::HTTP.new(uri.host, uri.port)
|
30
|
+
@http.use_ssl= true if ssl
|
31
|
+
resp = ""
|
32
|
+
@http.start do |http|
|
33
|
+
req = Net::HTTP::Get.new(uri.path)
|
34
|
+
req.basic_auth uri.user, uri.password
|
35
|
+
response = http.request(req)
|
36
|
+
raise "not authorized" if response.code == "401"
|
37
|
+
raise "could not find user: '#{user}'" if response.code == "404"
|
38
|
+
raise "something not right [#{response.code}]" unless response.code == "200"
|
39
|
+
resp = response.body
|
40
|
+
end
|
41
|
+
resp
|
42
|
+
end
|
43
|
+
|
44
|
+
# Prefixes url with username and password.
|
45
|
+
# <p>\http://example.com => \http://user:pass@example.com</p>
|
46
|
+
def inject_username_password(url,username,password)
|
47
|
+
url = url.split("://")
|
48
|
+
url[0] += "://"
|
49
|
+
url.push(url.last)
|
50
|
+
url[1] = "#{username}:#{password}@"
|
51
|
+
url = url.join
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/kerio-ical.rb'}"
|
9
|
+
puts "Loading kerio-ical gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestKerioIcal < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
KerioIcal::Config.config = YAML::load_file(File.join(KerioIcal::ROOT_DIR, "..", "config", "test_config.yml"))
|
7
|
+
@user = KerioIcal::Config['user']
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_calendars
|
11
|
+
calendars = KerioIcal::Get.calendars(@user)
|
12
|
+
calendars.each do |cal|
|
13
|
+
assert_equal cal.class, Icalendar::Calendar
|
14
|
+
cal.events.each do |event|
|
15
|
+
assert_equal event.class, Icalendar::Event
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_inject_username_password
|
21
|
+
url = "http://example.com"
|
22
|
+
assert_equal "http://user:pass@example.com", KerioIcal::Transport::inject_username_password(url, "user", "pass")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kerio-ical
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Tinnesand Eng
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-08 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: icalendar
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 1
|
33
|
+
- 5
|
34
|
+
version: 1.1.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rubyforge
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
- 4
|
50
|
+
version: 2.0.4
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hoe
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
- 2
|
66
|
+
version: 2.6.2
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description: A Ruby interface to Kerio Mail server calendars
|
70
|
+
email:
|
71
|
+
- thomas.tinnesand.eng@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- History.txt
|
78
|
+
- Manifest.txt
|
79
|
+
- PostInstall.txt
|
80
|
+
files:
|
81
|
+
- History.txt
|
82
|
+
- Manifest.txt
|
83
|
+
- PostInstall.txt
|
84
|
+
- README.rdoc
|
85
|
+
- Rakefile
|
86
|
+
- config/template_config.yml
|
87
|
+
- lib/kerio-ical/config.rb
|
88
|
+
- lib/kerio-ical/date_time.rb
|
89
|
+
- lib/kerio-ical/get.rb
|
90
|
+
- lib/kerio-ical/transport.rb
|
91
|
+
- lib/kerio-ical.rb
|
92
|
+
- script/console
|
93
|
+
- script/destroy
|
94
|
+
- script/generate
|
95
|
+
- test/test_kerio_ical.rb
|
96
|
+
- test/test_helper.rb
|
97
|
+
has_rdoc: true
|
98
|
+
homepage: http://github.com/athlite/kerio-ical
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message: PostInstall.txt
|
102
|
+
rdoc_options:
|
103
|
+
- --main
|
104
|
+
- README.rdoc
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project: kerio-ical
|
128
|
+
rubygems_version: 1.3.7
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: A Ruby interface to Kerio Mail server calendars
|
132
|
+
test_files:
|
133
|
+
- test/test_helper.rb
|
134
|
+
- test/test_kerio_ical.rb
|