Integrating $\frac1{a+b\cos(x)}$ using $e^{ix}$ In calculus class our teacher demonstrated us the evaluation of the definite integral $\int_0^\pi \dfrac{1}{a+b\cos(x)}dx=\dfrac{\pi}{\sqrt{a^2-b^2}}$, for $a\ne 0, b \ne 0, |\dfrac ba \lt 1|$, but there's a part I could not grasp.
Our teacher started out by setting up an equality: $bz^2+2az+b=b(z-\alpha)(z-\beta)$, where $\alpha, \beta$ are the roots of the expression on the LHS in $\Bbb C$, and $\alpha$ takes on the value with a negative sign before the radical, while $\beta$ is the other one. Letting $z=e^{ix}$, the integrand is transformed into the following form:
$\dfrac{1}{\sqrt{a^2-b^2}}\left(\dfrac{\alpha}{\alpha-e^{ix}}-\dfrac{\beta}{e^{ix}-\beta}\right)=\dfrac{1}{\sqrt{a^2-b^2}}\left(\dfrac{1}{\alpha e^{-ix}-1}+\dfrac{1}{1-\beta e^{-ix}}\right)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=0}^{\infty}(\beta^n-\alpha^n)e^{-inx}=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=1}^{\infty}(\beta^n-\alpha^n)(\cos(nx)-i\sin(nx))$
But then $\int_0^\pi \cos(nx)-i\sin(nx) dx=\dfrac 1n(\sin(nx)+i\cos(nx))|_0^\pi=\dfrac in(\cos(n\pi)-1)$ and I was completely lost on how the next part was carried out. For if we substitute that back into the infinite sum, we get that integrated version of that expression would be $\dfrac{1}{\sqrt{a^2-b^2}}\sum_{n=1}^{\infty}(\beta^n-\alpha^n)\dfrac in(\cos(n\pi)-1)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{k=1}^{\infty}(\beta^{2k-1}-\alpha^{2k-1})\dfrac {i}{2k-1}(\cos((2k-1)\pi)-1)$
$=\dfrac{1}{\sqrt{a^2-b^2}}\sum_{k=1}^{\infty}(\beta^{2k-1}-\alpha^{2k-1})\dfrac {-2i}{2k-1}$
Yet I fail to see how this could lead to the supposed final result, especially with that $i$ there.

In the given method, the fractions of the form $\dfrac1{1+z}$ are developed using Taylor, then integrated term-wise. Doing that, you retrieve the series for $\log(1+x)$, which are applied to $\alpha$ and $\beta$.
As the roots are complex, the computation of the logarithms is a little involved. In the end, only an imaginary number remains, which gets multiplied by $i$, resulting in a real.

A simpler way:
WLOG, $b=1$, and $|a|>1$. Let $z:=e^{ix}$ so that $\cos x=\dfrac{z+z^{-1}}2$ and $dz=iz\,dx$.
Then
$$\int_0^\pi\frac{dx}{a+\cos x}=-\int_1^{-1}\frac{2i\,dz}{2az+z^2+1}=-\int_1^{-1}\frac{2i\,dz}{(z+a)^2-(a^2-1)}.$$ (The complex integral is over a half circle.)
The antiderivative is readily found to be 
$$-\frac ic(\log(z+a-c)-\log(z+a+c))$$ where $c=\sqrt{a^2-1}$. We have
$$\frac{(1+a-c)(-1+a+c)}{(1+a+c)(-1+a-c)}=\frac{a^2-(c-1)^2}{a^2-(c+1)^2}=-1.$$ so that the logarithm is just $i\pi$ and the integral is
$$\frac\pi c.$$
Now for general $b$ we divide by $b$ and get
$$\frac\pi{bc}=\frac\pi{\sqrt{a^2-b^2}}.$$
