Add support for bodies other than objects #184
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #183.
TLDR
This adds support for bodies we receive, which are not an object. For example, arrays or plain strings.
Let's say we get the response:
You could now parse this with the following model:
Changes
Up until now all response bodies we parse in ioki-ruby need to be objects (in practice a
Hash
). We now support arrays and basic types (String
, ..) as well.For arrays we need to define an
item_class_name
which specifies the class of the items in the array.For basic types, we only define the type:
Note that even if the response is a basic type or an array, ioki-ruby will always return a model inheriting
Ioki::Model::Base
. This allows for helper methods such asserialize
and also allows access to the etag usingmodel._etag
.New method
#data
which returns the parsed data. For object responses, it returns#attributes
. The#data
method should be used in client applications to get the parsed array response.