dato 0.6.14 → 0.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/lib/dato/api_client.rb +33 -5
 - data/lib/dato/json_api_deserializer.rb +1 -7
 - data/lib/dato/json_api_serializer.rb +1 -1
 - data/lib/dato/json_schema_relationships.rb +9 -5
 - data/lib/dato/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 18f6bab733bb56da0e48f7141e919700ecf428d7dafa5e79812bdd01de16c5bc
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6b2f8b434254f0830c5c7d3e1a729f8752474ddab549e2b1bcc85771f0d0a136
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b8cc64b4cafeed1887cbc481f7e01c89ace6ba1597082b2ae42adf03c2a4ad284db40e920a060bcb9b91f7516b3466f8d8456c0f816ccf29c7d4ae3dc0bf1e84
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e2d408db575c37e60f33c472ce4c6698d4dc115e7c95757a788414d4822ca2dd129a7007f034e6091f554a5d23caf506f0b59113a41c6fc7fa1659d865edd478
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/dato/api_client.rb
    CHANGED
    
    | 
         @@ -72,15 +72,43 @@ module Dato 
     | 
|
| 
       72 
72 
     | 
    
         
             
                  puts e.message
         
     | 
| 
       73 
73 
     | 
    
         
             
                  raise e
         
     | 
| 
       74 
74 
     | 
    
         
             
                rescue Faraday::ClientError => e
         
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 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( 
     | 
| 
       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
         
     | 
| 
         @@ -1,15 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Dato
         
     | 
| 
       2 
2 
     | 
    
         
             
              class JsonSchemaRelationships
         
     | 
| 
       3 
     | 
    
         
            -
                attr_reader : 
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :schema
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                def initialize( 
     | 
| 
       6 
     | 
    
         
            -
                  @ 
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(schema)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @schema = schema
         
     | 
| 
       7 
7 
     | 
    
         
             
                end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                def relationships
         
     | 
| 
       10 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
      
 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
         
     | 
    
        data/lib/dato/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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 
     | 
    
         
            +
            date: 2018-12-16 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |