json_api_client 1.5.0 → 1.5.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: c6080263ed5bd33871ec24abc5e89a8f70b6e63c
4
- data.tar.gz: c084e334f7435d9301f5c5577df6b8b7b8baf6c5
3
+ metadata.gz: 441f2bb5cf8f6fd819fda9b1b06282a7295b314c
4
+ data.tar.gz: 4dafa2d5bdf7a8b8aecad456638c704f609719bb
5
5
  SHA512:
6
- metadata.gz: 141e23e17b57f4aa31a7299cb9d43acf177bc9703869dd4e97577cc32da7ee3bfe8924fdb69ff2ae8c62b3972d6b209c4b1848e940bdcbb2e33adf2fbf955ad9
7
- data.tar.gz: 74b02104a09ef030924b5b885e397c35facd293e749a03a9fa8e8a83f2c11799a5006563d5dd095ec709623e4e393296a0a0b852433562cfec960aeeb2c1b70d
6
+ metadata.gz: d7ef003297a74702c6425a6869c30b204cc66996cd579ba46f462607eb1295a37134155160638d301a035d31fc9151d58d465890e5bf406026dff41853106363
7
+ data.tar.gz: 1d67ac769d524ed852e9a675b9b5e831c6f6224c0c8f4ab0666f105f010eadf735c6497d3fb5f5ec2e09700869d072c94df9b181ce67101b3bff775550d7b021
@@ -23,4 +23,4 @@ module JsonApiClient
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -11,6 +11,7 @@ module JsonApiClient
11
11
  end
12
12
 
13
13
  class Association < BaseAssociation
14
+ include Helpers::URI
14
15
  def param
15
16
  :"#{attr_name}_id"
16
17
  end
@@ -18,7 +19,12 @@ module JsonApiClient
18
19
  def to_prefix_path
19
20
  "#{attr_name.to_s.pluralize}/%{#{param}}"
20
21
  end
22
+
23
+ def set_prefix_path(attrs)
24
+ attrs[param] = encode_part(attrs[param]) if attrs.key?(param)
25
+ to_prefix_path % attrs
26
+ end
21
27
  end
22
28
  end
23
29
  end
24
- end
30
+ end
@@ -3,5 +3,6 @@ module JsonApiClient
3
3
  autoload :Callbacks, 'json_api_client/helpers/callbacks'
4
4
  autoload :Dirty, 'json_api_client/helpers/dirty'
5
5
  autoload :DynamicAttributes, 'json_api_client/helpers/dynamic_attributes'
6
+ autoload :URI, 'json_api_client/helpers/uri'
6
7
  end
7
- end
8
+ end
@@ -0,0 +1,9 @@
1
+ module JsonApiClient
2
+ module Helpers
3
+ module URI
4
+ def encode_part(part)
5
+ Addressable::URI.encode_component(part, Addressable::URI::CharacterClasses::UNRESERVED)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,6 +2,7 @@ module JsonApiClient
2
2
  module Query
3
3
  class Requestor
4
4
  extend Forwardable
5
+ include Helpers::URI
5
6
 
6
7
  def initialize(klass)
7
8
  @klass = klass
@@ -49,16 +50,12 @@ module JsonApiClient
49
50
 
50
51
  def resource_path(parameters)
51
52
  if resource_id = parameters[klass.primary_key]
52
- File.join(klass.path(parameters), encoded(resource_id))
53
+ File.join(klass.path(parameters), encode_part(resource_id))
53
54
  else
54
55
  klass.path(parameters)
55
56
  end
56
57
  end
57
58
 
58
- def encoded(part)
59
- Addressable::URI.encode_component(part, Addressable::URI::CharacterClasses::UNRESERVED)
60
- end
61
-
62
59
  def request(type, path, params)
63
60
  klass.parser.parse(klass, connection.run(type, path, params, klass.custom_headers))
64
61
  end
@@ -119,7 +119,7 @@ module JsonApiClient
119
119
  parts = [resource_path]
120
120
  if params && _prefix_path.present?
121
121
  path_params = params.delete(:path) || params
122
- parts.unshift(_prefix_path % path_params.symbolize_keys)
122
+ parts.unshift(_set_prefix_path(path_params.symbolize_keys))
123
123
  else
124
124
  parts.unshift(_prefix_path)
125
125
  end
@@ -266,6 +266,10 @@ module JsonApiClient
266
266
  _belongs_to_associations.map(&:to_prefix_path).join("/")
267
267
  end
268
268
 
269
+ def _set_prefix_path(attrs)
270
+ _belongs_to_associations.map { |a| a.set_prefix_path(attrs) }.join("/")
271
+ end
272
+
269
273
  def _new_scope
270
274
  query_builder.new(self)
271
275
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
@@ -131,6 +131,7 @@ files:
131
131
  - lib/json_api_client/helpers/callbacks.rb
132
132
  - lib/json_api_client/helpers/dirty.rb
133
133
  - lib/json_api_client/helpers/dynamic_attributes.rb
134
+ - lib/json_api_client/helpers/uri.rb
134
135
  - lib/json_api_client/implementation.rb
135
136
  - lib/json_api_client/included_data.rb
136
137
  - lib/json_api_client/linking.rb