search-kit 0.0.1

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: 6e885ffbac473291386f4b7629cbef29e0f720c8
4
+ data.tar.gz: eb250e6aa6300ca73ff6d55e11812a1fdfda3485
5
+ SHA512:
6
+ metadata.gz: eb3fe55a47646cdfbde1fef77ee991e31479c6452c129d5f89d96d32491def796b0ee160e086cc0b9ed4ca3196ab8a72d87de2729f32b2b9ea284c29c16b1cbb
7
+ data.tar.gz: abf621d8a58167a6e38657f8b0f78406f4dd85985551fbe88e63fffabc8e035c28ca5c659f904dff9b65fbff865f477fdd8291e8e2107412463741ecf2ac11f2
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ _yardoc/
2
+ .bundle/
3
+ .DS_Store
4
+ .env
5
+ .gem
6
+ .sass-cache/
7
+ .yardoc
8
+ *.db
9
+ coverage/
10
+ Gemfile.lock
11
+ log/
12
+ node_modules/
13
+ pkg/
14
+ spec/reports/
15
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ Exclude:
3
+ - db/**/*
4
+
5
+ Style/FileName:
6
+ Enabled: false
7
+
8
+ StringLiterals:
9
+ Enabled: false
10
+
11
+ Style/ExtraSpacing:
12
+ Enabled: false
13
+
14
+ Style/SpaceInsideParens:
15
+ Enabled: false
16
+
17
+ Style/SpaceInsideBrackets:
18
+ Enabled: false
19
+
20
+ Style/EmptyLinesAroundModuleBody:
21
+ Enabled: false
22
+
23
+ Style/EmptyLinesAroundBlockBody:
24
+ Enabled: false
25
+
26
+ Style/EmptyLinesAroundClassBody:
27
+ Enabled: false
28
+
29
+ Style/AlignArray:
30
+ Enabled: false
31
+
32
+ Style/AlignHash:
33
+ Enabled: false
34
+
35
+ Style/AlignParameters:
36
+ Enabled: false
37
+
38
+ Style/MultilineOperationIndentation:
39
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in service-layer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joseph McCormick
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # SearchKit
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/service/layer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ * Notes about pulling, renaming, and spots to rename.
8
+
9
+ ## Usage
10
+
11
+ * Details about configuration and ENV variables.
12
+ * APP_ENV / app_env
13
+ * APP_DIR / app_dir
14
+ * APP_URI / app_uri
15
+ * LOG_DIR / log_dir
16
+
17
+ ## Development
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/esmevane/service-layer.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: [:spec]
data/bin/search-kit ADDED
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'search_kit'
6
+
7
+ SearchKit::CLI.start(ARGV)
@@ -0,0 +1,6 @@
1
+ en:
2
+ http:
3
+ 400: "Bad request"
4
+ 401:
5
+ inactive: "Inactive or expired token"
6
+ privilege: "Inadequate permissions on token"
data/lib/search_kit.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'bundler/setup'
2
+ require 'i18n'
3
+ require "search_kit/version"
4
+
5
+ module SearchKit
6
+ autoload :CLI, 'search_kit/cli'
7
+ autoload :Client, 'search_kit/client'
8
+ autoload :Configuration, 'search_kit/configuration'
9
+ autoload :Documents, 'search_kit/documents'
10
+ autoload :Errors, 'search_kit/errors'
11
+ autoload :Events, 'search_kit/events'
12
+ autoload :Indices, 'search_kit/indices'
13
+ autoload :Logger, 'search_kit/logger'
14
+ autoload :Messaging, 'search_kit/messaging'
15
+ autoload :Search, 'search_kit/search'
16
+
17
+ def self.logger
18
+ @logger ||= Logger.new
19
+ end
20
+
21
+ extend Configuration
22
+
23
+ configure do |config|
24
+ config.app_uri = ENV.fetch("APP_URI", "http://localhost:8080")
25
+ config.app_env = ENV.fetch("APP_ENV", "development")
26
+ config.app_dir = ENV.fetch("APP_DIR", nil) || Dir.pwd
27
+ config.verbose = ENV.fetch("APP_VERBOSE", true)
28
+
29
+ config.log_dir = ENV.fetch("LOG_DIR") do
30
+ Dir.mkdir('log') unless Dir.exist?('log')
31
+
32
+ 'log'
33
+ end
34
+
35
+ config.config_dir = File.join(config.app_dir, "config")
36
+ config.token_strategy = -> token { nil }
37
+ end
38
+
39
+ I18n.load_path += Dir.glob(File.join(config.config_dir, "locales/*.yml"))
40
+
41
+ end
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+
3
+ module SearchKit
4
+ class CLI < Thor
5
+ desc "documents", "Manage individual SearchKit documents"
6
+ subcommand "documents", SearchKit::Documents::CLI
7
+
8
+ desc "events", "Publish and subscribe to SearchKit events"
9
+ subcommand "events", SearchKit::Events::CLI
10
+
11
+ desc "indices", "Manage your SearchKit indices"
12
+ subcommand "indices", SearchKit::Indices::CLI
13
+
14
+ desc "search", "Quickly search your indices"
15
+ subcommand "search", SearchKit::Search::CLI
16
+
17
+ desc "config", "Configure your SearchKit settings"
18
+ def config
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require 'faraday'
2
+
3
+ module SearchKit
4
+ module Client
5
+ def self.connection
6
+ @connection ||= Faraday.new(SearchKit.config.app_uri)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+ require 'uri'
4
+
5
+ module SearchKit
6
+ module Configuration
7
+
8
+ def configure
9
+ yield(config) if block_given?
10
+ end
11
+
12
+ def config
13
+ @config ||= OpenStruct.new
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module SearchKit
6
+ class Documents
7
+ autoload :CLI, 'search_kit/documents/cli'
8
+
9
+ attr_reader :connection
10
+
11
+ def initialize
12
+ @connection = SearchKit::Client.connection
13
+ end
14
+
15
+ def create(slug, options)
16
+ document = { data: { type: "documents", attributes: options } }
17
+ response = connection.post(slug, document)
18
+ body = JSON.parse(response.body, symbolize_names: true)
19
+
20
+ fail Errors::BadRequest if response.status == 400
21
+ fail Errors::IndexNotFound if response.status == 404
22
+ fail Errors::Unprocessable if response.status == 422
23
+
24
+ body
25
+ end
26
+
27
+ def show(slug, id)
28
+ response = connection.get("#{slug}/#{id}")
29
+ body = JSON.parse(response.body, symbolize_names: true)
30
+
31
+ fail Errors::IndexNotFound if response.status == 404
32
+
33
+ body
34
+ end
35
+
36
+ def update(slug, id, options)
37
+ document = { data: { type: "documents", id: id, attributes: options } }
38
+ response = connection.patch("#{slug}/#{id}", document)
39
+ body = JSON.parse(response.body, symbolize_names: true)
40
+
41
+ fail Errors::BadRequest if response.status == 400
42
+ fail Errors::IndexNotFound if response.status == 404
43
+ fail Errors::Unprocessable if response.status == 422
44
+
45
+ body
46
+ end
47
+
48
+ def delete(slug, id)
49
+ response = connection.delete("#{slug}/#{id}")
50
+ body = JSON.parse(response.body, symbolize_names: true)
51
+
52
+ fail Errors::IndexNotFound if response.status == 404
53
+
54
+ body
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,70 @@
1
+ require 'thor'
2
+
3
+ module SearchKit
4
+ class Documents
5
+ class CLI < Thor
6
+ include Messaging
7
+
8
+ namespace :documents
9
+
10
+ desc "show SLUG ID", "View a document"
11
+ def show(slug, id)
12
+ response = client.show(slug, id)
13
+ info response.to_json
14
+ rescue Errors::IndexNotFound
15
+ warning "No index for that slug found (could also be missing doc)"
16
+ rescue Faraday::ConnectionFailed
17
+ warning "No running service found"
18
+ end
19
+
20
+ desc "create SLUG DOCUMENT", "Create a document with a json string"
21
+ def create(slug, document)
22
+ document = JSON.parse(document, symbolize_names: true)
23
+ response = client.create(slug, document)
24
+ info response.to_json
25
+ rescue JSON::ParserError
26
+ warning "Document must be given in the form of a JSON string"
27
+ rescue Errors::BadRequest
28
+ warning "Bad request given"
29
+ rescue Errors::Unprocessable
30
+ warning "Options given unprocessable"
31
+ rescue Faraday::ConnectionFailed
32
+ warning "No running service found"
33
+ end
34
+
35
+ desc "update SLUG ID DOCUMENT", "Update a document with a json string"
36
+ def update(slug, id, document)
37
+ document = JSON.parse(document, symbolize_names: true)
38
+ response = client.update(slug, id, document)
39
+ info response.to_json
40
+ rescue JSON::ParserError
41
+ warning "Document must be given in the form of a JSON string"
42
+ rescue Errors::BadRequest
43
+ warning "Bad request given"
44
+ rescue Errors::IndexNotFound
45
+ warning "Unable to find either the given index or document"
46
+ rescue Errors::Unprocessable
47
+ warning "Options given unprocessable"
48
+ rescue Faraday::ConnectionFailed
49
+ warning "No running service found"
50
+ end
51
+
52
+ desc "delete SLUG ID", "Delete a document"
53
+ def delete(slug, id)
54
+ response = client.delete(slug, id)
55
+ info response.to_json
56
+ rescue Errors::IndexNotFound
57
+ warning "Unable to find either the given index or document"
58
+ rescue Faraday::ConnectionFailed
59
+ warning "No running service found"
60
+ end
61
+
62
+ private
63
+
64
+ def client
65
+ @client ||= Documents.new
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ module SearchKit
2
+ module Errors
3
+ class BadRequest < StandardError; end
4
+ class IndexNotFound < StandardError; end
5
+ class PublicationFailed < StandardError; end
6
+ class EventNotFound < StandardError; end
7
+ class Unprocessable < StandardError; end
8
+ end
9
+ end
@@ -0,0 +1,57 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module SearchKit
6
+ class Events
7
+ autoload :CLI, 'search_kit/events/cli'
8
+ autoload :Publish, 'search_kit/events/publish'
9
+
10
+ attr_reader :connection
11
+
12
+ def initialize
13
+ @connection = SearchKit::Client.connection
14
+ end
15
+
16
+ def complete(id)
17
+ response = connection.delete("/api/events/#{id}")
18
+ body = JSON.parse(response.body, symbolize_names: true)
19
+
20
+ fail Errors::EventNotFound if response.status == 404
21
+
22
+ body
23
+ end
24
+
25
+ def index
26
+ response = connection.get('/api/events')
27
+
28
+ JSON.parse(response.body, symbolize_names: true)
29
+ end
30
+
31
+ def show(id)
32
+ response = connection.get("/api/events/#{id}")
33
+ body = JSON.parse(response.body, symbolize_names: true)
34
+
35
+ fail Errors::EventNotFound if response.status == 404
36
+
37
+ body
38
+ end
39
+
40
+ def pending(channel)
41
+ response = connection.get("/api/events?filter[channel]=#{channel}")
42
+
43
+ JSON.parse(response.body, symbolize_names: true)
44
+ end
45
+
46
+ def publish(channel, payload)
47
+ action = Publish.new(
48
+ channel: channel,
49
+ connection: connection,
50
+ payload: payload
51
+ )
52
+
53
+ action.perform
54
+ end
55
+
56
+ end
57
+ end