lib/sourcescrub/utils/response.rb in sourcescrub-0.0.2 vs lib/sourcescrub/utils/response.rb in sourcescrub-0.0.3

- old
+ new

@@ -6,9 +6,28 @@ # Parse the response. build with object module Response module_function def dynamic_attributes(object, attribute_names, response) + # Retrieve request limit data from header + # + # .date + # .content_type + # .server + # .content_length + # .request_context + # .strict_transport_security + # .x_ratelimit_limit + # .x_ratelimit_remaining + # .x_ratelimit_reset + headers = response.dig('headers') + headers&.keys&.each do |attr_name| + object.class.send(:define_method, attr_name.gsub('-', '_').to_sym) do + headers[attr_name] + end + end + + # Setup attributes attribute_names.each do |attr_name| attr_value = response.dig(attr_name) dynamic_define_method(object, attr_name, attr_value) end