Class: DAV4Rack::Carddav::ContactResource
- Inherits:
-
Resource
- Object
- Resource
- Resource
- DAV4Rack::Carddav::ContactResource
show all
- Defined in:
- lib/dav4rack_ext/carddav/resources/contact_resource.rb
Constant Summary
Constants inherited
from Resource
Resource::CARDAV_NS, Resource::PRIVILEGES
Instance Method Summary
collapse
Methods inherited from Resource
#children, #current_user, #get_property, #initialize, #is_self?, #properties, #router_params, #user_agent
#define_properties, extended
Instance Method Details
#collection? ⇒ Boolean
49
50
51
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 49
def collection?
false
end
|
#delete ⇒ Object
140
141
142
143
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 140
def delete
@contact.destroy
NoContent
end
|
#exist? ⇒ Boolean
53
54
55
56
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 53
def exist?
Logger.info "ContactR::exist?(#{public_path});"
@contact != nil
end
|
#get(request, response) ⇒ Object
135
136
137
138
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 135
def get(request, response)
response.['Etag'] = @contact.etag
response.body = @contact.vcard.vcard
end
|
#parent ⇒ Object
123
124
125
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 123
def parent
@address_book
end
|
#parent_collection? ⇒ Boolean
131
132
133
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 131
def parent_collection?
true
end
|
#parent_exists? ⇒ Boolean
127
128
129
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 127
def parent_exists?
@address_book != nil
end
|
#put(request, response) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 64
def put(request, response)
b = request.body.read
vcards = VCardParser::VCard.parse(b)
raise BadRequest if vcards.size != 1
vcf = vcards[0]
uid = vcf['UID'].value
want_new_contact = (request.env['HTTP_IF_NONE_MATCH'] == '*')
@contact = @address_book.find_contact(uid)
raise Conflict if (want_new_contact and @contact)
if if_match = request.env['HTTP_IF_MATCH']
if_match = if_match.tr('"', '')
if (if_match == '*') || !@contact
raise PreconditionFailed unless @contact
elsif (if_match != @contact.etag)
raise PreconditionFailed
end
end
if @contact
Logger.debug("Updating contact #{uid} (#{@contact.object_id})")
else
Logger.debug("Creating new contact ! (#{uid})")
@contact = @address_book.create_contact(uid)
end
@contact.update_from_vcard(vcf)
if @contact.save(user_agent)
new_public = @public_path.split('/')[0...-1]
new_public << @contact.uid.to_s
@public_path = new_public.join('/')
response['ETag'] = @contact.etag
end
Created
end
|
#setup ⇒ Object
58
59
60
61
62
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 58
def setup
super
@address_book = @options[:_parent_] || current_user.current_addressbook()
@contact = @options[:_object_] || current_user.current_contact()
end
|