https://github.com/jsonapi-rb/jsonapi-client
https://github.com/jsonapi-rb/jsonapi-client
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsonapi-rb/jsonapi-client
- Owner: jsonapi-rb
- Created: 2016-10-29T19:32:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T01:28:48.000Z (almost 7 years ago)
- Last Synced: 2025-01-22T18:35:49.277Z (3 months ago)
- Language: Ruby
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsonapi-client
Ruby gem for consuming [JSON API](http://jsonapi.org) documents.## Status
[](https://badge.fury.io/rb/jsonapi-client)
[](http://travis-ci.org/jsonapi-rb/client?branch=master)## Installation
```ruby
# In Gemfile
gem 'jsonapi-client'
```
then
```
$ bundle
```
or manually via
```
$ gem install jsonapi-client
```## Usage
First, require the gem:
```ruby
require 'jsonapi/client'
```Then
```ruby
payload = {
"links" => {
"self" => "http://example.com/articles",
"next" => "http://example.com/articles?page[offset]=2",
"last" => "http://example.com/articles?page[offset]=10"
},
"data" => [
{
"type" => "articles",
"id" => "1",
"attributes" => {
"title" => "JSON API paints my bikeshed!"
},
"relationships" => {
"author" => {
"links" => {
"self" => "http://example.com/articles/1/relationships/author",
"related" => "http://example.com/articles/1/author"
},
"data" => { "type" => "people", "id" => "9" }
},
"comments" => {
"links" => {
"self" => "http://example.com/articles/1/relationships/comments",
"related" => "http://example.com/articles/1/comments"
},
"data" => [
{ "type" => "comments", "id" => "5" },
{ "type" => "comments", "id" => "12" }
]
}
},
"links" => {
"self" => "http://example.com/articles/1"
}
}
],
"included" => [
{
"type" => "people",
"id" => "9",
"attributes" => {
"first-name" => "Dan",
"last-name" => "Gebhardt",
"twitter" => "dgeb"
},
"links" => {
"self" => "http://example.com/people/9"
}
}, {
"type" => "comments",
"id" => "5",
"attributes" => {
"body" => "First!"
},
"relationships" => {
"author" => {
"data" => { "type" => "people", "id" => "2" }
}
},
"links" => {
"self" => "http://example.com/comments/5"
}
}, {
"type" => "comments",
"id" => "12",
"attributes" => {
"body" => "I like XML better"
},
"relationships" => {
"author" => {
"data" => { "type" => "people", "id" => "9" }
}
},
"links" => {
"self" => "http://example.com/comments/12"
}
}
]
}document = JSONAPI::Client::Document.new(json_hash)
document.data[0].relationships['author'].data.attributes['first-name']
# => "Dan"
```## License
jsonapi-client is released under the [MIT License](http://www.opensource.org/licenses/MIT).