json_api_client 0.5.1 → 0.6.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b14973ffe9a4a87d4981a8b56d0817e65c8816
|
4
|
+
data.tar.gz: 975fa606cb2b0bea5af663ed098ad45990327efe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b51a687c23ea5a3f4bfddb16c621724d9e41870567c4386a68db8d0486c6003118a83fb657fab6b3a19699c093db0e951a7f2dffdc22b30f893ca916f482610
|
7
|
+
data.tar.gz: c6d1d89ccae79e4c9a17f861eb98f1a7030ee3d816304680d84ae17c7ed8b594b271a3378644b2b0816549e89354d875622468842dfcd4b54d1e3f44d8aa0c8e
|
@@ -5,6 +5,7 @@ module JsonApiClient
|
|
5
5
|
def parse(klass, response)
|
6
6
|
data = response.body
|
7
7
|
ResultSet.build(klass, data) do |result_set|
|
8
|
+
handle_meta(result_set, data)
|
8
9
|
handle_pagination(result_set, data)
|
9
10
|
handle_links(result_set, data)
|
10
11
|
handle_errors(result_set, data)
|
@@ -13,23 +14,26 @@ module JsonApiClient
|
|
13
14
|
|
14
15
|
private
|
15
16
|
|
17
|
+
def handle_meta(result_set, data)
|
18
|
+
result_set.meta = data.fetch("meta", {})
|
19
|
+
end
|
20
|
+
|
16
21
|
def handle_pagination(result_set, data)
|
17
|
-
|
18
|
-
result_set.per_page = meta.fetch("per_page") do
|
22
|
+
result_set.per_page = result_set.meta.fetch("per_page") do
|
19
23
|
result_set.length
|
20
24
|
end
|
21
|
-
result_set.total_entries = meta.fetch("total_entries") do
|
25
|
+
result_set.total_entries = result_set.meta.fetch("total_entries") do
|
22
26
|
result_set.length
|
23
27
|
end
|
24
|
-
result_set.current_page = meta.fetch("current_page", 1)
|
28
|
+
result_set.current_page = result_set.meta.fetch("current_page", 1)
|
25
29
|
|
26
30
|
# can fall back to calculating via total entries and per_page
|
27
|
-
result_set.total_pages = meta.fetch("total_pages") do
|
31
|
+
result_set.total_pages = result_set.meta.fetch("total_pages") do
|
28
32
|
(1.0 * result_set.total_entries / result_set.per_page).ceil rescue 1
|
29
33
|
end
|
30
34
|
|
31
35
|
# can fall back to calculating via per_page and current_page
|
32
|
-
result_set.offset = meta.fetch("offset") do
|
36
|
+
result_set.offset = result_set.meta.fetch("offset") do
|
33
37
|
result_set.per_page * (result_set.current_page - 1)
|
34
38
|
end
|
35
39
|
end
|
@@ -49,9 +53,9 @@ module JsonApiClient
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def handle_errors(result_set, data)
|
52
|
-
result_set.errors =
|
56
|
+
result_set.errors = result_set.meta.fetch("errors", [])
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
60
|
end
|
57
|
-
end
|
61
|
+
end
|
@@ -23,9 +23,9 @@ module JsonApiClient
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def inspect
|
26
|
-
"method: #{request_method}; path: #{path}; params: #{params}, headers: #{headers}"
|
26
|
+
"#{self.class.name}: method: #{request_method}; path: #{path}; params: #{params}, headers: #{headers}"
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -56,6 +56,8 @@ module JsonApiClient
|
|
56
56
|
include Helpers::CustomEndpoints
|
57
57
|
include Helpers::Schemable
|
58
58
|
|
59
|
+
attr_reader :last_request_meta
|
60
|
+
|
59
61
|
def save
|
60
62
|
query = persisted? ?
|
61
63
|
Query::Update.new(self.class, attributes) :
|
@@ -78,9 +80,10 @@ module JsonApiClient
|
|
78
80
|
def run_request(query)
|
79
81
|
# reset errors if a new request is being made
|
80
82
|
self.errors.clear if self.errors
|
81
|
-
|
83
|
+
|
82
84
|
result = self.class.run_request(query)
|
83
85
|
self.errors = result.errors
|
86
|
+
@last_request_meta = result.meta
|
84
87
|
if result.has_errors?
|
85
88
|
return false
|
86
89
|
else
|
@@ -92,4 +95,4 @@ module JsonApiClient
|
|
92
95
|
end
|
93
96
|
|
94
97
|
end
|
95
|
-
end
|
98
|
+
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: 0.
|
4
|
+
version: 0.6.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: 2014-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|