json_api_client 1.0.2 → 1.1.0

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: 27bde5e4eec74b2589b7ec2c121e799d40defbc9
4
- data.tar.gz: 8a25b071e84fd39f17e0044eda38eff1107d75bb
3
+ metadata.gz: 70ed96e8dad9bdeec5923280be1cd87e1f1d41b2
4
+ data.tar.gz: 6a3e93637e3b6dd1f744962088766e6a9d785891
5
5
  SHA512:
6
- metadata.gz: 86f7e70883d0521db847055f539cc8adff437f375f76a113b6d7abe5f960f6b50b82edee08a789886e0f34aa7dc9a1d9a8f5657d1a342d97bb35427f2403196e
7
- data.tar.gz: 8f7d8fc7e34e175bb7c3c5cf230d0bf00995bfbc07cb09d29890262f738b3b205cc45359ba80dcc8f04620b7f430c7c1d72beadf9dd4241833bf02850b340e89
6
+ metadata.gz: 3b435a4a8989ea0fd2b5571728feb3a175c2e7ad300c51769c245c7b4775dd5318ce9e087602d08d988ce6524339a63d43cb8ff0dc467c1a4bd3f17fd429a5f2
7
+ data.tar.gz: 994419ad14dcb898d9a7dd753834ac582398ea841f3671d5b8f234d908d536d400a3a601ea2fcf566b4b839be5fd2421123277742bb7082bee36b4fba4724252
data/README.md CHANGED
@@ -404,7 +404,7 @@ You can customize how the scope builder methods map to request parameters.
404
404
 
405
405
  ```ruby
406
406
  class MyQueryBuilder
407
- def def initialize(klass); end
407
+ def initialize(klass); end
408
408
 
409
409
  def where(conditions = {})
410
410
  end
@@ -21,9 +21,17 @@ module JsonApiClient
21
21
  end
22
22
  end
23
23
 
24
- def fetch_link(link_name)
24
+ def link_url_for(link_name)
25
25
  link_definition = links.fetch(link_name.to_s)
26
- record_class.requestor.linked(link_definition)
26
+ if link_definition.is_a?(Hash)
27
+ link_definition["href"]
28
+ else
29
+ link_definition
30
+ end
31
+ end
32
+
33
+ def fetch_link(link_name)
34
+ record_class.requestor.linked(link_url_for(link_name))
27
35
  end
28
36
  end
29
37
  end
@@ -13,7 +13,7 @@ module JsonApiClient
13
13
  end
14
14
 
15
15
  def prev
16
- result_set.links.fetch_link("next")
16
+ result_set.links.fetch_link("prev")
17
17
  end
18
18
 
19
19
  def first
@@ -26,7 +26,8 @@ module JsonApiClient
26
26
 
27
27
  def total_pages
28
28
  if links["last"]
29
- last_params = params_for_uri(links["last"])
29
+ uri = result_set.links.link_url_for("last")
30
+ last_params = params_for_uri(uri)
30
31
  last_params.fetch("page") do
31
32
  current_page
32
33
  end.to_i
@@ -9,6 +9,7 @@ module JsonApiClient
9
9
  @primary_key = nil
10
10
  @pagination_params = {}
11
11
  @path_params = {}
12
+ @additional_params = {}
12
13
  @filters = {}
13
14
  @includes = []
14
15
  @orders = []
@@ -54,6 +55,11 @@ module JsonApiClient
54
55
  self
55
56
  end
56
57
 
58
+ def with_params(more_params)
59
+ @additional_params.merge!(more_params)
60
+ self
61
+ end
62
+
57
63
  def first
58
64
  paginate(page: 1, per_page: 1).to_a.first
59
65
  end
@@ -70,6 +76,7 @@ module JsonApiClient
70
76
  .merge(select_params)
71
77
  .merge(primary_key_params)
72
78
  .merge(path_params)
79
+ .merge(additional_params)
73
80
  end
74
81
 
75
82
  def to_a
@@ -98,6 +105,10 @@ module JsonApiClient
98
105
  @path_params.empty? ? {} : {path: @path_params}
99
106
  end
100
107
 
108
+ def additional_params
109
+ @additional_params
110
+ end
111
+
101
112
  def primary_key_params
102
113
  return {} unless @primary_key
103
114
 
@@ -48,7 +48,7 @@ module JsonApiClient
48
48
 
49
49
  class << self
50
50
  extend Forwardable
51
- def_delegators :_new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :first, :find
51
+ def_delegators :_new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :with_params, :first, :find
52
52
 
53
53
  # The table name for this resource. i.e. Article -> articles, Person -> people
54
54
  #
@@ -280,6 +280,14 @@ module JsonApiClient
280
280
  save
281
281
  end
282
282
 
283
+ # Alias to update_attributes
284
+ #
285
+ # @param attrs [Hash] Attributes to update
286
+ # @return [Boolean] Whether the update succeeded or not
287
+ def update(attrs = {})
288
+ update_attributes(attrs)
289
+ end
290
+
283
291
  # Mark the record as persisted
284
292
  def mark_as_persisted!
285
293
  @persisted = true
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
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.2
4
+ version: 1.1.0
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-12-15 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.0
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.0
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday_middleware
43
43
  requirement: !ruby/object:Gem::Requirement