*/ class RestClient { private $curl ; private $url ; private $response =""; private $headers = array(); private $method="GET"; private $params=null; private $contentType = null; private $file =null; /** * Private Constructor, sets default options */ private function __construct() { $this->curl = curl_init(); curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($this->curl,CURLOPT_AUTOREFERER,true); // This make sure will follow redirects curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); // This too curl_setopt($this->curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers } /** * Execute the call to the webservice * @return RestClient */ public function execute() { if($this->method === "POST") { curl_setopt($this->curl,CURLOPT_POST,true); curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->params); } else if($this->method == "GET"){ curl_setopt($this->curl,CURLOPT_HTTPGET,true); $this->treatURL(); } else if($this->method === "PUT") { curl_setopt($this->curl,CURLOPT_PUT,true); $this->treatURL(); $this->file = tmpFile(); fwrite($this->file,$this->params); fseek($this->file,0); curl_setopt($this->curl,CURLOPT_INFILE,$this->file); curl_setopt($this->curl,CURLOPT_INFILESIZE,strlen($this->params)); } else { curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$this->method); } if($this->contentType != null) { curl_setopt($this->curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this->contentType)); } curl_setopt($this->curl,CURLOPT_URL,$this->url); $r = curl_exec($this->curl); $this->treatResponse($r); // Extract the headers and response return $this ; } /** * Treats URL */ private function treatURL(){ if(is_array($this->params) && count($this->params) >= 1) { // Transform parameters in key/value pars in URL if(!strpos($this->url,'?')) $this->url .= '?' ; foreach($this->params as $k=>$v) { $this->url .= "&".urlencode($k)."=".urlencode($v); } } return $this->url; } /* * Treats the Response for extracting the Headers and Response */ private function treatResponse($r) { if($r == null or strlen($r) < 1) { return; } $parts = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body while(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0]) or preg_match("@Moved@",$parts[0])) { // Continue header must be bypass for($i=1;$iheaders['content-type'] = $reg[1]; preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message $this->headers['code'] = $reg[1]; $this->headers['message'] = $reg[2]; $this->response = ""; for($i=1;$i 1) { $this->response .= "\n\r"; } $this->response .= $parts[$i]; } } /* * @return array */ public function getHeaders() { return $this->headers; } /* * @return string */ public function getResponse() { return $this->response ; } /* * HTTP response code (404,401,200,etc) * @return int */ public function getResponseCode() { return (int) $this->headers['code']; } /* * HTTP response message (Not Found, Continue, etc ) * @return string */ public function getResponseMessage() { return $this->headers['message']; } /* * Content-Type (text/plain, application/xml, etc) * @return string */ public function getResponseContentType() { return $this->headers['content-type']; } /** * This sets that will not follow redirects * @return RestClient */ public function setNoFollow() { curl_setopt($this->curl,CURLOPT_AUTOREFERER,false); curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false); return $this; } /** * This closes the connection and release resources * @return RestClient */ public function close() { curl_close($this->curl); $this->curl = null ; if($this->file !=null) { fclose($this->file); } return $this ; } /** * Sets the URL to be Called * @return RestClient */ public function setUrl($url) { $this->url = $url; return $this; } /** * Set the Content-Type of the request to be send * Format like "application/xml" or "text/plain" or other * @param string $contentType * @return RestClient */ public function setContentType($contentType) { $this->contentType = $contentType; return $this; } /** * Set the Credentials for BASIC Authentication * @param string $user * @param string $pass * @return RestClient */ public function setCredentials($user,$pass) { if($user != null) { curl_setopt($this->curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($this->curl,CURLOPT_USERPWD,"{$user}:{$pass}"); } return $this; } /** * Set the Request HTTP Method * For now, only accepts GET and POST * @param string $method * @return RestClient */ public function setMethod($method) { $this->method=$method; return $this; } /** * Set Parameters to be send on the request * It can be both a key/value par array (as in array("key"=>"value")) * or a string containing the body of the request, like a XML, JSON or other * Proper content-type should be set for the body if not a array * @param mixed $params * @return RestClient */ public function setParameters($params) { $this->params=$params; return $this; } /** * Creates the RESTClient * @param string $url=null [optional] * @return RestClient */ public static function createClient($url=null) { $client = new RestClient ; if($url != null) { $client->setUrl($url); } return $client; } /** * Convenience method wrapping a commom POST call * @param string $url * @param mixed params * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default * @return RestClient */ public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { return self::call("POST",$url,$params,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom PUT call * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { return self::call("PUT",$url,$body,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom GET call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function get($url,array $params=null,$user=null,$pwd=null) { return self::call("GET",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom delete call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function delete($url,array $params=null,$user=null,$pwd=null) { return self::call("DELETE",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom custom call * @param string $method * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { return self::createClient($url) ->setParameters($body) ->setMethod($method) ->setCredentials($user,$pwd) ->setContentType($contentType) ->execute() ->close(); } } ?> Sources du contenu du site

Sources du contenu du site

American Psychological Association. 2009. Report of the American Psychological Association Task Force on Appropriate Therapeutic Responses to Sexual Orientation. En ligne. 130 p. <http://www.apa.org/pi/lgbt/resources/therapeutic-response.pdf>.

Brotman, Shari, Bill Ryan, Yves Jalbert et Bill Rowe. 2002. « The Impact of Coming Out on Health and Health Care Access: The Experiences of Gay, Lesbian, Bisexual and Two-Spirit People ». Journal of Health & Social Policy. Vol. 15, no 1, p.1-29.

Chamberland, Line, Frédérick Gagné et Johanne Paquin. s.d. L’homoparentalité au Québec : les changements législatifs et leurs impacts dans la sphère du travail. 9 p. <www.cqgl.ca/uploads/files/APGLArticle02-01-2006.doc>.

Chamberland, Line, Gilbert Émond, Michaël Bernier, Gabrielle Richard, Marie-Pier Petit, Marilyne Chevrier, Bill Ryan, Joanne Otis et Danielle Julien. 2011.  L’homophobie  à l’école secondaire au Québec. Portrait de la situation, impacts et pistes de solution, Rapport de recherche, Montréal, Université du Québec à Montréal.

Charbonnier, Élodie et Pierluigi Graziani. 2012. « Les stratégies de coping que les jeunes homosexuels mettent en place lors de la divulgation de leur homosexualité ». Journal de Thérapie Comportementale et Cognitive. Vol. 22, no. 1, p.24-31.

Coalition jeunesse montréalaise de lutte à l’homophobie. 2005. ORIENTATION SEXUELLE & HOMOPHOBIE : Mieux intervenir auprès des jeunes. Guide de ressources et de sensibilisation. En ligne. 57 p. <http://crips.cirm-crips.org/crips/dossiers/op/CoalitionJeunesse_Guide_vFR_Optimale.pdf>.

Commission des droits de la personne et des droits de la jeunesse. 2011 (30 mars). «Module en ligne – Homophobie à l’école – CDPDJ – presentation». In CDPDJ : Accueil. En ligne. <http://www.cdpdj.qc.ca/former/modules/module-homophobie/Pages/presentation.html>.

Fondation Émergence. s.d. «Journée internationale contre l’homophobie – – > Définitions». In Journée internationale contre l’homophobie – – > Bienvenue sur www.homophobie.org ». En ligne. < http://homophobie.org/default.aspx?scheme=1027>.

Gai écoute. s.d Foire aux questions. En ligne. 43 p. <http://www.gai-ecoute.qc.ca/utilisateur/documents/gaiecoute/faq.pdf>.

GRIS-Montréal (Irène Demczuk). 2003. Démystifier l’homosexualité, ça commence à l’école : Mieux comprendre l’homosexualité pour prévenir l’homophobie. Guide pédagogique, Montréal, Québec, 120 p.

Institut national de santé publique du Québec. 2011. Guide du participant de la formation Pour une nouvelle vision de l’homosexualité. 305 p.

Institut national de santé publique du Québec. 2011. Guide du participant de la formation Adapter nos interventions aux réalités homosexuelles et bisexuelles, 243 p.

Juster, Robert-Paul, Nathan Grant Smith, Émilie Ouellet, Shireen Sindi et Sonia J. Lupien. 2013. « Sexual Orientation and Disclosure in Relation to Psychiatric Symptoms, Diurnal Cortisol, and Allostatic Load ». Psychosomatic Medicine. Vol. 75, p.103-116.

Ministère de la Justice du Québec. 2009. Politique Québécoise de lutte contre l’homophobie. 41 p. <http://www.justice.gouv.qc.ca/francais/publications/rapports/pdf/
homophobie.pdf>.

Petit, Marie-Pier, Line Chamberland, Gabrielle Richard et Marilyne Chevrier. 2011. « Jeunes de minorités sexuelles victimes d’homophobie en milieu scolaire: quels facteurs de protection? ». Revue canadienne de santé mentale communautaire. Vol. 30, no 2, p.13-29.

Rosario, Margaret, Eric W. Schrimshaw et Joyce Hunter. 2009. « Disclosure of sexual orientation and subsequent substance use and abuse among lesbian, gay, and bisexual youths: Critical role of disclosure reactions ». Psychology of Addictive Behaviors. Vol. 23, no 1, p. 175-184.

Roussy, Alain et François-Robert Rail. 2011. « L’homoparentalité, faits et croyances ». Psychologie Québec. En ligne. Vol. 28, no 6, p.28-31. <http://ordrepsy.qc.ca/pdf/Psy_Qc_Nov2011_Dossier_04_Rail_Roussy.pdf>.

Tellier, Pierre-Paul. 2007. Conseiller l’adolescent homosexuel qui se présenter au cabinet. En ligne. 6 p. <http://www.fmoq.org/Lists/FMOQDocumentLibrary/fr/Le%20M%C3%A9deci
n%20du%20Qu%C3%A9bec/Archives/2000%20-%202009/081-086DrTellier0407.pdf>.

Willoughby, Brian L. B., Neena M. Malik et Kristin M. Lindahl. 2006. « Parental Reactions to Their Sons’ Sexual Orientation Disclosures: The Roles of Family Cohesion, Adaptability, and Parenting Style». Psychology of men and masculinity, Vol. 7, no 1, p. 14-26.

World Health Organization (WHO). 2011 (17 mai). «WHO/Europe | HIV/AIDS – Stop discrimination against homosexual men and women». In WHO/Europe | World Health Organization Regional Office for Europe. En ligne. <http://www.euro.who.int/en/what-we-do/health-topics/communicable-diseases/hivaids/news/news/2011/5/stop-discrimination-against-homosexual-men-and-women>.