wrappix 0.1.0 → 0.1.1
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 +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/lib/wrappix/builder.rb +0 -1
- data/lib/wrappix/templates/client.rb +4 -2
- data/lib/wrappix/templates/documentation.rb +0 -4
- data/lib/wrappix/templates/main.rb +0 -5
- data/lib/wrappix/templates/request.rb +1 -1
- data/lib/wrappix/templates/resource.rb +7 -13
- data/lib/wrappix/version.rb +1 -1
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75bb824678a4d8239ed574f8de137cb8eb001cd7548b2583c63d3194927ca322
|
4
|
+
data.tar.gz: 4b33c0be1f907b8902ec78d90a4795dde6f4e9e1e292cd2d20ee96ed53a2a8b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab1613d90718549060197769a68216c1c3e89f6842343fc164554ad1cb6332b40ca1a375b8b2ae863d77895d2dd4fa7622981c6ed41ec73d73e2dc4d66142ff
|
7
|
+
data.tar.gz: 7417a751d3947661169d79d43a7b15ee27bd3909e542e167abb9138c5e843727864b43bbcd19f08a76a0bf764f46563382c0a1dbdbaed9f9f939898e7ff4b08b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/wrappix/builder.rb
CHANGED
@@ -4,7 +4,7 @@ module Wrappix
|
|
4
4
|
module Templates
|
5
5
|
class Client
|
6
6
|
def self.render(module_name, config)
|
7
|
-
<<~RUBY
|
7
|
+
template = <<~RUBY
|
8
8
|
# frozen_string_literal: true
|
9
9
|
|
10
10
|
module #{module_name}
|
@@ -17,17 +17,19 @@ module Wrappix
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
RUBY
|
20
|
+
template.gsub(/^ +/, "")
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.resource_methods(_module_name, config)
|
23
24
|
resources = config["resources"] || {}
|
24
25
|
|
25
26
|
resources.map do |name, _config|
|
26
|
-
<<~RUBY.strip
|
27
|
+
template = <<~RUBY.strip
|
27
28
|
def #{name}
|
28
29
|
@#{name} ||= Resources::#{name.capitalize}.new(self)
|
29
30
|
end
|
30
31
|
RUBY
|
32
|
+
template.gsub(/^ +/, "")
|
31
33
|
end.join("\n\n")
|
32
34
|
end
|
33
35
|
end
|
@@ -99,13 +99,10 @@ module Wrappix
|
|
99
99
|
method = endpoint["method"]&.upcase || "GET"
|
100
100
|
path = endpoint["path"] || name
|
101
101
|
|
102
|
-
# Extraer los parámetros del path
|
103
102
|
path_params = path.scan(/\{([^}]+)\}/).flatten
|
104
103
|
|
105
|
-
# Generar la URL completa para la documentación
|
106
104
|
full_url = "#{base_url.chomp("/")}/#{path}"
|
107
105
|
|
108
|
-
# Generar la llamada al método para la documentación
|
109
106
|
method_params = []
|
110
107
|
method_params.concat(path_params)
|
111
108
|
method_params << "params" if endpoint["params"]
|
@@ -113,7 +110,6 @@ module Wrappix
|
|
113
110
|
|
114
111
|
client_call = "client.#{resource_name}.#{name}(#{method_params.join(", ")})"
|
115
112
|
|
116
|
-
# Documentación del endpoint
|
117
113
|
doc = <<~MARKDOWN
|
118
114
|
|
119
115
|
### #{name}
|
@@ -4,7 +4,6 @@ module Wrappix
|
|
4
4
|
module Templates
|
5
5
|
class Main
|
6
6
|
def self.render(api_name, module_name, config)
|
7
|
-
# api_name ya debería estar normalizado aquí
|
8
7
|
resources = config["resources"] || {}
|
9
8
|
resource_requires = resources.keys.map do |r|
|
10
9
|
"require_relative \"#{api_name}/resources/#{r}\""
|
@@ -21,8 +20,6 @@ module Wrappix
|
|
21
20
|
require_relative "#{api_name}/collection"
|
22
21
|
require_relative "#{api_name}/client"
|
23
22
|
require_relative "#{api_name}/cache"
|
24
|
-
|
25
|
-
# Resources
|
26
23
|
#{resource_requires}
|
27
24
|
|
28
25
|
module #{module_name}
|
@@ -35,13 +32,11 @@ module Wrappix
|
|
35
32
|
self
|
36
33
|
end
|
37
34
|
|
38
|
-
# Método para acceder al cliente
|
39
35
|
def client
|
40
36
|
@client ||= Client.new(configuration)
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
# Default to memory cache
|
45
40
|
self.cache = MemoryCache.new
|
46
41
|
self.configuration = Configuration.new
|
47
42
|
end
|
@@ -87,8 +87,8 @@ module Wrappix
|
|
87
87
|
|
88
88
|
def connection
|
89
89
|
@connection ||= Faraday.new(url: @base_url) do |conn|
|
90
|
-
#{connection_auth_config(config)}
|
91
90
|
conn.headers = @config.headers
|
91
|
+
#{connection_auth_config(config)}
|
92
92
|
conn.response :json, content_type: /\\bjson$/
|
93
93
|
conn.adapter Faraday.default_adapter
|
94
94
|
end
|
@@ -9,10 +9,9 @@ module Wrappix
|
|
9
9
|
endpoint_method(module_name, resource_name, endpoint, resource_config)
|
10
10
|
end.join("\n\n")
|
11
11
|
|
12
|
-
# Para normalizar el nombre del recurso
|
13
12
|
class_name = resource_name.capitalize
|
14
13
|
|
15
|
-
<<~RUBY
|
14
|
+
template = <<~RUBY
|
16
15
|
# frozen_string_literal: true
|
17
16
|
|
18
17
|
module #{module_name}
|
@@ -28,6 +27,8 @@ module Wrappix
|
|
28
27
|
end
|
29
28
|
end
|
30
29
|
RUBY
|
30
|
+
# Remove leading whitespace from each line
|
31
|
+
template.gsub(/^ +/, "")
|
31
32
|
end
|
32
33
|
|
33
34
|
def self.endpoint_method(module_name, _resource_name, endpoint, resource_config)
|
@@ -35,35 +36,27 @@ module Wrappix
|
|
35
36
|
method = endpoint["method"] || "get"
|
36
37
|
path = endpoint["path"] || name
|
37
38
|
|
38
|
-
# Obtener configuración de formato de respuesta
|
39
39
|
response_format = resource_config["response_format"] || {}
|
40
|
-
|
41
|
-
# Determinar si es una colección
|
42
40
|
is_collection = endpoint["collection"] || %w[all list index search].include?(name)
|
43
41
|
|
44
|
-
# Procesar parámetros del path
|
45
42
|
has_params = path.include?("{")
|
46
43
|
param_list = has_params ? path.scan(/\{([^}]+)\}/).flatten : []
|
47
44
|
|
48
|
-
# Preparar los parámetros del método
|
49
45
|
endpoint_params = []
|
50
46
|
endpoint_params.concat(param_list)
|
51
47
|
endpoint_params << "params = {}" if endpoint["params"]
|
52
48
|
endpoint_params << "body = {}" if %w[post put patch].include?(method)
|
53
49
|
|
54
|
-
# Preparar argumentos para el método request
|
55
50
|
request_args = []
|
56
51
|
request_args << "params: params" if endpoint["params"]
|
57
52
|
request_args << "body: body" if %w[post put patch].include?(method)
|
58
53
|
request_options = request_args.empty? ? "" : "(#{request_args.join(", ")})"
|
59
54
|
|
60
|
-
# Generar path con reemplazos de variables
|
61
55
|
path_with_params = path
|
62
56
|
param_list.each do |param|
|
63
57
|
path_with_params = path_with_params.gsub(/\{#{param}\}/, "\#{#{param}}")
|
64
58
|
end
|
65
59
|
|
66
|
-
# Código para transformar la respuesta basada en la configuración
|
67
60
|
response_transform = if is_collection
|
68
61
|
"#{module_name}::Collection.from_response(response, type: #{module_name}::Object)"
|
69
62
|
else
|
@@ -75,7 +68,7 @@ module Wrappix
|
|
75
68
|
end
|
76
69
|
end
|
77
70
|
|
78
|
-
<<~RUBY.strip
|
71
|
+
template = <<~RUBY.strip
|
79
72
|
def #{name}(#{endpoint_params.join(", ")})
|
80
73
|
request = #{module_name}::Request.new("#{path_with_params}")
|
81
74
|
response = request.#{method}#{request_options}
|
@@ -83,6 +76,7 @@ module Wrappix
|
|
83
76
|
#{response_transform}
|
84
77
|
end
|
85
78
|
RUBY
|
79
|
+
template.gsub(/^ +/, "")
|
86
80
|
end
|
87
81
|
|
88
82
|
def self.generate_response_transform(module_name, is_collection, response_format)
|
@@ -91,8 +85,7 @@ module Wrappix
|
|
91
85
|
pagination_config = response_format["pagination"] || {}
|
92
86
|
next_page_key = pagination_config["next_page_key"] || "next_href"
|
93
87
|
|
94
|
-
|
95
|
-
<<~RUBY
|
88
|
+
template = <<~RUBY
|
96
89
|
data = response[:#{collection_root}] || response["#{collection_root}"] || []
|
97
90
|
next_href = response[:#{next_page_key}] || response["#{next_page_key}"]
|
98
91
|
|
@@ -101,6 +94,7 @@ module Wrappix
|
|
101
94
|
next_href: next_href
|
102
95
|
}, type: #{module_name}::Object)
|
103
96
|
RUBY
|
97
|
+
template.gsub(/^ +/, "")
|
104
98
|
else
|
105
99
|
item_root = response_format["item_root"]
|
106
100
|
if item_root
|
data/lib/wrappix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrappix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Costanzo
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -86,7 +85,8 @@ dependencies:
|
|
86
85
|
- - "~>"
|
87
86
|
- !ruby/object:Gem::Version
|
88
87
|
version: '3.18'
|
89
|
-
description:
|
88
|
+
description: Create API Wrappers fast and easily. Wrappix provides a simple and intuitive
|
89
|
+
way to create API Wrappers.
|
90
90
|
email:
|
91
91
|
- dev.bcostanzo@gmail.com
|
92
92
|
executables:
|
@@ -128,7 +128,6 @@ metadata:
|
|
128
128
|
homepage_uri: https://github.com/bruno-costanzo/wrappix
|
129
129
|
source_code_uri: https://github.com/bruno-costanzo/wrappix
|
130
130
|
changelog_uri: https://github.com/bruno-costanzo/wrappix/blob/main/CHANGELOG.md
|
131
|
-
post_install_message:
|
132
131
|
rdoc_options: []
|
133
132
|
require_paths:
|
134
133
|
- lib
|
@@ -143,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
142
|
- !ruby/object:Gem::Version
|
144
143
|
version: '0'
|
145
144
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
145
|
+
rubygems_version: 3.6.8
|
148
146
|
specification_version: 4
|
149
|
-
summary:
|
147
|
+
summary: Wrappix is a tool to create API Wrappers fast and easily
|
150
148
|
test_files: []
|