red-api 0.1.9 → 0.2.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 +4 -4
- data/lib/generators/endpoint/USAGE +4 -1
- data/lib/generators/endpoint/endpoint_generator.rb +16 -21
- data/lib/generators/endpoint/templates/endpoint_helper.erb +3 -3
- data/lib/generators/endpoint/templates/endpoint_spec.erb +1 -1
- data/lib/generators/endpoint/templates/endpoint_test.erb +3 -4
- data/lib/generators/endpoint/templates/mixin.erb +1 -1
- data/lib/generators/service/service_generator.rb +3 -3
- data/lib/generators/service/templates/api_endpoints.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3247b741f6c7d6a10fab58ebeeb6ab51c355418b4b791d2c2ffc4f1018e28d4
|
4
|
+
data.tar.gz: e27d1ceb69d5b89b2a4f87cc7ffaf20b5f19f8e3ce3e58cf9abdea2f92de8c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8822fc4aaa6ffa7c0f8b824605365b86d65ab68eb1fe93e4144344686717590f1ad98df1f97b674e7c8eb1daf86101945f6bbbe7393d902b6918441668ce20c
|
7
|
+
data.tar.gz: 59201a7157c80514c31bb61fcd9cc52daea985e2924bdc53aaca910b94d542f4ce1c7af9888d61b7f8f32d87870801cf834978888f190ef90e471cc02b23ff1c
|
@@ -1,8 +1,11 @@
|
|
1
1
|
Description:
|
2
2
|
Adds an endpoint api call to your generated API service with optional endpoint method and endpoint helper method parameters
|
3
3
|
|
4
|
+
--include-helper-params:
|
5
|
+
Will copy the --method-params given to your endpoint helper method to use in your endpoint URI path
|
6
|
+
|
4
7
|
Example:
|
5
|
-
rails generate endpoint ServiceName version EndpointName /endpoint/#{param1}/#{param2} --method-params param1 param2 --helper-params
|
8
|
+
rails generate endpoint ServiceName version EndpointName /endpoint/#{param1}/#{param2} --method-params param1 param2 --include-helper-params
|
6
9
|
|
7
10
|
Simple Form:
|
8
11
|
rails generate endpoint ServiceName V1 EndpointName /endpoint
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class EndpointGenerator < Rails::Generators::NamedBase
|
2
2
|
source_root File.expand_path('templates', __dir__)
|
3
3
|
|
4
|
-
argument :endpoint_name, type: :string
|
5
4
|
argument :api_version, type: :string
|
5
|
+
argument :endpoint_name, type: :string
|
6
6
|
argument :endpoint, type: :string
|
7
7
|
|
8
|
-
class_option :method, type: :string, default:
|
8
|
+
class_option :method, type: :string, default: 'get'
|
9
9
|
class_option :endpoint_params, type: :array
|
10
|
-
class_option :
|
10
|
+
class_option :include_helper_params
|
11
11
|
|
12
12
|
def create_api_call
|
13
13
|
@api_service = file_name.underscore
|
@@ -21,16 +21,16 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
21
21
|
@endpoint_reference = @api_service.camelize + '::' + @api_version.camelize + '::ApiEndpoints'
|
22
22
|
@full_endpoint_reference = @endpoint_reference + '.' + @endpoint_name.underscore
|
23
23
|
|
24
|
-
@endpoint = @endpoint[1..] unless @endpoint.first
|
25
|
-
@method = options[:method].to_sym
|
24
|
+
@endpoint = @endpoint[1..] unless @endpoint.first != '/'
|
25
|
+
@method = options[:method].to_sym
|
26
26
|
|
27
|
-
create_endpoint_params
|
28
|
-
create_helper_params
|
27
|
+
create_endpoint_params if options[:endpoint_params].present?
|
28
|
+
create_helper_params if options[:include_helper_params].present?
|
29
29
|
|
30
|
-
spec_file_name =
|
30
|
+
spec_file_name = 'endpoints_spec.rb';
|
31
31
|
spec_dir = 'spec/services/'
|
32
32
|
spec_api_dir = spec_dir + @api_service.underscore + '/'
|
33
|
-
service_version_dir = spec_api_dir + @api_version + '/'
|
33
|
+
service_version_dir = spec_api_dir + @api_version.downcase + '/'
|
34
34
|
|
35
35
|
Dir.mkdir spec_dir unless File.exist?(spec_dir)
|
36
36
|
Dir.mkdir spec_api_dir unless File.exist?(spec_api_dir)
|
@@ -38,13 +38,11 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
38
38
|
|
39
39
|
spec_file_path = service_version_dir + spec_file_name
|
40
40
|
|
41
|
-
unless File.exist? spec_file_path
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end_point_test.result(binding)
|
47
|
-
end
|
41
|
+
template 'endpoint_spec.erb', spec_file_path unless File.exist? spec_file_path
|
42
|
+
|
43
|
+
end_point_test = ERB.new load_template('endpoint_test.erb')
|
44
|
+
inject_into_file spec_file_path, after: " # API Endpoint tests\n" do
|
45
|
+
end_point_test.result(binding)
|
48
46
|
end
|
49
47
|
|
50
48
|
service_dir_path = "app/services/#{@api_service}/"
|
@@ -73,15 +71,12 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
73
71
|
end
|
74
72
|
|
75
73
|
def create_helper_params
|
76
|
-
@
|
77
|
-
str << p << ', '
|
78
|
-
end
|
79
|
-
@endpoint_params << options[:helper_params].last
|
74
|
+
@helper_params = @endpoint_params
|
80
75
|
end
|
81
76
|
|
82
77
|
def create_endpoint_params
|
83
78
|
@endpoint_params = options[:endpoint_params][0..-2].each_with_object('') do |p, str|
|
84
|
-
str << p << ', '
|
79
|
+
str << p.underscore << ', '
|
85
80
|
end
|
86
81
|
@endpoint_params << options[:endpoint_params].last
|
87
82
|
end
|
@@ -1,4 +1,4 @@
|
|
1
1
|
|
2
|
-
def <%= @endpoint_name.underscore%>_endpoint<%="(#{@helper_params})" if @
|
3
|
-
<%= "\"#{@endpoint}\".freeze" if @endpoint
|
4
|
-
end
|
2
|
+
def <%= @endpoint_name.underscore%>_endpoint<%="(#{@helper_params})" if @helper_params%>
|
3
|
+
<%= "\"#{@endpoint}\".freeze" if @endpoint %>
|
4
|
+
end
|
@@ -2,8 +2,7 @@
|
|
2
2
|
describe '#<%=@endpoint_name.underscore%>' do
|
3
3
|
it 'returns expected data' do
|
4
4
|
skip 'Write tests for <%=@endpoint_name.underscore%>'
|
5
|
-
|
6
|
-
|
7
|
-
response = <%=@full_endpoint_reference%><%="(#{@endpoint_params})" unless @endpoint_params%>
|
5
|
+
<%='# Define endpoint parameters here' if @endpoint_params%>
|
6
|
+
response = <%=@full_endpoint_reference%><%="(#{@endpoint_params})" if @endpoint_params%>
|
8
7
|
end
|
9
|
-
end
|
8
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
extend <%= @endpoint_name.camelize%>
|
1
|
+
extend <%= @endpoint_name.camelize%>
|
@@ -20,11 +20,11 @@ class ServiceGenerator < Rails::Generators::NamedBase
|
|
20
20
|
root_dir = "app/services/"
|
21
21
|
Dir.mkdir root_dir unless File.exist?(root_dir)
|
22
22
|
|
23
|
-
|
23
|
+
api_path = root_dir + @api_name.underscore + '/'
|
24
24
|
|
25
|
-
Dir.mkdir
|
25
|
+
Dir.mkdir api_path unless File.exist?(api_path)
|
26
26
|
|
27
|
-
service_dir_path =
|
27
|
+
service_dir_path = api_path + @api_version.downcase + '/'
|
28
28
|
|
29
29
|
Dir.mkdir service_dir_path unless File.exist?(service_dir_path)
|
30
30
|
Dir.mkdir "#{service_dir_path}/api_calls" unless File.exist?("#{service_dir_path}/api_calls")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Dir[Rails.root.join('app/services/<%= @
|
1
|
+
Dir[Rails.root.join('app/services/<%= @api_name.underscore%>/<%=@api_version.downcase%>/api_calls/*.rb')].sort.each { |api_call| require api_call }
|
2
2
|
|
3
3
|
class <%=@full_api_reference%>::ApiEndpoints < <%= @full_api_reference%>::Client
|
4
4
|
# API call modules
|