A set of mixins for building CloudKit::Response objects.
Methods
public instance
Public instance methods
allow
(methods)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 41 41: def allow(methods) 42: CloudKit::Response.new( 43: 200, 44: {'Allow' => methods.join(', '), 'Content-Type' => 'application/json'}) 45: end
data_required
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 29 29: def data_required 30: json_error_response(400, 'data required') 31: end
etag_required
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 37 37: def etag_required 38: json_error_response(400, 'etag required') 39: end
internal_server_error
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 25 25: def internal_server_error 26: json_error_response(500, 'unknown server error') 27: end
invalid_entity_type
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 33 33: def invalid_entity_type 34: json_error_response(400, 'valid entity type required') 35: end
json_create_response
(uri, etag, last_modified)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 64 64: def json_create_response(uri, etag, last_modified) 65: json = json_metadata(uri, etag, last_modified) 66: response(201, json, nil, nil, {:cache => false, :location => uri}) 67: end
json_error
(message)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 77 77: def json_error(message) 78: "{\"error\":\"#{message}\"}" 79: end
json_error_response
(status, message)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 81 81: def json_error_response(status, message) 82: response(status, json_error(message), nil, nil, :cache => false) 83: end
json_meta_response
(uri, etag, last_modified)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 59 59: def json_meta_response(uri, etag, last_modified) 60: json = json_metadata(uri, etag, last_modified) 61: response(200, json, nil, nil, :cache => false) 62: end
json_metadata
(uri, etag, last_modified)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 69 69: def json_metadata(uri, etag, last_modified) 70: JSON.generate( 71: :ok => true, 72: :uri => uri, 73: :etag => etag, 74: :last_modified => last_modified) 75: end
response
(status, content='', etag=nil, last_modified=nil, options={})
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 47 47: def response(status, content='', etag=nil, last_modified=nil, options={}) 48: cache_control = options[:cache] == false ? 'no-cache' : 'proxy-revalidate' 49: etag = "\"#{etag}\"" if etag 50: headers = {}.filter_merge!( 51: 'Content-Type' => 'application/json', 52: 'Cache-Control' => cache_control, 53: 'Last-Modified' => last_modified, 54: 'Location' => options[:location], 55: 'ETag' => etag) 56: CloudKit::Response.new(status, headers, content) 57: end
status_404
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 3 3: def status_404 4: json_error_response(404, 'not found') 5: end
status_405
(methods)
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 7 7: def status_405(methods) 8: response = json_error_response(405, 'method not allowed') 9: response['Allow'] = methods.join(', ') 10: response 11: end
status_410
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 13 13: def status_410 14: json_error_response(410, 'entity previously deleted') 15: end
status_412
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 17 17: def status_412 18: json_error_response(412, 'precondition failed') 19: end
status_422
()
[show source]
# File lib/cloudkit/store/response_helpers.rb, line 21 21: def status_422 22: json_error_response(422, 'unprocessable entity') 23: end