dato 0.6.14 → 0.6.15

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
  SHA256:
3
- metadata.gz: 95b2f3c8bcf22fedf8b578ae80e935c7992a325587592e32e6d8de0eb42d2723
4
- data.tar.gz: f0d31b23cf1a1c78a1d229601f88905e6a3e3d1097954d722d7454a402d2e645
3
+ metadata.gz: 18f6bab733bb56da0e48f7141e919700ecf428d7dafa5e79812bdd01de16c5bc
4
+ data.tar.gz: 6b2f8b434254f0830c5c7d3e1a729f8752474ddab549e2b1bcc85771f0d0a136
5
5
  SHA512:
6
- metadata.gz: 5e08e8c062c574e18fb638ed415ab63752230c41a30472ad9c69b82d1d8d8f5eebf905a8a511e0996531ce97c58d39228b9a574e267ff357d2cb8cf64e3f0c17
7
- data.tar.gz: 58b5b1c0dc0c0638b6b83e86238eb4b465db65950e4fb6866959b4c16786513a370edb62aa7f2c9f23f26ae2da897aa9743379d475d6b180adff11cb98f26bd5
6
+ metadata.gz: b8cc64b4cafeed1887cbc481f7e01c89ace6ba1597082b2ae42adf03c2a4ad284db40e920a060bcb9b91f7516b3466f8d8456c0f816ccf29c7d4ae3dc0bf1e84
7
+ data.tar.gz: e2d408db575c37e60f33c472ce4c6698d4dc115e7c95757a788414d4822ca2dd129a7007f034e6091f554a5d23caf506f0b59113a41c6fc7fa1659d865edd478
@@ -1,3 +1,7 @@
1
+ # 0.6.15
2
+
3
+ * Handle `429 Too Many Requests` responses from API
4
+
1
5
  # 0.6.12
2
6
 
3
7
  * Allow empty responses from server
@@ -72,15 +72,43 @@ module Dato
72
72
  puts e.message
73
73
  raise e
74
74
  rescue Faraday::ClientError => e
75
- error = ApiError.new(e)
76
- puts '===='
77
- puts error.message
78
- puts '===='
79
- raise error
75
+ if e.response[:status] == 429
76
+ to_wait = e.response[:headers]['x-ratelimit-reset'].to_i
77
+ puts "Rate limit exceeded, waiting #{to_wait} seconds..."
78
+ sleep(to_wait + 1)
79
+ request(*args)
80
+ elsif e.response[:status] == 422 && batch_data_validation?(e.response)
81
+ puts "Validating items, waiting 1 second and retrying..."
82
+ sleep(1)
83
+ request(*args)
84
+ else
85
+ error = ApiError.new(e)
86
+ puts "===="
87
+ puts error.message
88
+ puts "===="
89
+ raise error
90
+ end
80
91
  end
81
92
 
82
93
  private
83
94
 
95
+ def batch_data_validation?(response)
96
+ body = begin
97
+ JSON.parse(response[:body])
98
+ rescue JSON::ParserError => e
99
+ nil
100
+ end
101
+
102
+ return false unless body
103
+ return false unless body["data"]
104
+
105
+ body["data"].any? do |e|
106
+ e["attributes"]["code"] == "BATCH_DATA_VALIDATION_IN_PROGRESS"
107
+ end
108
+ rescue
109
+ false
110
+ end
111
+
84
112
  def connection
85
113
  default_headers = {
86
114
  'Accept' => 'application/json',
@@ -51,13 +51,7 @@ module Dato
51
51
  end
52
52
 
53
53
  def relationships
54
- @relationships ||= JsonSchemaRelationships.new(link_relationships).relationships
55
- end
56
-
57
- def link_relationships
58
- if link.target_schema
59
- link.target_schema.properties['data'].properties['relationships']
60
- end
54
+ @relationships ||= JsonSchemaRelationships.new(link.target_schema).relationships
61
55
  end
62
56
  end
63
57
  end
@@ -106,7 +106,7 @@ module Dato
106
106
  end
107
107
 
108
108
  def relationships
109
- @relationships ||= JsonSchemaRelationships.new(link_relationships).relationships
109
+ @relationships ||= JsonSchemaRelationships.new(link.schema).relationships
110
110
  end
111
111
 
112
112
  def required_relationships
@@ -1,15 +1,19 @@
1
1
  module Dato
2
2
  class JsonSchemaRelationships
3
- attr_reader :link
3
+ attr_reader :schema
4
4
 
5
- def initialize(link)
6
- @link = link
5
+ def initialize(schema)
6
+ @schema = schema
7
7
  end
8
8
 
9
9
  def relationships
10
- return {} unless link
10
+ if !schema || !schema.properties['data'] || !schema.properties['data'].properties['relationships']
11
+ return {}
12
+ end
13
+
14
+ relationships = schema.properties['data'].properties['relationships'].properties
11
15
 
12
- link.properties.each_with_object({}) do |(relationship, schema), acc|
16
+ relationships.each_with_object({}) do |(relationship, schema), acc|
13
17
  is_collection = schema.properties['data'].type.first == 'array'
14
18
 
15
19
  types = if is_collection
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.6.14'
4
+ VERSION = '0.6.15'
5
5
  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.6.14
4
+ version: 0.6.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-11 00:00:00.000000000 Z
11
+ date: 2018-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler