strapi_ruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +40 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +582 -0
- data/Rakefile +12 -0
- data/assets/strapi_ruby_logo.png +0 -0
- data/features.md +7 -0
- data/lib/strapi_ruby/client.rb +95 -0
- data/lib/strapi_ruby/config.rb +27 -0
- data/lib/strapi_ruby/configuration.rb +21 -0
- data/lib/strapi_ruby/endpoint/builder.rb +40 -0
- data/lib/strapi_ruby/endpoint/query.rb +31 -0
- data/lib/strapi_ruby/endpoint/strapi_parameters.rb +132 -0
- data/lib/strapi_ruby/errors/client_error.rb +48 -0
- data/lib/strapi_ruby/errors/configuration_error.rb +7 -0
- data/lib/strapi_ruby/errors/error_code.yml +9 -0
- data/lib/strapi_ruby/errors/error_message.rb +41 -0
- data/lib/strapi_ruby/errors/error_text.yml +13 -0
- data/lib/strapi_ruby/formatter.rb +88 -0
- data/lib/strapi_ruby/interface.rb +81 -0
- data/lib/strapi_ruby/markdown.rb +20 -0
- data/lib/strapi_ruby/railtie.rb +12 -0
- data/lib/strapi_ruby/tasks/config.rake +28 -0
- data/lib/strapi_ruby/validations.rb +63 -0
- data/lib/strapi_ruby/version.rb +5 -0
- data/lib/strapi_ruby.rb +27 -0
- data/rubocop.txt +4 -0
- data/sig/strapi_ruby.rbs +4 -0
- data/strapi_ruby.gemspec +44 -0
- metadata +135 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :strapi_ruby do
|
2
|
+
desc "Generates a configuration file within Rails applications"
|
3
|
+
task :config do
|
4
|
+
# Directory path for the config directory
|
5
|
+
initializers_dir = File.join(Rails.root, "config", "initializers")
|
6
|
+
|
7
|
+
# Configuration file path
|
8
|
+
config_file = File.join(initializers_dir, "strapi_ruby.rb")
|
9
|
+
|
10
|
+
# Check if the configuration file exists, and create it with default content if not
|
11
|
+
if File.exist?(config_file)
|
12
|
+
puts "StrapiRuby configuration file already exists."
|
13
|
+
else
|
14
|
+
# Define the configuration data (contents of strapi_ruby.rb)
|
15
|
+
config = <<-CONFIG
|
16
|
+
# Your StrapiRuby configuration goes here
|
17
|
+
# Check documentation for more configuration options
|
18
|
+
# https://github.com/saint-james-fr/strapi_ruby
|
19
|
+
StrapiRuby.configure do |config|
|
20
|
+
config.strapi_server_uri = "YOUR_SERVER_URI"
|
21
|
+
config.strapi_token = "YOUR_TOKEN"
|
22
|
+
end
|
23
|
+
CONFIG
|
24
|
+
File.write(config_file, config)
|
25
|
+
puts "StrapiRuby configuration file created at config/initializers/strapi_ruby.rb."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module StrapiRuby
|
2
|
+
module Validations
|
3
|
+
def validate_data_presence(options)
|
4
|
+
raise ArgumentError, ErrorMessage.missing_data unless options.key?(:data)
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate_config(config)
|
8
|
+
validate_mandatory_config_params(config.strapi_server_uri, config.strapi_token)
|
9
|
+
validate_faraday_block(config.faraday)
|
10
|
+
validate_show_endpoint_config(config.show_endpoint)
|
11
|
+
validate_convert_to_html(config.convert_to_html)
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_options(options)
|
15
|
+
validate_config_presence
|
16
|
+
validate_resource(options)
|
17
|
+
validate_id(options)
|
18
|
+
validate_show_endpoint_params(options)
|
19
|
+
validate_body(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate_convert_to_html(convert_to_html)
|
25
|
+
raise TypeError, "#{ErrorMessage.expected_array}. Got #{convert_to_html.class.name}" unless convert_to_html.is_a?(Array)
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_show_endpoint_config(show_endpoint)
|
29
|
+
raise TypeError, "#{ErrorMessage.expected_boolean}" unless [true, false].include?(show_endpoint)
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate_faraday_block(faraday)
|
33
|
+
raise TypeError, "#{ErrorMessage.expected_proc} Got #{faraday.class.name}" if !faraday.nil? && !faraday.is_a?(Proc)
|
34
|
+
end
|
35
|
+
|
36
|
+
def validate_mandatory_config_params(strapi_server_uri, strapi_token)
|
37
|
+
raise ConfigurationError, ErrorMessage.missing_strapi_server_uri if strapi_server_uri.nil? || strapi_server_uri.empty?
|
38
|
+
raise ConfigurationError, ErrorMessage.missing_strapi_token if strapi_token.nil? || strapi_token.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_config_presence
|
42
|
+
raise ConfigurationError, ErrorMessage.missing_configuration if @config.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_resource(options)
|
46
|
+
raise ArgumentError, ErrorMessage.missing_resource unless options.key?(:resource)
|
47
|
+
raise TypeError, "#{ErrorMessage.expected_string_symbol} Got #{options[:resource].class.name}" unless options[:resource].is_a?(String) || options[:resource].is_a?(Symbol)
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_id(options)
|
51
|
+
raise TypeError, "#{ErrorMessage.expected_integer} Got #{options[:id].class.name}" if options.key?(:id) && !options[:id].is_a?(Integer)
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate_show_endpoint_params(options)
|
55
|
+
raise TypeError, "#{ErrorMessage.expected_boolean}" if options[:show_endpoint] && ![true, false].include?(options[:show_endpoint])
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate_body(options)
|
59
|
+
return unless options.key?(:data)
|
60
|
+
raise TypeError, "#{ErrorMessage.expected_hash} Got #{options[:data].class.name}" unless options[:data].is_a?(Hash)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/strapi_ruby.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "strapi_ruby/version"
|
4
|
+
require_relative "strapi_ruby/validations"
|
5
|
+
require_relative "strapi_ruby/endpoint/builder"
|
6
|
+
require_relative "strapi_ruby/endpoint/strapi_parameters"
|
7
|
+
require_relative "strapi_ruby/endpoint/query"
|
8
|
+
require_relative "strapi_ruby/markdown"
|
9
|
+
require_relative "strapi_ruby/formatter"
|
10
|
+
require_relative "strapi_ruby/interface"
|
11
|
+
require_relative "strapi_ruby/client"
|
12
|
+
require_relative "strapi_ruby/configuration"
|
13
|
+
require_relative "strapi_ruby/config"
|
14
|
+
|
15
|
+
# Load errors
|
16
|
+
require_relative "strapi_ruby/errors/client_error"
|
17
|
+
require_relative "strapi_ruby/errors/configuration_error"
|
18
|
+
require_relative "strapi_ruby/errors/error_message"
|
19
|
+
|
20
|
+
# Load Rake tasks within Rails applications
|
21
|
+
require_relative "strapi_ruby/railtie" if defined?(Rails)
|
22
|
+
|
23
|
+
module StrapiRuby
|
24
|
+
extend Configuration
|
25
|
+
extend Interface
|
26
|
+
end
|
27
|
+
|
data/rubocop.txt
ADDED
data/sig/strapi_ruby.rbs
ADDED
data/strapi_ruby.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/strapi_ruby/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "strapi_ruby"
|
7
|
+
spec.version = StrapiRuby::VERSION
|
8
|
+
spec.authors = ["Maxence Robinet"]
|
9
|
+
spec.email = ["contact@maxencerobinet.fr"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby wrapper around Strapi API."
|
12
|
+
spec.description = <<-DESC
|
13
|
+
StrapiRuby is a Ruby gem designed to simplify interactions
|
14
|
+
with the Strapi CMS API. It provides an easy-to-use interface for
|
15
|
+
making requests to a Strapi server and handling responses.
|
16
|
+
DESC
|
17
|
+
|
18
|
+
spec.homepage = "https://github.com/saint-james-fr/strapi_ruby"
|
19
|
+
spec.license = "MIT"
|
20
|
+
spec.required_ruby_version = ">= 2.6.0"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/saint-james-fr/strapi_ruby/blob/master/CHANGELOG.md"
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(__dir__) do
|
29
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
30
|
+
(File.expand_path(f) == __FILE__) ||
|
31
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
# Uncomment to register a new dependency of your gem
|
39
|
+
spec.add_dependency "faraday", "~> 2.7"
|
40
|
+
spec.add_dependency "redcarpet", "~> 3.6"
|
41
|
+
|
42
|
+
spec.add_development_dependency "dotenv", "~> 2.8"
|
43
|
+
spec.add_development_dependency "webmock", "~> 3.19"
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strapi_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxence Robinet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redcarpet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.19'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.19'
|
69
|
+
description: |2
|
70
|
+
StrapiRuby is a Ruby gem designed to simplify interactions
|
71
|
+
with the Strapi CMS API. It provides an easy-to-use interface for
|
72
|
+
making requests to a Strapi server and handling responses.
|
73
|
+
email:
|
74
|
+
- contact@maxencerobinet.fr
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- CHANGELOG.md
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- assets/strapi_ruby_logo.png
|
86
|
+
- features.md
|
87
|
+
- lib/strapi_ruby.rb
|
88
|
+
- lib/strapi_ruby/client.rb
|
89
|
+
- lib/strapi_ruby/config.rb
|
90
|
+
- lib/strapi_ruby/configuration.rb
|
91
|
+
- lib/strapi_ruby/endpoint/builder.rb
|
92
|
+
- lib/strapi_ruby/endpoint/query.rb
|
93
|
+
- lib/strapi_ruby/endpoint/strapi_parameters.rb
|
94
|
+
- lib/strapi_ruby/errors/client_error.rb
|
95
|
+
- lib/strapi_ruby/errors/configuration_error.rb
|
96
|
+
- lib/strapi_ruby/errors/error_code.yml
|
97
|
+
- lib/strapi_ruby/errors/error_message.rb
|
98
|
+
- lib/strapi_ruby/errors/error_text.yml
|
99
|
+
- lib/strapi_ruby/formatter.rb
|
100
|
+
- lib/strapi_ruby/interface.rb
|
101
|
+
- lib/strapi_ruby/markdown.rb
|
102
|
+
- lib/strapi_ruby/railtie.rb
|
103
|
+
- lib/strapi_ruby/tasks/config.rake
|
104
|
+
- lib/strapi_ruby/validations.rb
|
105
|
+
- lib/strapi_ruby/version.rb
|
106
|
+
- rubocop.txt
|
107
|
+
- sig/strapi_ruby.rbs
|
108
|
+
- strapi_ruby.gemspec
|
109
|
+
homepage: https://github.com/saint-james-fr/strapi_ruby
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata:
|
113
|
+
homepage_uri: https://github.com/saint-james-fr/strapi_ruby
|
114
|
+
source_code_uri: https://github.com/saint-james-fr/strapi_ruby
|
115
|
+
changelog_uri: https://github.com/saint-james-fr/strapi_ruby/blob/master/CHANGELOG.md
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.6.0
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.3.7
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Ruby wrapper around Strapi API.
|
135
|
+
test_files: []
|