Class: SimpleDav::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_dav/base.rb

Direct Known Subclasses

AddressBook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/simple_dav/base.rb', line 21

def initialize(params = {})
  begin
    url = params[:ssl] ? "https://#{params[:server]}/" : "http://#{params[:server]}/"
    url += case (@type = params[:type])
    when "sogo" then "SOGo/dav/#{params[:user]}/"
    else ""
    end
    @uri = URI.parse(url)
    @uid = nil
    @headers = {}
    #open(uri) if uri
    proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] || nil
    @client = HTTPClient.new(proxy)
    @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE unless params[:verify]
    if (@user = params[:user]) && params[:pass]
      @client.set_basic_auth(@uri, @user, params[:pass])
    end
  rescue
    raise RuntimeError.exception("Init Failed!! (#{$!.to_s})")
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/simple_dav/base.rb', line 14

def client
  @client
end

#headersObject (readonly)

Returns the value of attribute headers.



14
15
16
# File 'lib/simple_dav/base.rb', line 14

def headers
  @headers
end

#uriObject (readonly)

Returns the value of attribute uri.



14
15
16
# File 'lib/simple_dav/base.rb', line 14

def uri
  @uri
end

Instance Method Details

#gen_uidObject

generate unique id to create resources



17
18
19
# File 'lib/simple_dav/base.rb', line 17

def gen_uid
  "#{rand(100000)}-#{Time.now.to_i}-#{rand(100000)}"
end