iTunes for Mac: Transfer iTunes Store purchases from iPod, iPhone, or iPad - https://support.apple.com/kb/PH19615 - This feature works only for media content (not apps) bought from the iTunes Store. Alternatively: Redownload apps, music, movies, TV shows, and books from the iTunes Store, iBooks Store, and App Store - https://support.apple.com/HT201272
For transferring other items from an i-device to a computer you will have to use third party commercial software. See this document by turingtest2: Recovering your iTunes library from your iPod or iOS device - https://discussions.apple.com/docs/DOC-3991 Even this method may not fully recover what you had in the library originally. For example if in order to save space when syncing you had converted music files to a lower bitrate, or photos to a lower resolution, it is those lower quality files you will recover.