iglu-ruby-client 0.1.0 → 0.2.0.beta

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
- SHA1:
3
- metadata.gz: e4645473809f6de1e11d74c472cec3c153da4f03
4
- data.tar.gz: 60924a1fe8c5f360d9b9f12c23a406faa3c3fda8
2
+ SHA256:
3
+ metadata.gz: a5f348ad495ca4e03d35075a7e9d79be3e686333cc6bd909281e495c374cb247
4
+ data.tar.gz: 206069a773a03d9453a3774344c1c3327073318cb540060262d7fbbdd31ad14c
5
5
  SHA512:
6
- metadata.gz: 04ffb86e0346bc61fbdce2ddad023d3326e313f803cc58599c67809c78967ede9c9bad1cb319ba2d38987dcb4c4322d4c1d11174c544d4851b37f1a29c873ee9
7
- data.tar.gz: e8a1eac53f5b407daabf852acd38eb584beec43677485b4ac39fece72454f2544d30f8d7973e4eb160455c16fe3c5976f30dcba21d377f5a10ce19e69773eeb7
6
+ metadata.gz: 6d249cbec95680becc4924c1da173eb7c15033839cc22a0623f39571646c1b034e8be88c754ab5fe88cb1463ea1abdf235db3c36be619deadcb3cd34e210f63e
7
+ data.tar.gz: f329af06ad188a7d6f52e0ec4d5259f16093aca503d374161f4c3125f1d92b974aa21690e8e52c2d0ee1972a6dd44980f8293191cb469678c4a8213bfe8921bb
data/README.md CHANGED
@@ -1,23 +1,24 @@
1
1
  # Ruby client for Iglu
2
2
 
3
- [![Build Status] [travis-image]] [travis]
4
- [![Release] [release-image]] [releases]
5
- [![License] [license-image]] [license]
6
- [![Coverage Status] [coveralls-image]] [coveralls]
3
+ [![Build Status][travis-image]][travis]
4
+ [![Release][release-image]][releases]
5
+ [![License][license-image]][license]
6
+ [![Coverage Status][coveralls-image]][coveralls]
7
7
 
8
- A Ruby client and resolver for **[Iglu schema repositories] [iglu-wiki]** from the team at **[Snowplow Analytics] [snowplow-website]**.
8
+ A Ruby client and resolver for **[Iglu schema repositories][iglu-wiki]** from the team at **[Snowplow Analytics][snowplow-website]**.
9
9
 
10
10
  ## Find out more
11
11
 
12
- | **[Technical Docs] [techdocs]** | **[Setup Guide] [setup]** | **[Roadmap] [roadmap]** | **[Contributing] [contributing]** |
13
- |-------------------------------------|-------------------------------|-----------------------------------|---------------------------------------------|
14
- | [![i1] [techdocs-image]] [techdocs] | [![i2] [setup-image]] [setup] | [![i3] [roadmap-image]] [roadmap] | [![i4] [contributing-image]] [contributing] |
12
+ | Technical Docs | Setup Guide | Roadmap | Contributing |
13
+ |--------------------------------|--------------------------|------------------------|----------------------------------|
14
+ | ![i1][techdocs-image] | ![i2][setup-image] | ![i3][roadmap-image] | ![i4][contributing-image] |
15
+ | **[Technical Docs][techdocs]** | **[Setup Guide][setup]** | **[Roadmap][roadmap]** | **[Contributing][contributing]** |
15
16
 
16
- ## Copyright and license
17
+ ## Copyright and License
17
18
 
18
- Iglu Ruby Client is copyright 2017 Snowplow Analytics Ltd.
19
+ Iglu Ruby Client is © 2017 Snowplow Analytics Ltd.
19
20
 
20
- Licensed under the **[Apache License, Version 2.0] [license]** (the "License");
21
+ Licensed under the **[Apache License, Version 2.0][license]** (the "License");
21
22
  you may not use this software except in compliance with the License.
22
23
 
23
24
  Unless required by applicable law or agreed to in writing, software
@@ -44,11 +45,10 @@ limitations under the License.
44
45
  [travis-image]: https://travis-ci.org/snowplow/iglu-ruby-client.png?branch=master
45
46
 
46
47
  [releases]: https://github.com/snowplow/ruby-iglu-client/releases
47
- [release-image]: http://img.shields.io/badge/release-0.1.0-blue.svg?style=flat
48
+ [release-image]: http://img.shields.io/badge/release-0.2.0-blue.svg?style=flat
48
49
 
49
50
  [license]: http://www.apache.org/licenses/LICENSE-2.0
50
51
  [license-image]: http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat
51
52
 
52
53
  [coveralls]: https://coveralls.io/r/snowplow/iglu-ruby-client
53
54
  [coveralls-image]: https://coveralls.io/repos/snowplow/iglu-ruby-client/badge.png
54
-
@@ -20,15 +20,7 @@ module Iglu
20
20
  SCHEMAVER_REGEX = Regexp.new "^([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$"
21
21
 
22
22
  # Class holding SchemaVer data
23
- class SchemaVer
24
- attr_accessor :model, :revision, :addition
25
-
26
- # Constructor. To initalize from string - use static parse_schemaver
27
- def initialize(model, revision, addition)
28
- @model = model
29
- @revision = revision
30
- @addition = addition
31
- end
23
+ class SchemaVer < Struct.new(:model, :revision, :addition)
32
24
 
33
25
  # Render as string
34
26
  def as_string
@@ -38,26 +30,17 @@ module Iglu
38
30
  # Construct SchemaVer from string
39
31
  def self.parse_schemaver(version)
40
32
  model, revision, addition = version.scan(SCHEMAVER_REGEX).flatten
41
- SchemaVer.new model.to_i, revision.to_i, addition.to_i
42
- end
43
-
44
- def ==(other)
45
- other.model == @model && other.revision == @revision && other.addition == @addition
33
+ if model.nil? or revision.nil? or addition.nil?
34
+ raise IgluError.new "Schema version #{version} is not a valid Iglu SchemaVer"
35
+ else
36
+ SchemaVer.new model.to_i, revision.to_i, addition.to_i
37
+ end
46
38
  end
47
39
  end
48
40
 
49
41
 
50
42
  # Class holding Schema metadata
51
- class SchemaKey
52
- attr_accessor :vendor, :name, :format, :version
53
-
54
- # Constructor. To initalize from string - use static parse_key
55
- def initialize(vendor, name, format, version)
56
- @vendor = vendor
57
- @name = name
58
- @format = format
59
- @version = version
60
- end
43
+ class SchemaKey < Struct.new(:vendor, :name, :format, :version)
61
44
 
62
45
  # Render as Iglu URI (with `iglu:`)
63
46
  def as_uri
@@ -79,10 +62,6 @@ module Iglu
79
62
  SchemaKey.new vendor, name, format, schema_ver
80
63
  end
81
64
  end
82
-
83
- def ==(other)
84
- other.vendor == @vendor && other.name == @name && other.format == @format && other.version == @version
85
- end
86
65
  end
87
66
 
88
67
 
@@ -41,13 +41,23 @@ module Iglu
41
41
  @uri = uri
42
42
  end
43
43
 
44
- def lookup_schema(schema_key)
44
+ def lookup_schema(schema_key, max_retries = 3)
45
45
  schema_uri = "#{@uri}/schemas/#{schema_key.as_path}"
46
+ times_retried = 0
47
+
46
48
  begin
47
- response = HTTParty.get(schema_uri)
49
+ response = HTTParty.get(schema_uri, timeout: 3)
48
50
  rescue SocketError => _
49
51
  raise IgluError.new "Iglu registry #{config.name} is not available"
52
+ rescue Net::ReadTimeout => e
53
+ if times_retried < max_retries
54
+ times_retried += 1
55
+ retry
56
+ else
57
+ raise e
58
+ end
50
59
  end
60
+
51
61
  if response.code == 200
52
62
  JSON::parse(response.body)
53
63
  else
@@ -16,11 +16,12 @@ module Iglu
16
16
 
17
17
  # Iglu Client. Able to fetch schemas only from Iglu Central
18
18
  class Resolver
19
- attr_reader :registries, :cache
19
+ attr_reader :registries, :cache, :cache_ttl
20
20
 
21
21
  def initialize(registries)
22
22
  @registries = registries.unshift(Registries.bootstrap)
23
23
  @cache = Hash.new
24
+ @cache_ttl = 1 # hour
24
25
  end
25
26
 
26
27
  # Lookup schema in cache or try to fetch
@@ -30,6 +31,7 @@ module Iglu
30
31
  end
31
32
  failures = []
32
33
 
34
+ fetch_time = Time.now.getutc
33
35
  cache_result = @cache[schema_key]
34
36
 
35
37
  if cache_result.nil? # Fetch from every registry
@@ -50,14 +52,22 @@ module Iglu
50
52
  if lookup_result.nil?
51
53
  raise Registries::ResolverError.new(failures, schema_key)
52
54
  else
53
- @cache[schema_key] = lookup_result
55
+ store_time = Time.now.getutc
56
+ @cache[schema_key] = [lookup_result, store_time]
54
57
  lookup_result
55
58
  end
56
59
  else
57
60
  if cache_result.is_a?(Registries::ResolverError)
58
61
  raise cache_result
59
62
  else
60
- cache_result
63
+ if cache_result.is_a? (Array)
64
+ if (cache_result[1] - fetch_time).round / 3600 >= @cache_ttl
65
+ @cache.delete(schema_key)
66
+ end
67
+ cache_result[0]
68
+ else # backward compliance
69
+ cache_result
70
+ end
61
71
  end
62
72
  end
63
73
  end
@@ -81,7 +91,7 @@ module Iglu
81
91
  Registries::EmbeddedRegistryRef.new(ref_config, config[:connection][:embedded][:path])
82
92
  elsif not config[:connection][:http].nil?
83
93
  Registries::HttpRegistryRef.new(ref_config, config[:connection][:http][:uri])
84
- else
94
+ else
85
95
  raise IgluError.new "Incorrect RegistryRef"
86
96
  end
87
97
  end
@@ -10,5 +10,5 @@
10
10
  # See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
11
 
12
12
  module Iglu
13
- CLIENT_VERSION = '0.1.0'
13
+ CLIENT_VERSION = '0.2.0.beta'
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iglu-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Parkhomenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -101,12 +101,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  version: 2.0.0
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
104
+ - - ">"
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: 1.3.1
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.4.5
109
+ rubygems_version: 2.7.0
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A Ruby client for Iglu