README.md in json_api_client-1.11.0 vs README.md in json_api_client-1.12.0

- old
+ new

@@ -1,10 +1,10 @@ # JsonApiClient [![Build Status](https://travis-ci.org/JsonApiClient/json_api_client.png)](https://travis-ci.org/JsonApiClient/json_api_client) [![Code Climate](https://codeclimate.com/github/JsonApiClient/json_api_client.png)](https://codeclimate.com/github/JsonApiClient/json_api_client) [![Code Coverage](https://codeclimate.com/github/JsonApiClient/json_api_client/coverage.png)](https://codeclimate.com/github/JsonApiClient/json_api_client) This gem is meant to help you build an API client for interacting with REST APIs as laid out by [http://jsonapi.org](http://jsonapi.org). It attempts to give you a query building framework that is easy to understand (it is similar to ActiveRecord scopes). -*Note: master is currently tracking the 1.0.0 specification. If you're looking for the older code, see [0.x branch](https://github.com/chingor13/json_api_client/tree/0.x)* +*Note: master is currently tracking the 1.0.0 specification. If you're looking for the older code, see [0.x branch](https://github.com/JsonApiClient/json_api_client/tree/0.x)* ## Usage You will want to create your own resource classes that inherit from `JsonApiClient::Resource` similar to how you would create an `ActiveRecord` class. You may also want to create your own abstract base class to share common behavior. Additionally, you will probably want to namespace your models. Namespacing your model will not affect the url routing to that resource. @@ -472,10 +472,18 @@ # will use the customized connection end end ``` +##### Server errors handling + +Non-success API response will cause the specific `JsonApiClient::Errors::SomeException` raised, depends on responded HTTP status. +Please refer to [JsonApiClient::Middleware::Status#handle_status](https://github.com/JsonApiClient/json_api_client/blob/master/lib/json_api_client/middleware/status.rb) +method for concrete status-to-exception mapping used out of the box. + +JsonApiClient will try determine is failed API response JsonApi-compatible, if so - JsonApi error messages will be parsed from response body, and tracked as a part of particular exception message. In additional, `JsonApiClient::Errors::ServerError` exception will keep the actual HTTP status and message within its message. + ##### Custom status handler You can change handling of response status using `connection_options`. For example you can override 400 status handling. By default it raises `JsonApiClient::Errors::ClientError` but you can skip exception if you want to process errors from the server. You need to provide a `proc` which should call `throw(:handled)` default handler for this status should be skipped. @@ -567,20 +575,20 @@ ### Custom Paginator You can customize how your resources find pagination information from the response. -If the [existing paginator](https://github.com/chingor13/json_api_client/blob/master/lib/json_api_client/paginating/paginator.rb) fits your requirements but you don't use the default `page` and `per_page` params for pagination, you can customise the param keys as follows: +If the [existing paginator](https://github.com/JsonApiClient/json_api_client/blob/master/lib/json_api_client/paginating/paginator.rb) fits your requirements but you don't use the default `page` and `per_page` params for pagination, you can customise the param keys as follows: ```ruby JsonApiClient::Paginating::Paginator.page_param = "number" JsonApiClient::Paginating::Paginator.per_page_param = "size" ``` Please note that this is a global configuration, so library authors should create a custom paginator that inherits `JsonApiClient::Paginating::Paginator` and configure the custom paginator to avoid modifying global config. -If the [existing paginator](https://github.com/chingor13/json_api_client/blob/master/lib/json_api_client/paginating/paginator.rb) does not fit your needs, you can create a custom paginator: +If the [existing paginator](https://github.com/JsonApiClient/json_api_client/blob/master/lib/json_api_client/paginating/paginator.rb) does not fit your needs, you can create a custom paginator: ```ruby class MyPaginator def initialize(result_set, data); end # implement current_page, total_entries, etc @@ -678,6 +686,6 @@ Ideally, the PR has 2 commits - the first showing the failed test and the second with the fix - although this is not required. The commits will be squashed into master once accepted. ## Changelog -See [changelog](https://github.com/chingor13/json_api_client/blob/master/CHANGELOG.md) +See [changelog](https://github.com/JsonApiClient/json_api_client/blob/master/CHANGELOG.md)