Module: KerioIcal::Transport

Defined in:
lib/kerio-ical/transport.rb

Overview

Methods for accessing curl transport

Class Method Summary collapse

Class Method Details

.get(username, password, user, transport = :net_http) ⇒ Object

parameters:

username

an authorized user

password

with password

user

the user we wish to list

transport

:net_http or :net_https



20
21
22
23
24
# File 'lib/kerio-ical/transport.rb', line 20

def get(username, password, user, transport = :net_http)
	return net_http(username, password, user, false) if transport == :net_http
	return net_http(username, password, user, true) if transport == :net_https
	""
end

.inject_username_password(url, username, password) ⇒ Object

Prefixes url with username and password. <p>example.com => user:[email protected]</p>



46
47
48
49
50
51
52
# File 'lib/kerio-ical/transport.rb', line 46

def inject_username_password(url,username,password)
	url = url.split("://")
	url[0] += "://"
	url.push(url.last)
	url[1] = "#{username}:#{password}@"
	url = url.join
end

.net_http(username, password, user, ssl = true) ⇒ Object

http transport



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kerio-ical/transport.rb', line 27

def net_http(username, password, user, ssl = true)
	uri = URI.parse( inject_username_password("#{@url}/#{user}", username, password) )
	@http=Net::HTTP.new(uri.host, uri.port)
	@http.use_ssl= true if ssl
	resp = ""
	@http.start do |http|
		req = Net::HTTP::Get.new(uri.path)
		req.basic_auth uri.user, uri.password
		response = http.request(req)
		raise "not authorized" if response.code == "401"
		raise "could not find user: '#{user}'" if response.code == "404"
		raise "something not right [#{response.code}]" unless response.code == "200"
		resp = response.body
	end
	resp
end

.urlObject

gets path to calendar service.



11
12
13
# File 'lib/kerio-ical/transport.rb', line 11

def url
	@url
end

.url=(u) ⇒ Object

sets path to calendar service.



7
8
9
# File 'lib/kerio-ical/transport.rb', line 7

def url=(u)
	@url = u
end