<commit_before>namespace Docker {
	
    public errordomain RequestError {
        FATAL,
        NOT_FOUND
    }
	
    public interface RepositoryInterface : GLib.Object {
        public abstract Image[]? get_images() throws RequestError;
    }

    public class UnixSocketRepository : RepositoryInterface, GLib.Object {
		
        private string socket_path;
		
        public UnixSocketRepository(string socket_path) {
            this.socket_path = socket_path;
        }
		
        public Image[]? get_images() throws RequestError {
		
            try {
                SocketClient client = new SocketClient();
                SocketConnection conn = client.connect(new UnixSocketAddress(this.socket_path));

                string message = "GET /images/json HTTP/1.1\r\nHost: localhost\r\n\r\n";	

                conn.output_stream.write(message.data);

                DataInputStream _response = new DataInputStream(conn.input_stream);

                response = new RepositoryResponse(_response);
				
                return parse_image_payload(response.payload);

            } catch (Error e) {
                var message_builder = new StringBuilder();
                message_builder.printf("Can't connect to docker daemon at %s", this.socket_path);
                throw new RequestError.FATAL(message_builder.str);
            }
        }
		
        public RepositoryResponse response { get; private set;}
		
        private Image[] parse_image_payload(string payload) {

            Image[] images = {};
            try {
                var parser = new Json.Parser();
                parser.load_from_data(payload);
				
                var nodes = parser.get_root().get_array().get_elements();
		
                foreach (unowned Json.Node node in nodes) {
                    string[0] repotag = node.get_object().get_array_member("RepoTags").get_string_element(0).split(":", 2);

                    images += Image() {
                        id 		   = node.get_object().get_string_member("Id"),
                        created_at = (int64) node.get_object().get_int_member("Created"),
                        repository = repotag[0],
                        tag        = repotag[1]
                    };
                }
            } catch (Error e) {

                return images;
            }

            return images;
        }<commit_msg>Refactoring of repository<commit_after>namespace Docker {
	
    public errordomain RequestError {
        FATAL,
        NOT_FOUND
    }
	
    public interface RepositoryInterface : GLib.Object {
        public abstract Image[]? get_images() throws RequestError;
    }

    public class UnixSocketRepository : RepositoryInterface, GLib.Object {
		
        private string socket_path;
		private SocketClient client = new SocketClient();
		
        public UnixSocketRepository(string socket_path) {
            this.socket_path = socket_path;
        }
		
		/**
		 * Retrieve the list of all images
		 */
        public Image[]? get_images() throws RequestError {
		
            try {
				
                string message = "GET /images/json HTTP/1.1\r\nHost: localhost\r\n\r\n";	
			
                return parse_image_payload(this.send(message).payload);

            } catch (Error e) {
                var message_builder = new StringBuilder();
                message_builder.printf("Can't connect to docker daemon at %s", this.socket_path);
                throw new RequestError.FATAL(message_builder.str);
            }
        }

        public RepositoryResponse response { get; private set;}
		
		/**
		 * Create the connection to docker daemon
		 */	
		private SocketConnection create_connection() {
			return this.client.connect(new UnixSocketAddress(this.socket_path));
		}
	
		/**
		 * Send a message to docker daemon and return the response
		 */ 
		private RepositoryResponse send(string message) {
			    
			var conn = this.create_connection();
			   
			conn.output_stream.write(message.data);

            return new RepositoryResponse(new DataInputStream(conn.input_stream));
		}
		
		/**
		 * Parse images payload
		 */ 
        private Image[] parse_image_payload(string payload) {

            Image[] images = {};
            try {
                var parser = new Json.Parser();
                parser.load_from_data(payload);
				
                var nodes = parser.get_root().get_array().get_elements();
		
                foreach (unowned Json.Node node in nodes) {
                    string[0] repotag = node.get_object().get_array_member("RepoTags").get_string_element(0).split(":", 2);

                    images += Image() {
                        id 		   = node.get_object().get_string_member("Id"),
                        created_at = (int64) node.get_object().get_int_member("Created"),
                        repository = repotag[0],
                        tag        = repotag[1]
                    };
                }
            } catch (Error e) {

                return images;
            }

            return images;
        }
{'fraction_non_alphanumeric': 0.09200633161851998, 'fraction_numerical': 0.003561535417491096, 'mean_word_length': 1.728008634646519, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2821212', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1242, 'n_words': 288}