schemaless_rest_api 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
+ SHA256:
3
+ metadata.gz: b53d03f54666f144c3dae0f2414fd55e93e3f3fecb009baaef864f923f9f8cea
4
+ data.tar.gz: 33ea31cdec641dc7e1325dafa813f941e32ceaebe8fa04f2425692a0608bfbe4
5
+ SHA512:
6
+ metadata.gz: 1a8ffcf689c4458a52df4ea3bdd94e8c368df7ee53859408ac8278bc0a72cb49bdc1c5186d70a6544d04b7d2eeef73d5fa4586ea6197c8b87eca54cd1a7144af
7
+ data.tar.gz: e5e92db62919640ed8674d397119d12432b8789c07b32f64b7d860b0df1d27d2cc3f66c8277a96c00cb52c422581e335da4b1067997bf3266e1b025aa38e7594
data/.idea/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ # Default ignored files
2
+ /workspace.xml
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.6.3" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/schemaless_rest_api.iml" filepath="$PROJECT_DIR$/.idea/schemaless_rest_api.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ schemaless_rest_api
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-10
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in schemaless_rest_api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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,42 @@
1
+ # SchemalessRestApi
2
+
3
+ Simple schema less rest API that can be run in docker and have entities configured through a simple list of environment variables.
4
+ It follows convention over configuration to allow you to get a REST api that stores unstructured data fast.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'schemaless_rest_api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install schemaless_rest_api
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/schemaless_rest_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/schemaless_rest_api/blob/master/CODE_OF_CONDUCT.md).
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the SchemalessRestApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/schemaless_rest_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "schemaless_rest_api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+ require "schemaless_rest_api"
6
+
7
+ RestServer.run!
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Entities mapped by environment variables
4
+ class Entities
5
+ @models = {}
6
+ class << self
7
+ attr_accessor :models
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sinatra"
4
+ require "puma"
5
+
6
+ class RestServer < Sinatra::Base
7
+ set :server, :puma
8
+ enable :logging if ENV["debug"] == "true"
9
+ set :bind, "0.0.0.0"
10
+
11
+ def has_id?(model, id)
12
+ Entities.models[model].key?(id)
13
+ end
14
+
15
+ def not_found(id)
16
+ [404, JSON.generate({ error: "'#{id}' not found" })]
17
+ end
18
+
19
+ get "/" do
20
+ JSON.generate({ models: Entities.models.keys.to_s })
21
+ end
22
+
23
+ Entities.models.each_key do |model|
24
+ post "/#{model}" do
25
+ id = SecureRandom.uuid
26
+ Entities.models[model][id] = JSON.parse(request.body.read)
27
+ [201, id]
28
+ end
29
+
30
+ get "/#{model}" do
31
+ puts params
32
+ puts params.class
33
+ puts params == {}
34
+ return [200, Entities.models[model].to_s] if params == {}
35
+
36
+ Entities.models[model].values.find_all { |val| val[params.keys[0]] == params.values[0] }
37
+ rescue Exception
38
+ [404, "Nothing found using #{params}. Only first param considered"]
39
+ end
40
+
41
+ get "/#{model}/:id" do |id|
42
+ return not_found(id) unless has_id?(model, id)
43
+
44
+ JSON.generate(Entities.models[model][id])
45
+ end
46
+
47
+ put "/#{model}/:id" do |id|
48
+ return not_found(id) unless has_id?(model, id)
49
+
50
+ Entities.models[model][id] = JSON.parse(request.body.read)
51
+ 204
52
+ end
53
+
54
+ delete "/#{model}/:id" do |id|
55
+ return not_found(id) unless has_id?(model, id)
56
+
57
+ Entities.models[model].delete(id)
58
+ 204
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SchemalessRestApi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "schemaless_rest_api/version"
4
+ require_relative "schemaless_rest_api/entities"
5
+
6
+ require "json"
7
+ require "securerandom"
8
+
9
+ def extract_models
10
+ error_msg = "Make 'models' environment variable an array (e.g ['model1', 'model2'])"
11
+ raise "Please set 'models' ENV variable. #{error_msg}" if ENV["models"].nil?
12
+
13
+ models = eval(ENV["models"])
14
+ raise error_msg unless models.is_a? Array
15
+
16
+ models
17
+ end
18
+
19
+ extract_models.each do |model|
20
+ Entities.models[model.to_sym] = {}
21
+ end
22
+
23
+ puts "Modelling #{Entities.models.keys}"
24
+
25
+ require_relative "schemaless_rest_api/rest_server"
26
+
27
+ module SchemalessRestApi
28
+ class Error < StandardError; end
29
+ # Your code goes here...
30
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/schemaless_rest_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "schemaless_rest_api"
7
+ spec.version = SchemalessRestApi::VERSION
8
+ spec.authors = ["Samuel Garratt"]
9
+ spec.email = ["samuel.garratt@sentify.co"]
10
+
11
+ spec.summary = "TSimple schema less rest API that have entities configured through environment variables"
12
+ spec.description = "Simple schema less rest API that can be run in docker and have entities configured through a simple list of environment variables.
13
+ It follows convention over configuration to allow you to get a REST api that stores unstructured data fast."
14
+ spec.homepage = "https://gitlab.com/samuel-garratt/schemaless_rest_api"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.6.0"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://gitlab.com/samuel-garratt/schemaless_rest_api"
20
+ spec.metadata["changelog_uri"] = "https://gitlab.com/samuel-garratt/schemaless_rest_api/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "mongodb", "~> 1.0"
35
+ spec.add_dependency "sinatra"
36
+ # spec.add_dependency "sinatra-docdsl"
37
+ spec.add_dependency "puma"
38
+ spec.add_dependency "thor"
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,4 @@
1
+ module SchemalessRestApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schemaless_rest_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Garratt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
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: puma
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |-
56
+ Simple schema less rest API that can be run in docker and have entities configured through a simple list of environment variables.
57
+ It follows convention over configuration to allow you to get a REST api that stores unstructured data fast.
58
+ email:
59
+ - samuel.garratt@sentify.co
60
+ executables:
61
+ - schemaless_rest_api
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".idea/.gitignore"
66
+ - ".idea/inspectionProfiles/Project_Default.xml"
67
+ - ".idea/misc.xml"
68
+ - ".idea/modules.xml"
69
+ - ".idea/vcs.xml"
70
+ - ".rspec"
71
+ - ".rubocop.yml"
72
+ - ".ruby-gemset"
73
+ - ".ruby-version"
74
+ - CHANGELOG.md
75
+ - CODE_OF_CONDUCT.md
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - exe/schemaless_rest_api
83
+ - lib/schemaless_rest_api.rb
84
+ - lib/schemaless_rest_api/entities.rb
85
+ - lib/schemaless_rest_api/rest_server.rb
86
+ - lib/schemaless_rest_api/version.rb
87
+ - schemaless_rest_api.gemspec
88
+ - sig/schemaless_rest_api.rbs
89
+ homepage: https://gitlab.com/samuel-garratt/schemaless_rest_api
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ homepage_uri: https://gitlab.com/samuel-garratt/schemaless_rest_api
94
+ source_code_uri: https://gitlab.com/samuel-garratt/schemaless_rest_api
95
+ changelog_uri: https://gitlab.com/samuel-garratt/schemaless_rest_api/CHANGELOG.md
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.6.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.2.32
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: TSimple schema less rest API that have entities configured through environment
115
+ variables
116
+ test_files: []