If there is no pain to touch the rib area, then you have probably injured your intersostals. These are muscles in between the ribs that help with laboured breathing. When you damage your rib area, you tend to shallow breath. This tightens the intercostals and so when you use them (and stretch them) they cause discomfort.

A couple of exercises for you:-
deep breathing - Take to the point of discomfort, not into pain and gradually increased depth with each breath.

Thoracic rotations - stand with your legs against a secure object e.g a table. Twist to the side maintaining contact with both legs upto discomfort. If you don't get discomfort at the end of range then adda deep breath at this end of range.

Hope they make sense. Be cautious with the gym as you will use these muscles when exercising. You do very gentle cardio and light weights to begin with, then gradually increase as your body lets you.