0.0
No commit activity in last 3 years
No release in over 3 years
Client library for the JSON API spec.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 0.1.1.beta2
>= 0.9
~> 3.4
 Project Readme

jsonapi-client

Ruby gem for consuming JSON API documents.

Status

Gem Version Build Status

Installation

# In Gemfile
gem 'jsonapi-client'

then

$ bundle

or manually via

$ gem install jsonapi-client

Usage

First, require the gem:

require 'jsonapi/client'

Then

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.