Over Cosin Squared Integral Show (using complex analysis) that
$$\int_{0}^\pi \frac{d\theta}{(a+\cos\theta)^2} = \frac{\pi.a}{(a^2-1)^{3/2}}$$
I choose a unite semi-circular path C. So I did:
$$z = e^{i.\theta}$$
$$dz = ie^{i\theta}d\theta \rightarrow d\theta = \frac{dz}{iz} = -i\frac{dz}{z}$$
$$\cos\theta = \frac{e^{i\theta} + e^{-iz}}{2} = \frac{z + z^{-1}}{2}$$
$$\int_{0}^\pi \frac{d\theta}{(a+\cos\theta)^2} = -i\int_{C} \frac{dz}{(a + \frac{z+z^{-1}}{2})z} = 8\pi.Res\left[ \frac{1}{z^3 + 4az^2 + (4a^2+1)z +2a}\right]$$ 
I'm not finding roots for the polynomial and I don't know if this is the best way to solve this problem.
 A: $\newcommand{\+}{^{\dagger}}%
 \newcommand{\angles}[1]{\left\langle #1 \right\rangle}%
 \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}%
 \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}%
 \newcommand{\dd}{{\rm d}}%
 \newcommand{\isdiv}{\,\left.\right\vert\,}%
 \newcommand{\ds}[1]{\displaystyle{#1}}%
 \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}%
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}%
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}%
 \newcommand{\ic}{{\rm i}}%
 \newcommand{\imp}{\Longrightarrow}%
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}%
 \newcommand{\pars}[1]{\left( #1 \right)}%
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}%
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}%
 \newcommand{\sech}{\,{\rm sech}}%
 \newcommand{\sgn}{\,{\rm sgn}}%
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}%
 \newcommand{\verts}[1]{\left\vert #1 \right\vert}%
 \newcommand{\yy}{\Longleftrightarrow}$
$\ds{{\cal J}\pars{a} \equiv \int_{0}^{\pi}
     {\dd\theta \over \bracks{a +\cos\pars{\theta}}^{2}}
     = {\pi a \over \pars{a^{2} - 1}^{3/2}}:\ {\large ?}}$
However,
$$
{\cal J}\pars{-a}
=
\int_{0}^{\pi}{\dd\theta \over \bracks{-a + \cos\pars{\theta}}^{2}}
=
\int_{-\pi}^{0}{\dd\theta \over \bracks{-a - \cos\pars{\theta}}^{2}}
=
\int_{0}^{\pi}{\dd\theta \over \bracks{a + \cos\pars{\theta}}^{2}}
=
{\cal J}\pars{a}
$$
Then, ${\cal J}\pars{a}$ is an even function:
$\ds{{\cal J}\pars{a}
     =
     {1 \over 2}\int_{-\pi}^{\pi}{\dd\theta \over \braces{\vphantom{\Large A}\verts{a} + \cos\pars{\theta}}^{2}}}$

\begin{align}
{\cal J}\pars{a}
&=
-\,{1 \over 2}\,\sgn\pars{a}\,\totald{}{a}\int_{0}^{\pi}
{\dd\theta \over \verts{a} + \cos\pars{\theta}}
=
-\,{1 \over 2}\,\sgn\pars{a}\oint_{\verts{z}\ =\ 1}
{1 \over \verts{a} + \bracks{\pars{z + 1/z}/2}}\,{\dd z \over \ic z}
\\[3mm]&=
-\sgn\pars{a}\,\totald{}{a}
\oint_{\verts{z}\ =\ 1}{\dd z/\ic \over z^{2} + 2\verts{a}z + 1}
=
-\sgn\pars{a}\,\totald{}{a}
\oint_{\verts{z}\ =\ 1}{\dd z/\ic \over \pars{z - z_{+}}\pars{z - z_{-}}}
\end{align}

where $z_{\pm}$ are $\pars{z^{2} + 2\verts{a}z + 1}^{-1}$ poles.
$z_{\pm}$ are given by
$z_{\pm} = -\verts{a} \pm \root{a^{2} - 1}$. We assume $\verts{a} > 1$. Then, let $\verts{a} = \cosh\pars{\phi}$, with $\phi > 0$, such that
$$
z_{\pm}
=
-\cosh\pars{\phi} \pm \sin\pars{\phi}
=
\left\lbrace%
\begin{array}{ll}
-\expo{-\phi} & \mbox{if}\ +
\\
-\expo{\phi} & \mbox{if}\ -
\end{array}\right.
$$
It shows that the pole $z_{+}$ is the only one 'inside' the integration contour:
\begin{align}
{\cal J}\pars{a}
&=
-\sgn\pars{a}\,\totald{}{a}2\pi\ic\,{1 \over \ic}\,{1 \over z_{+} - z_{-}}
=
-2\pi\sgn\pars{a}\,\totald{}{a}{1 \over 2\root{a^{2} - 1}}
\\[3mm]&=
-\pi\sgn\pars{a}\,\pars{-\,{1 \over 2}}{1 \over \pars{a^{2} - 1}^{3/2}}\,\pars{2a}
=
\pi\verts{a}{1 \over \pars{a^{2} - 1}^{3/2}}
\end{align}

$$
\color{#0000ff}{\large\int_{0}^{\pi}     {\dd\theta \over \bracks{a +\cos\pars{\theta}}^{2}}
=
{\pi\verts{a} \over \pars{a^{2} - 1}^{3/2}}\,,
\qquad
\verts{a} > 1}
$$

When $\verts{a} \leq 1$, the integral diverges at $\theta_{0}$ where $\cos\pars{\theta_{0}} = -a$. When $\theta \sim \theta_{0}$,
$a + \cos\pars{\theta} = a + \cos\pars{\theta_{0}}\cos\pars{\theta - \theta_{0}} - \sin\pars{\theta_{0}}\sin\pars{\theta - \theta_{0}}
\sim
-\sin\pars{\theta_{0}}\pars{\theta - \theta_{0}}$ such that the integral diverges since there is a non integrable singularity $\sim \pars{\theta - \theta_{0}}^{-2}$.
A: I assume $a > 1$ in the following. For $-1 \leqslant a \leqslant 1$, the integrand would have non-integrable singularities, and for $a < -1$, the given result would have the wrong sign.
To apply the residue theorem we need a closed contour. For the given integral, we could fudge it and take half the sum of the residues in the unit disk for the integral over the semicircle, but I prefer to close it, so using the evenness of the cosine,
$$\int_0^\pi \frac{d\theta}{(a+\cos\theta)^2} = \frac12 \int_{-\pi}^\pi \frac{d\theta}{(a+\cos\theta)^2}$$
to get us an integral over the unit circle. Then we use the substitution you had to obtain
$$\int_0^\pi \frac{d\theta}{(a+\cos\theta)^2} = \frac{1}{2i}\int_{\lvert z\rvert = 1} \frac{1}{\left(a + \frac{z+z^{-1}}{2}\right)^2}\,\frac{dz}{z}.$$
Now you made some mistake I can't figure out when computing the denominator of the integrand.
With
$$\left(a + \frac{z+z^{-1}}{2}\right)(2z) = z^2 + 2az + 1$$
we obtain the two roots
$$\alpha = -a + \sqrt{a^2-1};\quad \beta = -a -\sqrt{a^2-1};$$
of which $\alpha$ lies in the unit disk, and the factorisation $z^2+2az+1 = (z-\alpha)(z-\beta)$.
That gives us
$$\frac{1}{\left(a + \frac{z+z^{-1}}{2}\right)^2z} = \frac{4z}{\left(a + \frac{z+z^{-1}}{2}\right)^2(2z)^2} = \frac{4z}{(z-\alpha)^2(z-\beta)^2}$$
and
$$\begin{align}
\int_0^\pi \frac{d\theta}{(a+\cos\theta)^2} &= \frac{1}{2i}\int_{\lvert z\rvert = 1} \frac{4z}{(z-\alpha)^2(z-\beta)^2}\,dz\\
&= \pi \operatorname{Res}\left(\frac{4z}{(z-\alpha)^2(z-\beta)^2};\, \alpha\right).
\end{align}$$
$\alpha$ is a double pole, so the residue is
$$\left.\frac{d}{dz}\right\rvert_{\alpha} \frac{4z}{(z-\beta)^2} = -\frac{4(\alpha+\beta)}{(\alpha-\beta)^3} = \frac{8a}{(2\sqrt{a^2-1})^3} = \frac{a}{(a^2-1)^{3/2}}.$$
