Class: Carddav::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/carddav/client.rb

Constant Summary collapse

NAMESPACES =
{ 'xmlns:D' => 'DAV:', 'xmlns:C' => 'urn:ietf:params:xml:ns:carddav' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, username, password) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/carddav/client.rb', line 7

def initialize(host, username, password)
  @host = Carddav::Url.new host
  @username = username
  @password = password
end

Instance Attribute Details

#addressbook_home_set_urlObject

Returns the value of attribute addressbook_home_set_url.



4
5
6
# File 'lib/carddav/client.rb', line 4

def addressbook_home_set_url
  @addressbook_home_set_url
end

#addressbook_urlObject

Returns the value of attribute addressbook_url.



4
5
6
# File 'lib/carddav/client.rb', line 4

def addressbook_url
  @addressbook_url
end

#current_user_principal_urlObject

Returns the value of attribute current_user_principal_url.



4
5
6
# File 'lib/carddav/client.rb', line 4

def current_user_principal_url
  @current_user_principal_url
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/carddav/client.rb', line 4

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'lib/carddav/client.rb', line 4

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/carddav/client.rb', line 4

def username
  @username
end

Instance Method Details

#cardsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/carddav/client.rb', line 39

def cards
  res = request addressbook_url, method: 'REPORT', depth: 1 do
    Nokogiri::XML::Builder.new do |xml|
      xml['C'].send 'addressbook-query', NAMESPACES do
        xml['D'].prop do
          xml['D'].getetag
          xml['C'].send 'address-data'
        end
      end
    end.to_xml
  end
  res.xpath('//address-data/text()').map { |node| Carddav::Card.new node }
end