Module: Riak::Client::HTTPBackend::ObjectMethods
- Included in:
- Riak::Client::HTTPBackend
- Defined in:
- riak-client/lib/riak/client/http_backend/object_methods.rb
Overview
Methods for assisting with the handling of RObjects present in HTTP requests and responses.
Instance Method Summary (collapse)
-
- (Object) load_object(robject, response)
Load object data from an HTTP response.
-
- (Hash) reload_headers(robject)
HTTP header hash that will be sent along when reloading the object.
-
- (Hash) store_headers(robject)
HTTP header hash that will be sent along when storing the object.
Instance Method Details
- (Object) load_object(robject, response)
Load object data from an HTTP response
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'riak-client/lib/riak/client/http_backend/object_methods.rb', line 61 def load_object(robject, response) extract_header(robject, response, "location", :key) {|v| URI.unescape(v.match(%r{.*/(.*?)(\?.*)?$})[1]) } extract_header(robject, response, "content-type", :content_type) extract_header(robject, response, "x-riak-vclock", :vclock) extract_header(robject, response, "link", :links) {|v| Set.new(Link.parse(v)) } extract_header(robject, response, "etag", :etag) extract_header(robject, response, "last-modified", :last_modified) {|v| Time.httpdate(v) } robject. = response[:headers].inject({}) do |h,(k,v)| if k =~ /x-riak-meta-(.*)/ h[$1] = v end h end robject.conflict = (response[:code] && response[:code].to_i == 300 && robject.content_type =~ /multipart\/mixed/) robject.siblings = robject.conflict? ? extract_siblings(robject, response[:body]) : nil robject.raw_data = response[:body] if response[:body].present? && !robject.conflict? robject end |
- (Hash) reload_headers(robject)
HTTP header hash that will be sent along when reloading the object
30 31 32 33 34 35 |
# File 'riak-client/lib/riak/client/http_backend/object_methods.rb', line 30 def reload_headers(robject) {}.tap do |h| h['If-None-Match'] = robject.etag if robject.etag.present? h['If-Modified-Since'] = robject.last_modified.httpdate if robject.last_modified.present? end end |
- (Hash) store_headers(robject)
HTTP header hash that will be sent along when storing the object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'riak-client/lib/riak/client/http_backend/object_methods.rb', line 39 def store_headers(robject) {}.tap do |hash| hash["Content-Type"] = robject.content_type hash["X-Riak-Vclock"] = robject.vclock if robject.vclock if robject.prevent_stale_writes && robject.etag.present? hash["If-Match"] = robject.etag elsif robject.prevent_stale_writes hash["If-None-Match"] = "*" end unless robject.links.blank? hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map(&:to_s).join(", ") end unless robject..blank? robject..each do |k,v| hash["X-Riak-Meta-#{k}"] = v.to_s end end end end |