How to solve this integral using the method of residues?

By the substitution $\theta=2\varphi$ and the cosine duplication formula we have

$$ I = \int_{0}^{\pi}\frac{d\theta}{(3+2\cos\theta)^2} = 2\int_{0}^{\pi/2}\frac{d\varphi}{(1+4\cos^2\varphi)^2} \tag{1}$$ and by the substitution $\varphi=\arctan t$ the problem boils down to evaluating $$ 2\int_{0}^{+\infty}\frac{(1+t^2)}{(5+t^2)^2}\,dt = \int_{-\infty}^{+\infty}\frac{(1+t^2)}{(5+t^2)^2}\,dt.\tag{2}$$ The meromorphic function $f(t)=\frac{(1+t^2)}{(5+t^2)^2}$ has a double pole at $t=\pm i\sqrt{5}$ and behaves like $\frac{1}{t^2}$ for $|t|\to +\infty$. By the residue theorem it follows that:

$$ I = 2\pi i\,\text{Res}(f(t),t=i\sqrt{5}) =2\pi i\lim_{t\to i\sqrt{5}}\frac{d}{dt}\frac{(1+t^2)}{(t+i\sqrt{5})^2}=\color{red}{\frac{3\pi}{5\sqrt{5}}}\tag{3}$$ as wanted, after a straightforward computation.


There also is a simple geometric approach. $\rho(\theta)=\frac{p}{1+\varepsilon\cos\theta}$ is the polar equation of an ellipse with respect to a focus. Since the area in polar coordinates is given by $\frac{1}{2}\int_{0}^{2\pi}\rho(\theta)^2\,d\theta$, $I$ just depends on the area of an ellipse ($\pi ab $) with a given eccentricity and a given semi-latus rectum. This proves the more general $$ \int_{0}^{\pi}\frac{d\theta}{(u+v\cos\theta)^2} = \frac{\pi u}{\left(u^2-v^2\right)^{3/2}} \tag{4}$$ as soon as $0<v<u$.


Note $$\int_0^{\pi} \frac{d \theta}{(3+2cos \theta)^2} = \frac12\int_0^{2\pi} \frac{d \theta}{(3+2cos \theta)^2}.$$ Let $z=e^{i\theta}$ and hence one has \begin{eqnarray} &&\int_0^{\pi} \frac{d \theta}{(3+2cos \theta)^2}\\ &=&\frac12\int_0^{2\pi} \frac{d \theta}{(3+2cos \theta)^2}\\ &=&\frac12\int_{|z|=1}\frac{1}{(3+z+z^{-1})^2}\frac{dz}{iz}\\ &=&\frac12\int_{|z|=1}\frac{z}{(z^2+3z+1)^2}dz\\ &=&\pi\text{Res}(f(z),z=\frac{1}{2}(-3+\sqrt5))\\ &=& \frac{3 \pi \sqrt{5}}{25} \end{eqnarray} where $f(z)=\frac{z}{(z^2+3z+1)^2}$ has a pole at $z=\frac{1}{2}(-3+\sqrt5)$.