jschema 0.2.0 → 0.2.1

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: 5d4b107701aecdbf3da8a1f497e1ea5464005b5f
4
- data.tar.gz: 7f37df5b104add21c85fb491925d932b4c708212
3
+ metadata.gz: 32ddf45ff9ed3c8f8922bd23962d932ec921d42c
4
+ data.tar.gz: ec0efce314be4969803f3cdec809099011af6495
5
5
  SHA512:
6
- metadata.gz: 40ec990c33022c4983b23aaeb1e1859da7f8e260138a981c02b732dcdeb7fcb1a643acc0a4b7048c0e8e5b7716bf0b774e07471d43adccdc07600bfd2945912e
7
- data.tar.gz: e0240a32c0769dee642d98f5fffbe599b94c316dab0c1ecba68e8dd4cbca6b71695c46e7328ab4ce8a76bcf6228418a6a213f5e0b56e546483526ca203404e91
6
+ metadata.gz: eee310162f1b3484ecd1541e80cfc40b3f837f6d2fc56d88bdb3d3446ce0cf4ed271685845e7357bae000b073a4192d8af9f89db0fb756ceb1f31141797ba4ce
7
+ data.tar.gz: 3cff14eacb201b794b15372d62abd997dcbba14659a7332e9c0a6d44e38aacd1a435856e24acd5cab2c504993f8cf6e12ed0862f06e26204d8e710c773f95515
@@ -65,8 +65,8 @@ module JSchema
65
65
  schema_data = JSON.parse download_schema(uri)
66
66
  parent_schema = schema && schema.parent
67
67
  Schema.build(schema_data, parent_schema, uri.to_s)
68
- rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED
69
- raise InvalidSchema, "Failed to download external schema: #{uri}"
68
+ rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED, Net::HTTPBadResponse => e
69
+ raise InvalidSchema, "Failed to download external schema #{uri}. #{e.class}: #{e.message}"
70
70
  end
71
71
 
72
72
  def valid_external_uri?(uri)
@@ -74,24 +74,30 @@ module JSchema
74
74
  end
75
75
 
76
76
  def download_schema(uri)
77
- request = Net::HTTP::Get.new(uri.to_s)
78
- request['Accept'] = 'application/json+schema'
79
-
80
- http = Net::HTTP.new(uri.hostname, uri.port)
81
- http.read_timeout = 3
82
- http.open_timeout = 2
83
- http.continue_timeout = 1
84
-
85
- http.request(request).body
77
+ 3.times do
78
+ request = Net::HTTP::Get.new(uri.to_s)
79
+ request['Accept'] = 'application/json+schema'
80
+
81
+ http = Net::HTTP.new(uri.hostname, uri.port)
82
+ http.read_timeout = 3
83
+ http.open_timeout = 2
84
+ http.continue_timeout = 1
85
+ response = http.request(request)
86
+ if ["301", "302"].include?(response.code)
87
+ uri = URI.parse(response.header['location'])
88
+ else
89
+ return response.body
90
+ end
91
+ end
92
+ raise Net::HTTPBadResponse, "Too many redirects -- last location header was #{uri}"
86
93
  end
87
94
 
88
95
  def key(uri, schema)
89
96
  if schema
90
97
  root_schema = root(schema)
91
- "#{root_schema.object_id}:#{uri}"
92
- else
93
- uri.to_s
98
+ return "#{root_schema.object_id}:#{uri}"
94
99
  end
100
+ uri.to_s
95
101
  end
96
102
 
97
103
  def root(schema)
@@ -42,6 +42,13 @@ module JSchema
42
42
 
43
43
  attr_reader :uri, :parent
44
44
 
45
+ def initialize(schema, uri, parent)
46
+ @uri = uri
47
+ @parent = parent
48
+ @schema = schema
49
+ @validators = Validator.build(schema, self)
50
+ end
51
+
45
52
  def valid?(instance)
46
53
  validate(instance).empty?
47
54
  end
@@ -59,13 +66,5 @@ module JSchema
59
66
  def to_s
60
67
  uri.to_s
61
68
  end
62
-
63
- private
64
-
65
- def initialize(schema, uri, parent)
66
- @uri = uri
67
- @parent = parent
68
- @validators = Validator.build(schema, self)
69
- end
70
69
  end
71
70
  end
@@ -49,7 +49,7 @@ module JSchema
49
49
  end
50
50
 
51
51
  def integer?(value)
52
- value.is_a?(Fixnum) || value.is_a?(Bignum)
52
+ value.is_a?(Integer)
53
53
  end
54
54
 
55
55
  def greater_or_equal_to?(value, limit)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Papkovskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implementation of JSON Schema Draft 4
14
14
  email: konstantin@papkovskiy.com
@@ -47,7 +47,7 @@ files:
47
47
  - lib/jschema/validator/required.rb
48
48
  - lib/jschema/validator/type.rb
49
49
  - lib/jschema/validator/unique_items.rb
50
- homepage: http://github.com/Soylent/jschema
50
+ homepage: https://github.com/Soylent/jschema
51
51
  licenses:
52
52
  - MIT
53
53
  metadata: {}
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubyforge_project:
70
- rubygems_version: 2.5.1
70
+ rubygems_version: 2.6.8
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: JSON Schema implementation