Some of the posters have mentioned it above but the easiest two ways to keep someone from attacking you: (1) encase your town center and resource stockhouses in defenses -- multiple towers, garrisons, catapults, walls, caltrops and spikes -- and (2) spend as much of your resources as possible before you take an extended break from the game. Since 150 gold is basically nothing, it's easier to just take a pass on your nation if it looks like it'll be a pain in the ass to destroy.
Additionally, almost all of the times I've been attacked were revenge opportunities. You attack someone, they get pissed off and attack back. If you're laying low and playing your defense smart, I can definitely see never getting attacked.