-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
161 changed files
with
8,400 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/convenient_service/examples/standard/request_params.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "request_params/constants" | ||
require_relative "request_params/entities" | ||
require_relative "request_params/services" | ||
require_relative "request_params/utils" | ||
|
||
## | ||
# @since 0.3.0 | ||
# | ||
# @internal | ||
# Usage example: | ||
# | ||
# http_string = | ||
# <<~TEXT | ||
# POST /rules/1000000.json HTTP/1.1 | ||
# User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 | ||
# Host: code-review.com | ||
# Content-Type: application/json; charset=utf-8 | ||
# Content-Length: 134 | ||
# Accept-Language: en-us | ||
# Accept-Encoding: gzip, deflate | ||
# Connection: Keep-Alive | ||
# | ||
# {"title":"Avoid error shadowing","description":"Check the official User Docs","tags":["error-shadowing"]} | ||
# TEXT | ||
# | ||
# request = ConvenientService::Examples::Standard::RequestParams::Entities::Request.new(http_string:) | ||
# | ||
# ConvenientService::Examples::Standard::RequestParams.prepare(request) | ||
# | ||
# - https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types | ||
# - https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome | ||
# - https://www.tutorialspoint.com/http/http_requests.htm | ||
# | ||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
class << self | ||
def prepare(request) | ||
Services::Prepare[request: request] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
lib/convenient_service/examples/standard/request_params/constants.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Constants | ||
module Tags | ||
EMPTY = "" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/convenient_service/examples/standard/request_params/entities.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "entities/logger" | ||
require_relative "entities/request" | ||
|
||
require_relative "entities/description" | ||
require_relative "entities/format" | ||
require_relative "entities/id" | ||
require_relative "entities/source" | ||
require_relative "entities/tag" | ||
require_relative "entities/title" |
40 changes: 40 additions & 0 deletions
40
lib/convenient_service/examples/standard/request_params/entities/description.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Entities | ||
class Description | ||
def initialize(value:) | ||
@value = value | ||
end | ||
|
||
class << self | ||
def cast(value) | ||
case value | ||
when ::String | ||
new(value: value.to_s) | ||
end | ||
end | ||
end | ||
|
||
def ==(other) | ||
return unless other.instance_of?(self.class) | ||
|
||
value == other.value | ||
end | ||
|
||
def to_s | ||
value | ||
end | ||
|
||
protected | ||
|
||
attr_reader :value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
lib/convenient_service/examples/standard/request_params/entities/format.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Entities | ||
class Format | ||
def initialize(value:) | ||
@value = value | ||
end | ||
|
||
class << self | ||
def cast(value) | ||
case value | ||
when ::String | ||
new(value: value.to_s) | ||
end | ||
end | ||
end | ||
|
||
def ==(other) | ||
return unless other.instance_of?(self.class) | ||
|
||
value == other.value | ||
end | ||
|
||
def to_s | ||
value | ||
end | ||
|
||
protected | ||
|
||
attr_reader :value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
lib/convenient_service/examples/standard/request_params/entities/id.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Entities | ||
## | ||
# TODO: https://ruby-doc.org/3.1.3/stdlibs/yaml/YAML/DBM.html | ||
# | ||
class ID | ||
def initialize(value:) | ||
@value = value | ||
end | ||
|
||
class << self | ||
def cast(value) | ||
case value | ||
when ::String, ::Integer | ||
new(value: value.to_s) | ||
end | ||
end | ||
end | ||
|
||
def ==(other) | ||
return unless other.instance_of?(self.class) | ||
|
||
value == other.value | ||
end | ||
|
||
def to_i | ||
value.to_i | ||
end | ||
|
||
def to_s | ||
value | ||
end | ||
|
||
protected | ||
|
||
attr_reader :value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/convenient_service/examples/standard/request_params/entities/logger.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Entities | ||
class Logger | ||
class << self | ||
def log(message, out: $stdout) | ||
out.puts message | ||
|
||
message | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/convenient_service/examples/standard/request_params/entities/request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Examples | ||
module Standard | ||
module RequestParams | ||
module Entities | ||
class Request | ||
attr_reader :http_string | ||
|
||
def initialize(http_string:) | ||
@http_string = http_string | ||
end | ||
|
||
def to_s | ||
http_string | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.