schema_registry 0.0.1 → 0.0.2

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: 0ae27f7cfce0bff061ce4ac247a11bae184d2bbd
4
- data.tar.gz: aa3fbeeeb5a04273d70588ee319d730d0644fe2a
3
+ metadata.gz: 123c56978eca9e032fb3031fd89fad4a8845a81b
4
+ data.tar.gz: e40bb00dcccdc774a9517f38763e1dfea2e9e4f0
5
5
  SHA512:
6
- metadata.gz: eba53efa53ede87f404ed70cf7405f5af0ccc10650796dd19038b8100bab76d16927b7e1bf0cfd2b6fe24b9780683b5aea38618b1e4ec71a640ae2231a8e6c91
7
- data.tar.gz: 572a7592030e7e576da373f112fa9961603dad0037072410e100bc5488899adb0d925215a85bbf5d0a636952a07d5b8660cb280674af17c36ded03226ca5be3c
6
+ metadata.gz: 23e48444ab0c919fa9f1ed578a98b5fbfffcc6a0ef64f8c6e6dcb5dd2caf0a5911d31b94292cf7d7a94a19600cf15c16048c833c3e15f5183b0d77182f3306f1
7
+ data.tar.gz: 56063fd8b4b087ef2121dc2b202ff105b8cb1f5a22bf7f5bcd4b179a0815b1af8e12b8a06f37333f6bda344bdb3d09d80ae996bf02ba457f567e0b8d13503d2b
@@ -11,6 +11,16 @@ module SchemaRegistry
11
11
  end
12
12
  end
13
13
 
14
+ RESPONSE_ERROR_CODES = {
15
+ 40401 => (SubjectNotFound = Class.new(SchemaRegistry::ResponseError)),
16
+ 40402 => (VersionNotFound = Class.new(SchemaRegistry::ResponseError)),
17
+ 40403 => (SchemaNotFound = Class.new(SchemaRegistry::ResponseError)),
18
+ 42201 => (InvalidAvroSchema = Class.new(SchemaRegistry::ResponseError)),
19
+ 42202 => (InvalidVersion = Class.new(SchemaRegistry::ResponseError)),
20
+ 42203 => (InvalidCompatibilityLevel = Class.new(SchemaRegistry::ResponseError)),
21
+ 409 => (IncompatibleAvroSchema = Class.new(SchemaRegistry::ResponseError)),
22
+ }
23
+
14
24
  class Client
15
25
 
16
26
  attr_reader :endpoint, :username, :password
@@ -62,8 +72,11 @@ module SchemaRegistry
62
72
  response = http.request(request)
63
73
  response_data = JSON.parse(response.body)
64
74
  case response
65
- when Net::HTTPOK; response_data
66
- else raise SchemaRegistry::ResponseError.new(response_data['error_code'], response_data['message'])
75
+ when Net::HTTPSuccess;
76
+ response_data
77
+ else
78
+ error_class = RESPONSE_ERROR_CODES[response_data['error_code']] || SchemaRegistry::ResponseError
79
+ raise error_class.new(response_data['error_code'], response_data['message'])
67
80
  end
68
81
  end
69
82
  end
@@ -1,5 +1,20 @@
1
1
  module SchemaRegistry
2
2
 
3
+ class SchemaRegistration
4
+ attr_accessor :subject, :id, :version, :schema
5
+
6
+ def initialize(subject, options = {})
7
+ @subject = subject
8
+ @id = options['id']
9
+ @version = options['version']
10
+ @schema = options['schema']
11
+ end
12
+
13
+ def pretty_json
14
+ JSON.pretty_generate(JSON.parse(@schema))
15
+ end
16
+ end
17
+
3
18
  class Subject
4
19
  attr_reader :client, :name
5
20
 
@@ -12,15 +27,15 @@ module SchemaRegistry
12
27
  end
13
28
 
14
29
  def version(version)
15
- client.request(:get, "/subjects/#{name}/versions/#{version}")
30
+ SchemaRegistration.new(self, client.request(:get, "/subjects/#{name}/versions/#{version}"))
16
31
  end
17
32
 
18
33
  def verify_schema(schema_json)
19
- client.request(:post, "/subjects/#{name}", schema: schema_json)
34
+ SchemaRegistration.new(self, client.request(:post, "/subjects/#{name}", schema: schema_json))
20
35
  end
21
36
 
22
- def update_schema(schema_json)
23
- client.request(:post, "/subjects/#{name}/versions", schema: schema_json)["id"]
37
+ def register_schema(schema_json)
38
+ client.request(:post, "/subjects/#{name}/versions", schema: schema_json)['id']
24
39
  end
25
40
 
26
41
  def compatibility_level
@@ -29,7 +44,7 @@ module SchemaRegistry
29
44
  end
30
45
 
31
46
  def compatibility_level=(level)
32
- response = client.request(:put, "/config/#{name}", compatibility: level)
47
+ client.request(:put, "/config/#{name}", compatibility: level)
33
48
  end
34
49
 
35
50
  def compatible?(schema, version = "latest")
@@ -1,3 +1,3 @@
1
1
  module SchemaRegistry
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler