json_api_client 1.0.0.beta3 → 1.0.0.beta4

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: 1af573eac7e606a57e398c563b46b41ed2f4aea0
4
- data.tar.gz: 0c6b27e6af8fd78b449a253226c1a37e9c83c81b
3
+ metadata.gz: 6a4cf7888d664d4668f98705059cdffcead9c2b7
4
+ data.tar.gz: 454e3c488bbcfe07799ecdbb7bb721a6c62801e7
5
5
  SHA512:
6
- metadata.gz: 5cefa69d519d148e9298e36a0bba1e11605a59b841e34d9eb5c213ed7e56eecfe6e6a86914584b84777e513d707c6b4cebd597b701406cdfc9d33a89454e19e3
7
- data.tar.gz: 7ee4e4c5e432f24f232349ce0ee4565fdec370c00de50b5ba1f27291dee3bc9aa9095608a9ad48e6ea0b35b971128248dbfa94dd3b5bc9526f0a386092d9163d
6
+ metadata.gz: cb67e1ab20c2cd63d2aeaa72a2b2ff7682d9d34fd82303a9acbe62c1ad535a5606cbacf0e35c8503a7e89c9726f13681c38b5603ad77f174c8e4ea587aae4311
7
+ data.tar.gz: 609d93e6f8c0b63fb04bd4215a1e996085e8ecada6b4620a3591f764e75c47493e1fb483a15f6e8b582518b408aa2d80196084c7cc5e669bcdc17a9ba974df77
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :associations
7
+ class_attribute :associations, instance_accessor: false
8
8
  self.associations = []
9
9
 
10
10
  include Associations::BelongsTo
@@ -30,12 +30,8 @@ module JsonApiClient
30
30
  def path(params = nil)
31
31
  parts = [table_name]
32
32
  if params
33
- filters = params.fetch(:filter, params)
34
- slurp = filters.slice(*prefix_params)
35
- prefix_params.each do |param|
36
- filters.delete(param)
37
- end
38
- parts.unshift(prefix_path % slurp.symbolize_keys)
33
+ path_params = params.delete(:path) || params
34
+ parts.unshift(prefix_path % path_params.symbolize_keys)
39
35
  else
40
36
  parts.unshift(prefix_path)
41
37
  end
@@ -49,7 +45,7 @@ module JsonApiClient
49
45
  protected
50
46
 
51
47
  def load_associations(params)
52
- associations.each do |association|
48
+ self.class.associations.each do |association|
53
49
  if params.has_key?(association.attr_name.to_s)
54
50
  set_attribute(association.attr_name, association.parse(params[association.attr_name.to_s]))
55
51
  end
@@ -1,7 +1,6 @@
1
1
  module JsonApiClient
2
2
  module Helpers
3
3
  module DynamicAttributes
4
- extend ActiveSupport::Concern
5
4
 
6
5
  def attributes
7
6
  @attributes
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :initializers
7
+ class_attribute :initializers, instance_accessor: false
8
8
  self.initializers = []
9
9
  end
10
10
 
@@ -15,7 +15,7 @@ module JsonApiClient
15
15
  end
16
16
 
17
17
  def initialize(params = {})
18
- initializers.each do |initializer|
18
+ self.class.initializers.each do |initializer|
19
19
  if initializer.respond_to?(:call)
20
20
  initializer.call(self, params)
21
21
  else
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :linker
7
+ class_attribute :linker, instance_accessor: false
8
8
  self.linker = Linking::Links
9
9
 
10
10
  # the links for this resource
@@ -13,7 +13,7 @@ module JsonApiClient
13
13
  initializer do |obj, params|
14
14
  links = params && params.delete("links")
15
15
  links ||= {}
16
- obj.links = obj.linker.new(links)
16
+ obj.links = obj.class.linker.new(links)
17
17
  end
18
18
  end
19
19
 
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :paginator
7
+ class_attribute :paginator, instance_accessor: false
8
8
  self.paginator = Paginating::Paginator
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :parser
7
+ class_attribute :parser, instance_accessor: false
8
8
  self.parser = Parsers::Parser
9
9
  end
10
10
 
@@ -8,7 +8,7 @@ module JsonApiClient
8
8
  extend Forwardable
9
9
  def_delegators :new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :first, :find
10
10
  end
11
- class_attribute :connection_class, :connection_object, :connection_options, :query_builder
11
+ class_attribute :connection_class, :connection_object, :connection_options, :query_builder, instance_accessor: false
12
12
  self.connection_class = Connection
13
13
  self.connection_options = {}
14
14
  self.query_builder = Query::Builder
@@ -4,7 +4,7 @@ module JsonApiClient
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- class_attribute :relationship_linker
7
+ class_attribute :relationship_linker, instance_accessor: false
8
8
  self.relationship_linker = Relationships::Relations
9
9
 
10
10
  # the relationships for this resource
@@ -13,7 +13,7 @@ module JsonApiClient
13
13
  initializer do |obj, params|
14
14
  relationships = params && params.delete("relationships")
15
15
  relationships ||= {}
16
- obj.relationships = obj.relationship_linker.new(relationships)
16
+ obj.relationships = obj.class.relationship_linker.new(relationships)
17
17
  end
18
18
  end
19
19
 
@@ -5,7 +5,7 @@ module JsonApiClient
5
5
 
6
6
  included do
7
7
  attr_accessor :last_result_set, :errors
8
- class_attribute :requestor_class
8
+ class_attribute :requestor_class, instance_accessor: false
9
9
  self.requestor_class = Query::Requestor
10
10
  end
11
11
 
@@ -1,22 +1,20 @@
1
1
  module JsonApiClient
2
2
  module Helpers
3
3
  module Serializable
4
- RESERVED = ['id', 'type', 'links', 'meta', 'relationships']
4
+ extend ActiveSupport::Concern
5
5
 
6
- # def as_json(options=nil)
7
- # attributes.slice(*RESERVED).tap do |h|
8
- # h['attributes'] = serialized_attributes
9
- # end
10
- # end
11
-
12
- def data
13
- attributes.slice(*RESERVED).tap do |h|
14
- h['attributes'] = serialized_attributes
15
- end
6
+ included do
7
+ class_attribute :read_only_attributes, instance_accessor: false
8
+ self.read_only_attributes = ['id', 'type', 'links', 'meta', 'relationships']
16
9
  end
17
10
 
18
- def serialized_attributes
19
- attributes.except(*RESERVED)
11
+ def serializable_hash
12
+ attributes.slice('id', 'type').tap do |h|
13
+ relationships.serializable_hash.tap do |r|
14
+ h['relationships'] = r unless r.empty?
15
+ end
16
+ h['attributes'] = attributes.except(*self.class.read_only_attributes)
17
+ end
20
18
  end
21
19
 
22
20
  end
@@ -9,7 +9,7 @@ module JsonApiClient
9
9
  klass = Utils.compute_type(record_class, type.singularize.classify)
10
10
  h[type] = records.map do |datum|
11
11
  params = klass.parser.parameters_from_resource(datum)
12
- resource = klass.new(params)
12
+ resource = klass.load(params)
13
13
  resource.result_set = result_set
14
14
  resource
15
15
  end.index_by(&:id)
@@ -2,12 +2,13 @@ module JsonApiClient
2
2
  module Query
3
3
  class Builder
4
4
 
5
- attr_reader :klass
5
+ attr_reader :klass, :path_params
6
6
 
7
7
  def initialize(klass)
8
8
  @klass = klass
9
9
  @primary_key = nil
10
10
  @pagination_params = {}
11
+ @path_params = {}
11
12
  @filters = {}
12
13
  @includes = []
13
14
  @orders = []
@@ -15,7 +16,9 @@ module JsonApiClient
15
16
  end
16
17
 
17
18
  def where(conditions = {})
18
- @filters.merge!(conditions)
19
+ # pull out any path params here
20
+ @path_params.merge!(conditions.slice(*klass.prefix_params))
21
+ @filters.merge!(conditions.except(*klass.prefix_params))
19
22
  self
20
23
  end
21
24
 
@@ -66,6 +69,7 @@ module JsonApiClient
66
69
  .merge(order_params)
67
70
  .merge(select_params)
68
71
  .merge(primary_key_params)
72
+ .merge(path_params)
69
73
  end
70
74
 
71
75
  def to_a
@@ -90,6 +94,10 @@ module JsonApiClient
90
94
 
91
95
  private
92
96
 
97
+ def path_params
98
+ @path_params.empty? ? {} : {path: @path_params}
99
+ end
100
+
93
101
  def primary_key_params
94
102
  return {} unless @primary_key
95
103
 
@@ -10,13 +10,13 @@ module JsonApiClient
10
10
  # expects a record
11
11
  def create(record)
12
12
  request(:post, klass.path(record.attributes), {
13
- data: record.data
13
+ data: record.serializable_hash
14
14
  })
15
15
  end
16
16
 
17
17
  def update(record)
18
18
  request(:patch, resource_path(record.attributes), {
19
- data: record.data
19
+ data: record.serializable_hash
20
20
  })
21
21
  end
22
22
 
@@ -11,6 +11,12 @@ module JsonApiClient
11
11
  attributes.present?
12
12
  end
13
13
 
14
+ def serializable_hash
15
+ Hash[attributes.map do |k, v|
16
+ [k, v.slice("data")]
17
+ end]
18
+ end
19
+
14
20
  protected
15
21
 
16
22
  def set_attribute(name, value)
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.0.0.beta3"
2
+ VERSION = "1.0.0.beta4"
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.0.0.beta3
4
+ version: 1.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -171,9 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: 1.3.1
172
172
  requirements: []
173
173
  rubyforge_project:
174
- rubygems_version: 2.2.2
174
+ rubygems_version: 2.4.5
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Build client libraries compliant with specification defined by jsonapi.org
178
178
  test_files: []
179
- has_rdoc: