json_api_client 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26e65758ae09b482b1225164727d13e14976a9f5
4
- data.tar.gz: 7307ffd05a5b5336b5cdd1da281913d40c3c0839
3
+ metadata.gz: 9d4a8de0c8279d6ea5d6b7a3bf1d3da4af650d66
4
+ data.tar.gz: 84624c1a31f574187b0adb03f1db3800df2af6d4
5
5
  SHA512:
6
- metadata.gz: b39d8afd03a7d669cef3225828661f1cc68d2acd02d54e6f3a00fc5105f8b7fa6191f81ba8ebcbb53c1ca6c00bc819efcdcbc085e1885292a44aef373a4cb28a
7
- data.tar.gz: d815f9852679b6a008c66c806ccf729653f11fdf525e054780cdaecd6b6be567cf41804e6ef571f85df5f38da7383c442ceb7f716700231a0a6331c75572e048
6
+ metadata.gz: 2ea79d5d91d055556a3f26ca37d3d3447744b03858c668e676d11b787e5658bbf7b31965416c016ad46c4a42bff116df977876330852a8db48bb9f7eef477076
7
+ data.tar.gz: c7a70e2f4fb4a969e47a2dec2be67b77b682523ca4d5a1ccde554c855c632163582395af8951047044bba128c17d0270f0383e93f30341ca649477dd19a257c6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonApiClient [![Build Status](https://travis-ci.org/chingor13/json_api_client.png)](https://travis-ci.org/chingor13/json_api_client) [![Code Climate](https://codeclimate.com/github/chingor13/json_api_client.png)](https://codeclimate.com/github/chingor13/json_api_client) [![Code Coverage](https://codeclimate.com/github/chingor13/json_api_client/coverage.png)](https://codeclimate.com/github/chingor13/json_api_client)
1
+ # 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)
2
2
 
3
3
  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).
4
4
 
@@ -399,7 +399,7 @@ class NullConnection
399
399
  def initialize(*args)
400
400
  end
401
401
 
402
- def run(request_method, path, params = {}, headers = {})
402
+ def run(request_method, path, params: nil, headers: {}, body: nil)
403
403
  end
404
404
 
405
405
  def use(*args); end
@@ -493,8 +493,8 @@ You can customize how your resources find pagination information from the respon
493
493
  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:
494
494
 
495
495
  ```ruby
496
- JsonApiClient::Paginating::Paginator.page_param = "page[number]"
497
- JsonApiClient::Paginating::Paginator.per_page_param = "page[size]"
496
+ JsonApiClient::Paginating::Paginator.page_param = "number"
497
+ JsonApiClient::Paginating::Paginator.per_page_param = "size"
498
498
  ```
499
499
 
500
500
  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.
@@ -35,6 +35,8 @@ module JsonApiClient
35
35
  :request_params_class,
36
36
  :keep_request_params,
37
37
  instance_accessor: false
38
+ class_attribute :add_defaults_to_changes,
39
+ instance_writer: false
38
40
  self.primary_key = :id
39
41
  self.parser = Parsers::Parser
40
42
  self.paginator = Paginating::Paginator
@@ -48,6 +50,7 @@ module JsonApiClient
48
50
  self.associations = []
49
51
  self.request_params_class = RequestParams
50
52
  self.keep_request_params = false
53
+ self.add_defaults_to_changes = false
51
54
 
52
55
  #:underscored_key, :camelized_key, :dasherized_key, or custom
53
56
  self.json_key_format = :underscored_key
@@ -309,14 +312,13 @@ module JsonApiClient
309
312
  #
310
313
  # @param params [Hash] Attributes, links, and relationships
311
314
  def initialize(params = {})
315
+ params = params.symbolize_keys
312
316
  @persisted = nil
313
- self.links = self.class.linker.new(params.delete("links") || {})
314
- self.relationships = self.class.relationship_linker.new(self.class, params.delete("relationships") || {})
317
+ self.links = self.class.linker.new(params.delete(:links) || {})
318
+ self.relationships = self.class.relationship_linker.new(self.class, params.delete(:relationships) || {})
315
319
  self.attributes = self.class.default_attributes.merge(params)
316
320
 
317
- self.class.schema.each_property do |property|
318
- attributes[property.name] = property.default unless attributes.has_key?(property.name) || property.default.nil?
319
- end
321
+ setup_default_properties
320
322
 
321
323
  self.class.associations.each do |association|
322
324
  if params.has_key?(association.attr_name.to_s)
@@ -480,6 +482,15 @@ module JsonApiClient
480
482
 
481
483
  protected
482
484
 
485
+ def setup_default_properties
486
+ self.class.schema.each_property do |property|
487
+ unless attributes.has_key?(property.name) || property.default.nil?
488
+ attribute_will_change!(property.name) if add_defaults_to_changes
489
+ attributes[property.name] = property.default
490
+ end
491
+ end
492
+ end
493
+
483
494
  def method_missing(method, *args)
484
495
  association = association_for(method)
485
496
 
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-27 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport