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
46
47
48
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 46
def collection?
false
end
|
#delete ⇒ Object
135
136
137
138
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 135
def delete
@contact.destroy
NoContent
end
|
#exist? ⇒ Boolean
50
51
52
53
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 50
def exist?
Logger.info "ContactR::exist?(#{public_path});"
@contact != nil
end
|
#get(request, response) ⇒ Object
130
131
132
133
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 130
def get(request, response)
response.['Etag'] = @contact.etag
response.body = @contact.vcard.vcard
end
|
#parent ⇒ Object
118
119
120
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 118
def parent
@address_book
end
|
#parent_collection? ⇒ Boolean
126
127
128
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 126
def parent_collection?
true
end
|
#parent_exists? ⇒ Boolean
122
123
124
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 122
def parent_exists?
@address_book != nil
end
|
#put(request, response) ⇒ Object
61
62
63
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
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 61
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 (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
55
56
57
58
59
|
# File 'lib/dav4rack_ext/carddav/resources/contact_resource.rb', line 55
def setup
super
@address_book = @options[:_parent_] || current_user.current_addressbook()
@contact = @options[:_object_] || current_user.current_contact()
end
|