Move V2 API payloads to travis-api
Merge pull request #369 from travis-ci/ps-move-payloads-to-api

Move V2 API payloads to travis-api
Add Repository::Settings::Collection and Repository::Settings::Model

This is a first stab at structuring settings API. Model and Collection
will be used in Settings to save and load data for given type (like
ssh_keys or notifications). This will allow us to keep the clean API on
top of settings without tieing us closely with underlying
representation.
Allow to pass key and use_prefix as options to EncryptedColumn
Improvements to models and collections for settings

This commit adds encryption and vaildation to models. It also gives
ability to register collections on settings, so they can be serialized
into JSON before saving settings.
Extract common behavior to OverwritableMethodDefinitions module
Move classes from Repository::Settings to separate files
Add Repository::Settings::Model#update method
Allow loading models for settings from JSON

In order to not process values passed to a model twice (for example not
to encrypt a value twice) we need a method to load raw attributes into
the model
Save collections on #save method in settings
Add Settings::Collection#find and Settings::Collection#destroy
Don't coerce nil values for models in settings
Add getters for validation and serialization to settings model
Fix settings specs
Attach ssh_keys to worker payload
Return only basic settings as hash and remove unneeded stuff in settings
Use const_get rather than constantize

For some reason self.name in Travis::Api returns something like this in
some circumstances:

    >> Travis::Api.name
    => "#<Class:0x007f0bef9b0328>::Travis::Api"

I couldn't reproduce it in tests, but version from this commit should be
equivalent (all tests pass) and it works without the problem mentioned
above.

This commit also uses const_defined? instead of rescuing.