File tree 3 files changed +32
-0
lines changed
3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module ParentController
13
13
14
14
def parent_controller
15
15
return "Avo::ArrayController" if options [ "array" ]
16
+ return "Avo::Core::Controllers::Http" if options [ "http" ]
16
17
17
18
options [ "parent-controller" ] || ::Avo . configuration . resource_parent_controller
18
19
end
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ class ResourceGenerator < NamedBaseGenerator
22
22
type : :boolean ,
23
23
default : false
24
24
25
+ class_option "http" ,
26
+ desc : "Indicates if the resource should be HTTP." ,
27
+ type : :boolean ,
28
+ default : false
29
+
25
30
def create
26
31
return if override_controller?
27
32
@@ -33,6 +38,8 @@ def create
33
38
def parent_resource
34
39
if options [ "array" ]
35
40
"Avo::Resources::ArrayResource"
41
+ elsif options [ "http" ]
42
+ "Avo::Core::Resources::Http"
36
43
else
37
44
"Avo::BaseResource"
38
45
end
Original file line number Diff line number Diff line change @@ -11,6 +11,26 @@ class Avo::Resources::<%= resource_class %> < <%= parent_resource %><% if option
11
11
}
12
12
]
13
13
end
14
+ <% elsif options["http"] %>
15
+ # self.endpoint = "https://api.openalex.org/"
16
+ # self.endpoint_key = "authors"
17
+ # self.parse_collection = -> {
18
+ # raise Avo::HttpError.new response["message"] if response["error"].present?
19
+ #
20
+ # response["results"]
21
+ # }
22
+ # self.parse_record = -> { response }
23
+ # self.parse_count = -> { response["meta"]["count"] }
24
+
25
+ ## This is required only when the ID includes characters (e.g., ".") that could be improperly routed.
26
+ # self.find_record_method = -> { query.find Base64.decode64(id) }
27
+ ## Encodes the ID for use in URL helpers. The `model_class_eval` block is executed when the model is defined in memory,
28
+ ## allowing us to override `to_param` and obfuscate the raw ID via Base64 encoding.
29
+ # self.model_class_eval = -> {
30
+ # define_method :to_param do
31
+ # Base64.encode64(id)
32
+ # end
33
+ # }
14
34
<% else %>
15
35
# self.includes = []
16
36
# self.attachments = []<%= model_class_from_args %>
@@ -21,6 +41,10 @@ class Avo::Resources::<%= resource_class %> < <%= parent_resource %><% if option
21
41
def fields
22
42
field :id, as: :id
23
43
field :title
44
+ end<% elsif options["http"] %>
45
+ def fields
46
+ field :id, as: :id
47
+ # field :display_name
24
48
end<% else %>
25
49
def fields
26
50
field :id, as: :id<%= generate_fields %>
You can’t perform that action at this time.
0 commit comments