<commit_before># FunWithJsonApi
[![Build Status](https://travis-ci.org/bmorrall/fun_with_json_api.svg?branch=master)](https://travis-ci.org/bmorrall/fun_with_json_api)

## Deserializer


### Attribute Types

| Attribute Type      | Format      | Ruby Object        | Example                       |
| ------------------- | ----------- | -------------      | ----------------------------- |
| string              | :string     | String             | 'Lorem ipsum dolor sit amet.. |
| text                | :string     | String             | 'Lorem ipsum dolor sit amet.. |
| boolean             | :boolean    | Boolean.TRUE/FALSE | true, false                   |
| date                | :date       | Date               | '2016-03-12'                  |
| datetime (ISO 8601) | :datetime   | DateTime           | '2016-03-12T16:33:17+11:00'   |
| decimal             | :decimal    | BigDecimal         | 123.45                        |
| float               | :float      | Float              | 12.34                         |
| integer             | :integer    | Integer            | 12                            |

## Exceptions

FunWithJsonApi includes a `render_fun_with_json_api_exception` helper method,<commit_msg>Updated readme [skip ci]<commit_after># FunWithJsonApi
[![Build Status](https://travis-ci.org/bmorrall/fun_with_json_api.svg?branch=master)](https://travis-ci.org/bmorrall/fun_with_json_api)

## Deserializer

With a User Deserializer:

```
class UserDeserializer < FunWithJsonApi::Deserializer
  type 'people'
  resource_class User
end
```

and a Article Deserializer:

```
class ArticlesDeserializer
  resource_class Article

  attribute :title

  has_one :author, -> { UserDeserializer }
end
```

Calling `FunWithJsonApi.deserialize(params, ArticlesDeserializer)` within a controller,
will convert:

```
{
  "type": "articles",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "relationships": {
    "author": {
      "data": { "type": "people", "id": "9" }
    }
  }
}
```

Into parameters than can create/update a `Article`:

```
{
  title: "Rails is Omakase",
  author_id: 9
}
```

With a sprinking of json_api validation, and a lot of semantically correct json api error responses.

### Attribute Types

| Attribute Type      | Format      | Ruby Object        | Example                       |
| ------------------- | ----------- | -------------      | ----------------------------- |
| string              | :string     | String             | 'Lorem ipsum dolor sit amet.. |
| text                | :string     | String             | 'Lorem ipsum dolor sit amet.. |
| boolean             | :boolean    | Boolean.TRUE/FALSE | true, false                   |
| date                | :date       | Date               | '2016-03-12'                  |
| datetime (ISO 8601) | :datetime   | DateTime           | '2016-03-12T16:33:17+11:00'   |
| decimal             | :decimal    | BigDecimal         | 123.45                        |
| float               | :float      | Float              | 12.34                         |
| integer             | :integer    | Integer            | 12                            |

## Exceptions

FunWithJsonApi includes a `render_fun_with_json_api_exception` helper method,
{'fraction_non_alphanumeric': 0.15289765721331688, 'fraction_numerical': 0.025893958076448828, 'mean_word_length': 1.4564723694171082, 'pattern_counts': {'":': 8, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2156884', 'n_tokens_mistral': 978, 'n_tokens_neox': 893, 'n_words': 205}