neuromancer-indexer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 516f0524a5df3de1d2f9100852e154c8f05f9a07
4
+ data.tar.gz: eae5ec3dc3dd58e0a28aa9f4bc8e0309a47c0e2d
5
+ SHA512:
6
+ metadata.gz: f8172335f1065e6ed7de8695e23fd2258b261ebdb12ed9e4261fa9188769f99f62b087644b87a23a7f47f3ca948c4b613f0d149ec62e5f733ad0165ea89f40e6
7
+ data.tar.gz: 92683bb07be166097c36520a0c2c8b07b617663e29ad72c7d3ea75a44cda0d142e68631edd543ecf56f7f9900c1d2c3fe9ee4298dadbef3c4b29f15690f2fc6c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.3.8
6
+ - 2.5.5
7
+ before_install:
8
+ - gem install bundler -v 1.17.3
9
+ script:
10
+ - bundle exec rake spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Changelog
2
+
3
+ #### 0.1.0
4
+ - initial version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neuromancer-indexer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ neuromancer-indexer (0.1.0)
5
+ aws-sdk-sqs
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aws-eventstream (1.0.3)
11
+ aws-partitions (1.224.0)
12
+ aws-sdk-core (3.68.1)
13
+ aws-eventstream (~> 1.0, >= 1.0.2)
14
+ aws-partitions (~> 1.0)
15
+ aws-sigv4 (~> 1.1)
16
+ jmespath (~> 1.0)
17
+ aws-sdk-sqs (1.22.0)
18
+ aws-sdk-core (~> 3, >= 3.61.1)
19
+ aws-sigv4 (~> 1.1)
20
+ aws-sigv4 (1.1.0)
21
+ aws-eventstream (~> 1.0, >= 1.0.2)
22
+ diff-lcs (1.3)
23
+ jmespath (1.4.0)
24
+ rake (10.5.0)
25
+ rspec (3.9.0)
26
+ rspec-core (~> 3.9.0)
27
+ rspec-expectations (~> 3.9.0)
28
+ rspec-mocks (~> 3.9.0)
29
+ rspec-core (3.9.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-expectations (3.9.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-mocks (3.9.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-support (3.9.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 2.0)
44
+ neuromancer-indexer!
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
47
+
48
+ BUNDLED WITH
49
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Jörgen Dahlke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # neuromancer-indexer
2
+
3
+ [![Build Status](https://travis-ci.com/jdahlke/neuromancer-indexer.svg?branch=develop)](https://travis-ci.com/jdahlke/neuromancer-indexer)
4
+
5
+ Ruby gem to push data for indexing to the Neuromancer service
6
+
7
+ ### Configuration and Usage
8
+
9
+ ```
10
+ Neuromancer::Indexer.configure do |config|
11
+ config.region = 'eu-central-1'
12
+ config.sqs_url = 'https://sqs.eu-central-1.amazonaws.com/1234567890/neuromancer-index'
13
+ end
14
+
15
+ Neuromancer::Indexer.index({
16
+ id: 'id-1',
17
+ type: 'objects',
18
+ body: {
19
+ foo: 'foo-string',
20
+ bar: 123,
21
+ baz: ['abc', 'def']
22
+ }
23
+ })
24
+ ```
25
+
26
+
27
+ ### Installation
28
+
29
+ ```
30
+ gem 'neuromancer-indexer'
31
+
32
+ ```
33
+
34
+
35
+ ### Test
36
+
37
+ ```
38
+ bundle exec rake spec
39
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ desc 'Run all specs in spec directory (excluding plugin specs)'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'neuromancer/indexer'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'aws-sdk-sqs'
5
+
6
+ module Neuromancer
7
+ module Indexer
8
+ class Client
9
+ attr_reader :config
10
+
11
+ def initialize
12
+ @config = Neuromancer::Indexer.config
13
+ end
14
+
15
+ def index(obj)
16
+ message = obj.to_json
17
+ validate_message!(message)
18
+
19
+ sqs.send_message({
20
+ queue_url: config.sqs_url,
21
+ message_body: message,
22
+ delay_seconds: 1
23
+ })
24
+ end
25
+
26
+ private
27
+ def sqs
28
+ @sqs ||= Aws::SQS::Client.new(region: config.region)
29
+ end
30
+
31
+ def validate_message!(message)
32
+ hash = JSON.parse(message)
33
+ id = hash['id'].to_s
34
+ type = hash['type'].to_s
35
+ body = hash['body']
36
+
37
+ if id.empty?
38
+ raise Error, 'Key `id` in obj cannot be empty'
39
+ end
40
+
41
+ if type.empty?
42
+ raise Error, 'Key `type` in obj cannot be empty'
43
+ end
44
+
45
+ if !body.is_a?(Hash)
46
+ raise Error, 'Key `body` must be a Hash'
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module Neuromancer
6
+ module Indexer
7
+ class Configuration
8
+ attr_accessor :region
9
+ attr_accessor :sqs_url
10
+ attr_accessor :stage
11
+
12
+ def initialize
13
+ @region = 'eu-central-1'
14
+ end
15
+
16
+ def validate!
17
+ if region.to_s.empty?
18
+ raise ConfigurationError, '`region` cannot be empty'
19
+ end
20
+
21
+ if sqs_url.to_s.empty?
22
+ raise ConfigurationError, '`sqs_url` cannot be empty'
23
+ end
24
+
25
+ begin
26
+ if URI(sqs_url).scheme != 'https'
27
+ raise ConfigurationError, '`sqs_url` must be a HTTPS url'
28
+ end
29
+ rescue => e
30
+ raise ConfigurationError, '`sqs_url` must be a HTTPS url'
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,5 @@
1
+ module Neuromancer
2
+ module Indexer
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'neuromancer/indexer/version'
4
+ require 'neuromancer/indexer/client'
5
+ require 'neuromancer/indexer/configuration'
6
+
7
+ module Neuromancer
8
+ module Indexer
9
+ class Error < StandardError; end
10
+ class ConfigurationError < Error; end
11
+
12
+ def self.config
13
+ @config ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield config
18
+
19
+ config.validate!
20
+ @client = Client.new
21
+
22
+ config
23
+ end
24
+
25
+ def self.index(obj)
26
+ @client ||= Client.new
27
+ @client.index(obj)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'neuromancer/indexer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'neuromancer-indexer'
7
+ spec.version = Neuromancer::Indexer::VERSION
8
+ spec.authors = ['Joergen Dahlke']
9
+ spec.email = ['joergen.dahlke@infopark.de']
10
+
11
+ spec.summary = 'Ruby gem to push data for indexing to the Neuromancer service.'
12
+ spec.description = 'Ruby gem to push data for indexing to the Neuromancer service.'
13
+ spec.homepage = 'https://github.com/jdahlke/neuromancer-indexer'
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/jdahlke/neuromancer-indexer'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/jdahlke/neuromancer-indexer/blob/master/CHANGELOG.md'
23
+ else
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_dependency 'aws-sdk-sqs'
38
+
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neuromancer-indexer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joergen Dahlke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-sqs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Ruby gem to push data for indexing to the Neuromancer service.
70
+ email:
71
+ - joergen.dahlke@infopark.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/neuromancer/indexer.rb
88
+ - lib/neuromancer/indexer/client.rb
89
+ - lib/neuromancer/indexer/configuration.rb
90
+ - lib/neuromancer/indexer/version.rb
91
+ - neuromancer-indexer.gemspec
92
+ homepage: https://github.com/jdahlke/neuromancer-indexer
93
+ licenses: []
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ homepage_uri: https://github.com/jdahlke/neuromancer-indexer
97
+ source_code_uri: https://github.com/jdahlke/neuromancer-indexer
98
+ changelog_uri: https://github.com/jdahlke/neuromancer-indexer/blob/master/CHANGELOG.md
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Ruby gem to push data for indexing to the Neuromancer service.
119
+ test_files: []