{"action":"created","issue":{"url":"https://api.github.com/repos/KPull/Bastion/issues/44","repository_url":"https://api.github.com/repos/KPull/Bastion","labels_url":"https://api.github.com/repos/KPull/Bastion/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/KPull/Bastion/issues/44/comments","events_url":"https://api.github.com/repos/KPull/Bastion/issues/44/events","html_url":"https://github.com/KPull/Bastion/issues/44","id":188346241,"number":44,"title":"Unintuitive `bind` functionality","user":{"login":"KPull","id":5477536,"avatar_url":"https://avatars.githubusercontent.com/u/5477536?v=3","gravatar_id":"","url":"https://api.github.com/users/KPull","html_url":"https://github.com/KPull","followers_url":"https://api.github.com/users/KPull/followers","following_url":"https://api.github.com/users/KPull/following{/other_user}","gists_url":"https://api.github.com/users/KPull/gists{/gist_id}","starred_url":"https://api.github.com/users/KPull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KPull/subscriptions","organizations_url":"https://api.github.com/users/KPull/orgs","repos_url":"https://api.github.com/users/KPull/repos","events_url":"https://api.github.com/users/KPull/events{/privacy}","received_events_url":"https://api.github.com/users/KPull/received_events","type":"User","site_admin":false},"labels":[{"id":374050639,"url":"https://api.github.com/repos/KPull/Bastion/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/KPull/Bastion/milestones/4","html_url":"https://github.com/KPull/Bastion/milestones/0.4-BETA","labels_url":"https://api.github.com/repos/KPull/Bastion/milestones/4/labels","id":2117058,"number":4,"title":"0.4-BETA","description":"","creator":{"login":"KPull","id":5477536,"avatar_url":"https://avatars.githubusercontent.com/u/5477536?v=3","gravatar_id":"","url":"https://api.github.com/users/KPull","html_url":"https://github.com/KPull","followers_url":"https://api.github.com/users/KPull/followers","following_url":"https://api.github.com/users/KPull/following{/other_user}","gists_url":"https://api.github.com/users/KPull/gists{/gist_id}","starred_url":"https://api.github.com/users/KPull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KPull/subscriptions","organizations_url":"https://api.github.com/users/KPull/orgs","repos_url":"https://api.github.com/users/KPull/repos","events_url":"https://api.github.com/users/KPull/events{/privacy}","received_events_url":"https://api.github.com/users/KPull/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":3,"state":"open","created_at":"2016-11-06T10:43:37Z","updated_at":"2016-11-09T20:36:56Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2016-11-09T20:36:38Z","updated_at":"2016-11-09T20:38:04Z","closed_at":null,"body":"Bastion users have reported that `bind()` does not work very intuitively. In particular, the following request fails (assuming the server returns content-type `application/json`):\r\n\r\n```java\r\nString data = Bastion.request(\"Create Sushi Request\", new CreateSushiRequest())\r\n                .bind(String.class)\r\n                .withAssertions((statusCode, response, model) -> {\r\n                    assertThat(statusCode).isEqualTo(201);\r\n                }).call().getModel();\r\n```\r\n\r\nA user would expect that all the HTTP response entity data will be available as a `String`. Right now though, since the content-type is `application/json`, Bastion creates a *single* `ObjectNode` model and cannot return a `String`.\r\n\r\nHere's my idea (looking for feedback):\r\n\r\nBastion will register a number of `ResponseDecoder`s (as it does now). Each `ResponseDecoder` may return a view object (they could return nothing). These views will be constructed by parsing the HTTP response entity data into various objects. For example, the following response decoders:\r\n\r\n* `ObjectNodeResponseDecoder` - Returns an `ObjectNode` if the HTTP response content-type is `application/json`.\r\n* `JsonObjectMapperResponseDecoder` - If the content-type is JSON, takes the object type inside the `DecodingHints` object and attempts to parse the HTTP response into an instance of that object type.\r\n* `YamlObjectMapperResponseDecoder` - Same as above, but for YAML.\r\n* `ProtobufObjectMapperResponseDecoder` - Same as above, but for Protobuf binary data.\r\n* `MapResponseDecoder` - Provides a map representation if the response is a collection of key/value pairs (eg. Form URL encoded data).\r\n* `ImageResponseDecoder` - If the content-type is an image, this will return an `Image` object\r\n* `StringResponseDecoder` - Provides a `String` view of the HTTP response entity regardless of the content-type.\r\n* ... and so on.\r\n\r\nNow, `bind()` will assert whether a view of the given type exists in the Response. This view will be provided to the `Assertions` when the assertions are executed. Furthermore, after the `call()` method, the user may:\r\n\r\n* Call `getModel()` to retrieve the view specified in `bind()` earlier.\r\n* Call `getView()`, providing the view object type which the user wants.\r\n* Call `getResponse()`, which returns the HTTP response representation. The user may then call `getModel()` and `getView()` on the response object itself which will behave just like the above two methods.\r\n\r\nAll this allows us to extend for new future views simply by implementing more `ResponseDecoder`s and it also frees us from having to decide (and guess) which *single* `ResponseDecoder` the user wants us to execute to get the bound model."},"comment":{"url":"https://api.github.com/repos/KPull/Bastion/issues/comments/259519881","html_url":"https://github.com/KPull/Bastion/issues/44#issuecomment-259519881","issue_url":"https://api.github.com/repos/KPull/Bastion/issues/44","id":259519881,"user":{"login":"KPull","id":5477536,"avatar_url":"https://avatars.githubusercontent.com/u/5477536?v=3","gravatar_id":"","url":"https://api.github.com/users/KPull","html_url":"https://github.com/KPull","followers_url":"https://api.github.com/users/KPull/followers","following_url":"https://api.github.com/users/KPull/following{/other_user}","gists_url":"https://api.github.com/users/KPull/gists{/gist_id}","starred_url":"https://api.github.com/users/KPull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KPull/subscriptions","organizations_url":"https://api.github.com/users/KPull/orgs","repos_url":"https://api.github.com/users/KPull/repos","events_url":"https://api.github.com/users/KPull/events{/privacy}","received_events_url":"https://api.github.com/users/KPull/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T20:38:04Z","updated_at":"2016-11-09T20:38:04Z","body":"@tyrone-grech might want to provide some feedback on the above."}}
{"actor":{"display_login":"KPull"}}