My solution of this integral does not match. Where am I doing wrong? I've been trying to calculate the following integral. But I always get the wrong result....
$$
S(a, b) = \int_0^{2\pi}\frac{d\theta}{\left(a + b\cos\theta\right)^2},
\quad\quad\quad\mbox{for}\quad a > b > 0
$$

Assume substitution: $z = e^{i\theta}$. Then:
$
\displaystyle\cos\theta = \frac{1}{2}\left(e^{i\theta} + e^{-i\theta}\right) =
\frac{1}{2}\left(z + \frac{1}{z}\right)
$.
Also, $dz = ie^{i\theta} d\theta = izd\theta$.
This is what I do:
$$
\int_0^{2\pi}\frac{d\theta}{a + b\cos\theta} = 
\oint_{|z|=1}\frac{dz}{iz\left[a + \frac{b}{2}\left(z + \frac{1}{z}\right)\right]^2} = 
\frac{1}{i}\oint_{|z|=1}\frac{4zdz}{\left[2az + b z^2 + b\right]^2}
$$
Singularities:
$$
2az + bz^2 + b = 0 \\
z_{\pm} = \frac{-a}{b} \pm\frac{1}{b}\sqrt{a^2 - b^2}
$$
Residues:
$$
Res_{z=z_{+}}\left\{\frac{4z}{\left[2az + b z^2 + b\right]^2}\right\} =
\frac{1}{2\pi i}\oint_{\gamma+}\frac{4zdz}{(z-z_+)^2(z-z_-)^2} = 
\frac{d}{dz}\left[\frac{4z}{(z-z_-)^2}\right]_{z = z_+} \\
Res_{z=z_{+}}\left\{\frac{4z}{\left[2az + b z^2 + b\right]^2}\right\} =
4\left[\frac{1}{(z_+-z_-)^2} - \frac{2z_+}{(z_+-z_-)^3}\right] \\
Res_{z=z_-}\left\{\frac{4z}{\left[2az + b z^2 + b\right]^2}\right\} =
4\left[\frac{1}{(z_--z_+)^2} - \frac{2z_-}{(z_--z_+)^3}\right]
$$
Where $\gamma+$ is the contour centered at $z_+$ with small radius $\epsilon$. We know:
$$
\int_0^{2\pi}\frac{d\theta}{\left(a + b\cos\theta\right)^2} = 
\frac{1}{i}\oint_{|z|=1}\frac{4zdz}{\left[az + b z^2 + b\right]^2} = 
2\pi \sum_n Res_{z = z_n}\left\{\frac{4z}{\left[2az + b z^2 + b\right]^2}\right\}
$$
Where $z_n$ are all isolated singularities inside unit circle $|z|=1$. If $I(z)$ is an indicator function of the interior of the unit circle:
$$
S(a, b) = 4I(z_+)\left[\frac{1}{(z_+-z_-)^2} - \frac{2z_+}{(z_+-z_-)^3}\right] + 
4I(z_-)\left[\frac{1}{(z_--z_+)^2} - \frac{2z_-}{(z_--z_+)^3}\right]
$$

When $b=1$ this seems to work for all values of $a$ that I've tested. But, if $b\neq 1$ it does not work... I tried to find a mistake somewhere, but I see none.
For instance, if $a=8$ and $b=2$, I find:
$$
z_+ = 0.127017 \\
z_- = -7.87298 \\
Res_{z=z_+} = 0.068853 \\
S = 0.432616
$$
But the integral is $0.108154$ instead of $0.432616$. Where is wrong?

Notice that $S(a,b)$ can be computed from a symmetry argument only. We have
$$\begin{eqnarray*} S(a,b)=2\int_{0}^{\pi}\frac{d\theta}{(a-b\cos\theta)^2}&=&2\int_{-\pi/2}^{\pi/2}\frac{d\theta}{(a+b\sin\theta)^2}\\&=&2\int_{0}^{\pi/2}\left[\frac{1}{(a-b\sin\theta)^2}+\frac{1}{(a+b\sin\theta)^2}\right]\,d\theta\\&=&4\int_{0}^{\pi/2}\frac{a^2+b^2\sin^2\theta}{(a^2-b^2\sin^2\theta)^2}\,d\theta\end{eqnarray*}$$
and by setting $\theta=\arctan t$,
$$ S(a,b) = 2\int_{-\infty}^{+\infty}\frac{a^2(1+t^2)+b^2 t^2}{(a^2(1+t^2)-b^2 t^2)^2}=\color{red}{\frac{2\pi a}{(a^2-b^2)^{3/2}}}$$
where the last equality is a simple consequence of the residue theorem.
