dato 0.3.3 → 0.3.5

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: b9ddbcaa4cd09253d0a43f0f05169498d22e125e
4
- data.tar.gz: 16f0cf8243fd0f9519f78bc49fceb1a41cb6c85a
3
+ metadata.gz: ad3ec619bb80a4704d54452bc49ec677e1b6f498
4
+ data.tar.gz: 1c4f832a125be15cd51fa8923d7d431707c6c618
5
5
  SHA512:
6
- metadata.gz: 53899624f929cdc34a587426ab3fc21a18e5096b6b1f87ffe5cf959087d2c8a42bf2ef27baf775acf81aa6e0203774f9667767994e6421723a2ecc60d9b53f9e
7
- data.tar.gz: 7363a20c682292080b81a2f55a47d7ed0a7924d2e998dfd6e22c3c2f8b604627319153a7960e8eba65075ccf3d840b3eb36a6b7c6d2d371aa682d841c1c142cd
6
+ metadata.gz: c69a434cbbfed50009a013c9e23b7d2b1e9fbd62a370f2c90976739958a94c9c31031ef2c04536348042a37a9c173a432473dd2042bb4bde1f1f06c6aa2afd32
7
+ data.tar.gz: f1e25a2b11be0c93f2e8a7c7577a114bc712a5538c2770231c8a8992043e4d619f757703e4c63d8d043c555386a4182d581e92b41b8d571049277cb4c2b9491d
@@ -127,9 +127,12 @@ module Dato
127
127
  item_types.each do |item_type|
128
128
  method = item_type_methods[item_type]
129
129
  next unless item_type.singleton
130
- @collections_by_type[method] = @items_by_id[
131
- item_type.singleton_item.id
132
- ]
130
+
131
+ item = if item_type.singleton_item
132
+ @items_by_id[item_type.singleton_item.id]
133
+ end
134
+
135
+ @collections_by_type[method] = item
133
136
  end
134
137
  end
135
138
 
@@ -57,7 +57,7 @@ module Dato
57
57
  linkage.map do |item|
58
58
  data_source.find_entity(item[:type], item[:id])
59
59
  end
60
- else
60
+ elsif linkage.is_a? Hash
61
61
  data_source.find_entity(linkage[:type], linkage[:id])
62
62
  end
63
63
  end
@@ -31,23 +31,7 @@ module Dato
31
31
  end
32
32
 
33
33
  def all_items
34
- items_per_page = 500
35
- base_response = client.request(:get, '/items', 'page[limit]' => 500)
36
-
37
- extra_pages = (
38
- base_response[:meta][:total_count] / items_per_page.to_f
39
- ).ceil - 1
40
-
41
- extra_pages.times do |page|
42
- base_response[:data] += client.request(
43
- :get,
44
- '/items',
45
- 'page[offset]' => items_per_page * (page + 1),
46
- 'page[limit]' => items_per_page
47
- )[:data]
48
- end
49
-
50
- base_response
34
+ client.items.all({}, false)
51
35
  end
52
36
  end
53
37
  end
@@ -35,8 +35,33 @@ module Dato
35
35
  put_request "/items/#{item_id}", body
36
36
  end
37
37
 
38
- def all(filters = {})
39
- get_request '/items', filters
38
+ def all(filters = {}, deserialize_response = true)
39
+ items_per_page = 500
40
+
41
+ base_response = client.request(
42
+ :get, '/items', filters.dup.merge('page[limit]' => items_per_page)
43
+ )
44
+
45
+ extra_pages = (
46
+ base_response[:meta][:total_count] / items_per_page.to_f
47
+ ).ceil - 1
48
+
49
+ extra_pages.times do |page|
50
+ base_response[:data] += client.request(
51
+ :get,
52
+ '/items',
53
+ filters.dup.merge(
54
+ 'page[offset]' => items_per_page * (page + 1),
55
+ 'page[limit]' => items_per_page
56
+ )
57
+ )[:data]
58
+ end
59
+
60
+ if deserialize_response
61
+ JsonApiDeserializer.new.deserialize(base_response)
62
+ else
63
+ base_response
64
+ end
40
65
  end
41
66
 
42
67
  def find(item_id)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Dato
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.5'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler