public static function factory($config = array()){
        // Provide a hash of default client configuration options
        $default = array(
            'Accept'=>'application/json',
            'environment'=>'prod',
            'service-description-name' => Client::NAME_SERVICE_API,
            'store' => new FileStore(),
            'ssl'=>false
        );

        $required = array(
            'base_url',
            'client_id',
            'secret',
        );

        // Merge in default settings and validate the config
        $config = Collection::fromConfig($config, $default, $required);

        if($config['environment'] == 'dev' && $config['ssl'] ==  false ){
            $config['ssl.certificate_authority'] = 'system';
            $config['curl.options'] = array(CURLOPT_SSL_VERIFYHOST=>false,CURLOPT_SSL_VERIFYPEER=>false);
        }

        // Create a new ChateaGratis client
        $client = new self($config->get('base_url'),$config);

        $client->authenticateAsGuest = isset($config['as_guest']) ? $config['as_guest'] : false;
        $client->chateaOAuth2Client = $config->get('OAuth2Client');
        $client->store = $config->get('store');
        $client->addSubscriber(new AcceptHeaderPluging($config->toArray()));
        return $client;
    }