Small code cleanup and moving files from app to lib

Mostly to fix a dependency issue I was getting when trying to test openstax_api.
But you have a rails dependency for this gem in the gemspec `s.add_dependency "rails", ">= 3.1"` so it will always be used. I think?