There's only one rule. Really. It comes down to this: make her feel good.
You get a girl by making her feel good. And you keep a girl by making her feel good. You can be a drug and sex addict, but as long as you're making her laugh, you're golden.
Women evaluate relationships and men based on how the relationship (or the man) makes her feel.
If she says she "needs space" - it means she's found someone or something else who's making her feel better.
If she says "let's just be friends" - it means that you're not making her feel that way anymore.
It's all about how she feels. Don't take it personally. Feelings come and go like the wind.
And of course, the trick that no man has ever figured out and probably never will, is how to keep her feeling good forever. Hell, that was never our job in the first place;-)
But don't fret, every guy gets the cold shoulder. In the meantime, here are some tricks you can use to delay the inevitable:
1. Conversations should be 70% about her life and her feelings, 30% yours
2. Make her laugh (jokes are good from time to time)
3. Keep things light
4. Tease her (done correctly, this spikes her buying temperature)
5. Sprinkle some sarcasm like that fairy dust they all seem to like
6. Stay away from logic (and debates)
7. Use cocky humor to remind her who's boss in a non-threatening way
8. Keep her guessing (don't ever let her think she's won you completely over)
9. Make her earn your attention (really, this is what she wants deep down)
10. Flaunt your social value (assuming you have some) in controlled settings (helps to take her around people who respect you)