Code Monkey home page Code Monkey logo

jsonapi's Introduction

jsonapi's People

Contributors

aars avatar beauby avatar buren avatar diminish7 avatar glsignal avatar jaredbeck avatar jbodah avatar lgebhardt avatar nullvoxpopuli avatar ruslan-volyanyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jsonapi's Issues

Error using #to_activerecord_hash

I get this error while using this to_activerecord_hash (related to #7 )

NoMethodError: undefined method `[]' for nil:NilClass
    from /var/lib/gems/2.2.0/gems/jsonapi_parser-0.5.5/lib/json/api/resource/active_record.rb:142:in `filter_keys'
    from /var/lib/gems/2.2.0/gems/jsonapi_parser-0.5.5/lib/json/api/resource/active_record.rb:82:in `attributes_for_activerecord_hash'
    from /var/lib/gems/2.2.0/gems/jsonapi_parser-0.5.5/lib/json/api/resource/active_record.rb:72:in `to_activerecord_hash'

The related object is

#<JSON::API::Resource:0x00000006905528
 @attributes=
  #<JSON::API::Attributes:0x00000006905398
   @attributes=
    {"name"=>nil,
     "tax_id"=>"19818",
     "description"=>nil,
     "image_url"=>nil,
     "preferred_name"=>"PALMER SECOND BAPTIST CHURCH",
     "created_at"=>"2016-03-28T18:41:34.000Z",
     "updated_at"=>"2016-03-28T18:41:34.000Z",
     "json_data"=>{"deductibility"=>1, "sort_name"=>3514},
     "type_of_cause"=>nil,
     "images"=>[],
     "primary_image"=>nil}>,
 @attributes_hash=
  {"name"=>nil,
   "tax_id"=>"19818",
   "description"=>nil,
   "image_url"=>nil,
   "preferred_name"=>"PALMER SECOND BAPTIST CHURCH",
   "created_at"=>"2016-03-28T18:41:34.000Z",
   "updated_at"=>"2016-03-28T18:41:34.000Z",
   "json_data"=>{"deductibility"=>1, "sort_name"=>3514},
   "type_of_cause"=>nil,
   "images"=>[],
   "primary_image"=>nil},
 @id="472",
 @id_optional=true,
 @links=#<JSON::API::Links:0x000000068c3f88 @links={}>,
 @links_hash={},
 @options={},
 @relationships=#<JSON::API::Relationships:0x000000069040d8 @relationships={}>,
 @relationships_hash={},
 @type="causes">

I think there's an incorrect assertion in `Document#parse_resource_identifier!`

This assertion here: https://github.com/beauby/jsonapi/blob/master/parser/lib/jsonapi/parser/document.rb#L126

That assertion currently fails when the resource identifier has both id and type.
Based on what the error message is, I think it should test for equality rather than inequality:

ensure!(ri.keys & RESOURCE_IDENTIFIER_KEYS == RESOURCE_IDENTIFIER_KEYS,
                'A resource identifier object MUST contain ' \
                "#{RESOURCE_IDENTIFIER_KEYS} members.")

cannot load jsonapi file from active_support/dependencies.rb

Hi, I'm getting this:

activesupport-4.1.14.1/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- jsonapi (LoadError)

since the update for 0.1.1.beta4

Yes, I do use version 4.1.14.1 for activesupport.

Hope this helps.. Thanks for the good job!

It can't parse the post request for jsonapi data/resource(s)

At jsonapi.org--create a resource by jsonapi, the request does not have 'id' field. For example,

document = {
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      }
    }
  }
}

JSONAPI.parse_resouce!(document)

It just return JSONAPI::Parser::InvalidDocument: The request MUST include a single resource object as primary data.

So can any one add this parser?

PS: Base on the jsonapi standard , I usually do some batch_operation by pull the request like

{
  "data": {
    "type": "photos",
    "attributes": [{
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },{
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },{
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    }]
  }
}

So I hope this gem can also parse data to hash array.

Cleanup/add tests

Just a reminder that more tests are always welcome (currently lacking the most are tests for failing scenarios).

Should the "parser" be a "validator"?

I'm in the middle of upgrading from beta2 to beta5, and it seems like parsing is no longer a part of this gem's functionality. I spent a bit of time trying to figure out why the result of parse! was always nil. By the time it gets to the "parser" now, it is expected to already by parsed, and the core functionality here seems to be to raise an exception if the already-parsed object doesn't match JSON API expectations.

0.1.1.beta6 + active_model_serializers include: "blargh.**" and "blargh.*" appears to be broken

Using active_model_serializers version 0.10.2 and rails 4.2.7.1

I'm currently trying to get this down to an easy test that you can reproduce but thought I'd go ahead and report it while I work on making it.

We have an app with a render invocation using activemodel_serializers that looks like:

render json: @object,
           adapter: :json,
           root: 'something', 
           include: 'blah, blargh.**',

There's some other render options provided that shouldn't matter.

With jsonapi 0.1.1.beta2 this works as expected and there is a blargh key with nested stuff under it in the resulting json.

However, with jsonapi 0.1.1.beta6 there is no blargh key at all. If I remove the .** then the blargh key is back and has data, but obviously no nesting. If I switch to just blargh.* I get the same bad result as .** where I have no blargh key.

I will work on getting that test ready so you can take a look yourself. I'm "blaming" this on jsonapi gem instead of active_model_serializers because upgrading the jsonapi gem is the direct cause of the breakage.

JSONAPI::Resource clashes with the jsonapi-resources gem

If you have both the jsonapi gem and the jsonapi-resources gem, there is a conflict as both gems define the JSONAPI::Resource class. This conflict did not exist until this gem moved to the JSONAPI namespace. The only solution to me seems to be that both gems use independent namespaces.

Meta is never set

Hey there, I was digging through the implementation here for why meta was showing up as nil, even though the flag @meta_defined is set.

https://github.com/beauby/jsonapi_parser/blob/master/lib/json/api/document.rb#L79 checks that meta_hash is indeed a hash and fails if it's not valid, but it never returns anything and so meta remains nil.

I see there isn't a test case for this yet, so are there plans around how you want to load meta or would it be sufficient to return meta_hash in parse_meta (leaving it as a regular hash, rather than an object of some sort as in parse_data)?

If you're alright with just a hash being there then I can submit a PR pretty promptly, otherwise let's discuss how to implement it.

Yanked beta2 gem version breaks activemodel-serializers release 0.10.2

Activemodel-serializers is currently broken due to the gem being yanked from rubygems.org. Failure indicates like this:

  + bundle install
  Fetching gem metadata from https://rubygems.org/
  Fetching version metadata from https://rubygems.org/
  Fetching dependency metadata from https://rubygems.org/
  Could not find jsonapi-parser-0.1.1.beta2 in any of the sources (Executor::NonZeroExitStatus)

If we can unyank the gem, that would fix this issue. The twiddle-wakka (~>) used in AMS's gemspec does not automatically increment to beta3, unfortunately.

How to deal with the post params

In your doc, document = JSONAPI.parse(hash_or_json_string)
in rails, the params() returns a single hash.
So I think I can use JSONAPI.parse(params) to parse the jsonapi params.

But now I get the error: TypeError (no implicit conversion of ActionController::Parameters into String):.

Is it right?

Retrieving full resources from included based on relationship resource identifiers

One thing I often need to do with JSONAPI documents is to take a resource identifier from a relationship in the main data section and find the linked full resource from included. I end up writing a lot of code (or having to define my own helper for) things like:

identifier = document.data.relationships.default_payment_method.data
document.included.find{|x| identifier.id == x.id && identifier.type == x.type }

So I was wondering if you'd be open to a PR that adds something like this:

document.find_included(document.data.relationships.payment_method.data)

find_included would take a resource identifier and retrieve the resource from included for you--could either just iterate through full array to find it or we could set up a more efficient data structure for retrieval when we initialize the document. This way you could give any resource identifier to the document--including ones from a different document, or from another resource in included--and try to retrieve it from included. It's a small thing but I think it would be useful.

Another option would be to optionally link relationships to full resources when initializing the document, so you could call a method like full_resource on any instance of JSONAPI::Relationship. Could get into odd recursive nesting situations with that though, so maybe the first method is enough.

Let me know what you think!

Update dependencies?

jsonapi-parser and jsonapi-renderer have new versions, currently 0.1.1 and 0.1.2, respectively, but the latest release of jsonapi, 0.1.1.beta6, depends on 0.1.1.beta3 and 0.1.1.beta1, respectively.

Should we release a new version of jsonapi with updated dependency constraints, or should people (e.g. active_model_serializers) no longer use the jsonapi gem? I mean, should people just use jsonapi-parser and jsonapi-renderer directly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.