Class: MDQT::Client::MetadataResponse
- Inherits:
-
Object
- Object
- MDQT::Client::MetadataResponse
- Defined in:
- lib/mdqt/client/metadata_response.rb
Instance Method Summary collapse
- #code ⇒ Object
- #content_type ⇒ Object
- #data ⇒ Object
- #entity_id ⇒ Object
- #entity_ids ⇒ Object
- #etag ⇒ Object
- #expires ⇒ Object
- #explanation ⇒ Object
- #filename ⇒ Object
- #identifier ⇒ Object
-
#initialize(identifier, service, http_response, options = {}) ⇒ MetadataResponse
constructor
A new instance of MetadataResponse.
- #last_modified ⇒ Object
- #message ⇒ Object
- #ok? ⇒ Boolean
- #requested_identifier ⇒ Object
- #service ⇒ Object
- #signed? ⇒ Boolean
- #type ⇒ Object
- #valid? ⇒ Boolean
- #validation_error ⇒ Object
- #verified_signature?(certs = [], _ = {}) ⇒ Boolean
Constructor Details
#initialize(identifier, service, http_response, options = {}) ⇒ MetadataResponse
Returns a new instance of MetadataResponse.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mdqt/client/metadata_response.rb', line 9 def initialize(identifier, service, http_response, = {}) @requested_identitier = identifier @identifier = URI.decode_www_form_component(identifier) @service = service @code = http_response.status || 500 @data = http_response.body || "" @type = nil @content_type = http_response.headers['Content-Type'] @expires = http_response.headers['Expires'] @etag = http_response.headers['ETag'] @last_modified = http_response.headers['Last-Modified'] @ok = http_response.success? @explanation = {} if [:explain] @explanation[:url] = http_response.env.url.to_s @explanation[:method] = http_response.env.method.to_s.upcase @explanation[:status] = http_response.status @explanation[:response_headers] = http_response.headers @explanation[:request_headers] = http_response.env.request_headers end end |
Instance Method Details
#code ⇒ Object
57 58 59 |
# File 'lib/mdqt/client/metadata_response.rb', line 57 def code @code end |
#content_type ⇒ Object
69 70 71 |
# File 'lib/mdqt/client/metadata_response.rb', line 69 def content_type @content_type end |
#data ⇒ Object
61 62 63 |
# File 'lib/mdqt/client/metadata_response.rb', line 61 def data @data || "" end |
#entity_id ⇒ Object
43 44 45 46 |
# File 'lib/mdqt/client/metadata_response.rb', line 43 def entity_id raise "Incorrect metadata file type - aggregate" if aggregate? @entity_id ||= extract_entity_id end |
#entity_ids ⇒ Object
48 49 50 |
# File 'lib/mdqt/client/metadata_response.rb', line 48 def entity_ids @entity_ids ||= extract_entity_ids end |
#etag ⇒ Object
77 78 79 |
# File 'lib/mdqt/client/metadata_response.rb', line 77 def etag @etag end |
#expires ⇒ Object
73 74 75 |
# File 'lib/mdqt/client/metadata_response.rb', line 73 def expires @expires end |
#explanation ⇒ Object
149 150 151 |
# File 'lib/mdqt/client/metadata_response.rb', line 149 def explanation @explanation end |
#filename ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/mdqt/client/metadata_response.rb', line 109 def filename if identifier.empty? @filename = "aggregate-#{Digest::SHA1.hexdigest(@service)}.xml" else @filename ||= identifier.start_with?("{sha1}") ? "#{@identifier.gsub("{sha1}","")}.xml" : "#{Digest::SHA1.hexdigest(@identifier)}.xml" end end |
#identifier ⇒ Object
34 35 36 |
# File 'lib/mdqt/client/metadata_response.rb', line 34 def identifier @identifier end |
#last_modified ⇒ Object
81 82 83 |
# File 'lib/mdqt/client/metadata_response.rb', line 81 def last_modified @last_modified end |
#message ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/mdqt/client/metadata_response.rb', line 119 def case code when 200 identifier.empty? ? "[200] OK! Data for aggregate has been downloaded from #{service}" : "[200] OK! Data for '#{identifier}' has been downloaded from #{service}" when 304 "[304] OK! Data for '#{identifier}' is already available in a local cache" when 400 "[400] The identifier '#{identifier}' ('#{requested_identifier}') is malformed or service URL #{service} is incorrect" when 401 "[401] Credentials are incorrect or missing for '#{identifier}'" when 403 identifier.empty? ? "[403] The MDQ service at #{service} does not support aggregate downloads" : "[403] You do not have access rights to '#{identifier}' at #{service}" when 404 identifier.empty? ? "[404] The MDQ service at #{service} is not responding with aggregated metadata or the correct status" : "[404] Entity metadata for '#{identifier}' was not found at #{service}" when 405 "[405] The service at #{service} believes the wrong HTTP method was used. We should have used HTTP GET..." when 406 "[406] The requested content type is not available at #{service}" when 500 "[500] An error has occurred at #{service}" when 505 "[505] The service at #{service} claims our request was using pre-1999 web protocols, not HTTP 1.1 or later" else "[#{code}] Sorry - an unknown error has occurred requesting '#{identifier}' from #{service}.\nPlease report this bug!" end end |
#ok? ⇒ Boolean
85 86 87 |
# File 'lib/mdqt/client/metadata_response.rb', line 85 def ok? @ok end |
#requested_identifier ⇒ Object
39 40 41 |
# File 'lib/mdqt/client/metadata_response.rb', line 39 def requested_identifier @identifier end |
#service ⇒ Object
53 54 55 |
# File 'lib/mdqt/client/metadata_response.rb', line 53 def service @service end |
#signed? ⇒ Boolean
89 90 91 |
# File 'lib/mdqt/client/metadata_response.rb', line 89 def signed? @data.include? "Signature" # This is... not great end |
#type ⇒ Object
65 66 67 |
# File 'lib/mdqt/client/metadata_response.rb', line 65 def type @type ||= calculate_type end |
#valid? ⇒ Boolean
99 100 101 102 |
# File 'lib/mdqt/client/metadata_response.rb', line 99 def valid? validator = MetadataValidator.new validator.valid?(self) end |
#validation_error ⇒ Object
104 105 106 107 |
# File 'lib/mdqt/client/metadata_response.rb', line 104 def validation_error validator = MetadataValidator.new validator.validation_error(self) end |
#verified_signature?(certs = [], _ = {}) ⇒ Boolean
93 94 95 96 97 |
# File 'lib/mdqt/client/metadata_response.rb', line 93 def verified_signature?(certs = [], _ = {}) return true unless ok? # CHECK ? validator = MetadataValidator.new(certs: [certs].flatten) validator.verified_signature?(self) end |