red-api 0.1.9 → 0.2.3
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 +17 -25
- data/lib/generators/endpoint/templates/endpoint_helper.erb +3 -3
- data/lib/generators/endpoint/templates/endpoint_spec.erb +8 -2
- data/lib/generators/endpoint/templates/mixin.erb +1 -1
- data/lib/generators/service/USAGE +9 -7
- data/lib/generators/service/service_generator.rb +5 -6
- data/lib/generators/service/templates/api_endpoints.erb +1 -1
- metadata +4 -19
- data/lib/generators/endpoint/templates/endpoint_test.erb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d7d7d53824c734d42780257148211cc70788dc29ac04d03fdaeb427a7eb0467
|
4
|
+
data.tar.gz: 64ef94c872681198c0de4530aa1f9c1c94755c0b80b172e4550db83406990dfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08b57006fe0b799f63827c3b52a273ea68ba50633c53559593ecd80e772158013d6920ebdf2aa36e0d07b293a459e126ed32b53a50b6658cd49fc5628f979741'
|
7
|
+
data.tar.gz: fe2faa911327a6744e16d68b1d6dfd75ea1c7f9483a2d77468d58fa79f8e2991a10629a8afbbcd858c80d55bfc6287a293e7445190fe85bd46dc3a011bc5e712
|
@@ -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} --
|
8
|
+
rails generate endpoint ServiceName version EndpointName --endpoint /endpoint/#{param1}/#{param2} --endpoint-params param1 param2 --include-helper-params
|
6
9
|
|
7
10
|
Simple Form:
|
8
11
|
rails generate endpoint ServiceName V1 EndpointName /endpoint
|
@@ -1,36 +1,38 @@
|
|
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
|
6
|
-
argument :
|
5
|
+
argument :endpoint_name, type: :string
|
7
6
|
|
8
|
-
class_option :
|
7
|
+
class_option :endpoint, 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
|
14
14
|
@api_version = api_version
|
15
15
|
@endpoint_name = endpoint_name
|
16
|
-
@endpoint = endpoint
|
16
|
+
@endpoint = options[:endpoint]
|
17
17
|
|
18
|
-
raise ArgumentError 'Endpoint name required' unless @endpoint_name
|
19
|
-
raise ArgumentError '
|
18
|
+
raise ArgumentError, 'Endpoint name required' unless @endpoint_name
|
19
|
+
raise ArgumentError, 'Version is required, e.g. V1' unless @api_version
|
20
|
+
raise ArgumentError, 'Version should not be included in your endpoint, generator will build it for you' if @endpoint.downcase.include?(@api_version.downcase)
|
20
21
|
|
21
22
|
@endpoint_reference = @api_service.camelize + '::' + @api_version.camelize + '::ApiEndpoints'
|
22
23
|
@full_endpoint_reference = @endpoint_reference + '.' + @endpoint_name.underscore
|
23
24
|
|
24
|
-
@endpoint = @endpoint
|
25
|
-
@
|
25
|
+
@endpoint = '/' + @endpoint unless @endpoint.first == '/'
|
26
|
+
@endpoint = @api_version.downcase + @endpoint
|
27
|
+
@method = options[:method].to_sym
|
26
28
|
|
27
|
-
create_endpoint_params
|
28
|
-
create_helper_params
|
29
|
+
create_endpoint_params if options[:endpoint_params].present?
|
30
|
+
create_helper_params if options[:include_helper_params].present?
|
29
31
|
|
30
32
|
spec_file_name = @endpoint_name.underscore + '_spec.rb';
|
31
33
|
spec_dir = 'spec/services/'
|
32
34
|
spec_api_dir = spec_dir + @api_service.underscore + '/'
|
33
|
-
service_version_dir = spec_api_dir + @api_version + '/'
|
35
|
+
service_version_dir = spec_api_dir + @api_version.downcase + '/'
|
34
36
|
|
35
37
|
Dir.mkdir spec_dir unless File.exist?(spec_dir)
|
36
38
|
Dir.mkdir spec_api_dir unless File.exist?(spec_api_dir)
|
@@ -38,14 +40,7 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
38
40
|
|
39
41
|
spec_file_path = service_version_dir + spec_file_name
|
40
42
|
|
41
|
-
|
42
|
-
template 'endpoint_spec.erb', spec_file_path
|
43
|
-
else
|
44
|
-
end_point_test = ERB.new load_template('endpoint_test.erb')
|
45
|
-
inject_into_file spec_file_path, after: " # API Endpoint tests\n" do
|
46
|
-
end_point_test.result(binding)
|
47
|
-
end
|
48
|
-
end
|
43
|
+
template 'endpoint_spec.erb', spec_file_path
|
49
44
|
|
50
45
|
service_dir_path = "app/services/#{@api_service}/"
|
51
46
|
service_api_version_path = service_dir_path + @api_version + '/'
|
@@ -73,15 +68,12 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
73
68
|
end
|
74
69
|
|
75
70
|
def create_helper_params
|
76
|
-
@
|
77
|
-
str << p << ', '
|
78
|
-
end
|
79
|
-
@endpoint_params << options[:helper_params].last
|
71
|
+
@helper_params = @endpoint_params
|
80
72
|
end
|
81
73
|
|
82
74
|
def create_endpoint_params
|
83
75
|
@endpoint_params = options[:endpoint_params][0..-2].each_with_object('') do |p, str|
|
84
|
-
str << p << ', '
|
76
|
+
str << p.underscore << ', '
|
85
77
|
end
|
86
78
|
@endpoint_params << options[:endpoint_params].last
|
87
79
|
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
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe <%=@endpoint_reference%> do
|
4
|
-
|
5
|
-
|
4
|
+
describe '<%=@endpoint_name.underscore%>' do
|
5
|
+
it 'returns expected data when successful' do
|
6
|
+
skip 'Write tests for <%=@endpoint_name.underscore%>'
|
7
|
+
<%='# Define endpoint parameters here' if @endpoint_params%>
|
8
|
+
response = <%=@full_endpoint_reference%><%="(#{@endpoint_params})" if @endpoint_params%>
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
extend <%= @endpoint_name.camelize%>
|
1
|
+
extend <%= @endpoint_name.camelize%>
|
@@ -2,14 +2,16 @@ Description:
|
|
2
2
|
Generates the framework for a basic API service your app consumes
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate service ServiceName version https://service/api/endpoint/ --key api_key env_key_name
|
5
|
+
rails generate service ServiceName version --endpoint https://service/api/endpoint/ --key api_key env_key_name
|
6
6
|
|
7
7
|
Simple Form:
|
8
|
-
rails generate service ServiceName V1 https://service/api/endpoint/
|
8
|
+
rails generate service ServiceName V1 --endpoint https://service/api/endpoint/
|
9
|
+
|
10
|
+
Not supplying an endpoint will default to https://
|
9
11
|
|
10
12
|
This will create:
|
11
|
-
app/services/ServiceName/
|
12
|
-
app/services/ServiceName/
|
13
|
-
app/services/ServiceName/
|
14
|
-
app/services/ServiceName/
|
15
|
-
app/services/ServiceName/
|
13
|
+
app/services/ServiceName/v1
|
14
|
+
app/services/ServiceName/v1/api_calls/
|
15
|
+
app/services/ServiceName/v1/api_endpoints.rb
|
16
|
+
app/services/ServiceName/v1/client.rb
|
17
|
+
app/services/ServiceName/v1/endpoint_helpers.rb
|
@@ -2,17 +2,16 @@ class ServiceGenerator < Rails::Generators::NamedBase
|
|
2
2
|
source_root File.expand_path('templates', __dir__)
|
3
3
|
|
4
4
|
argument :version, type: :string
|
5
|
-
|
5
|
+
class_option :api_endpoint, type: :string, default: 'https://'
|
6
6
|
class_option :key, type: :array
|
7
7
|
|
8
8
|
def create_api_service
|
9
9
|
@api_name = file_name
|
10
10
|
@api_version = version
|
11
|
-
@api_endpoint = api_endpoint
|
11
|
+
@api_endpoint = options[:api_endpoint]
|
12
12
|
@env_var_opts = options[:key]
|
13
13
|
|
14
14
|
raise ArgumentError, 'Need to give the API version' unless @api_version.present?
|
15
|
-
raise ArgumentError, 'Need to give the API endpoint URI e.g. https://api/' unless @api_endpoint.present?
|
16
15
|
|
17
16
|
@full_api_reference = @api_name.camelize + '::' + @api_version.upcase
|
18
17
|
@api_endpoint = @api_endpoint + '/' unless @api_endpoint.last == '/'
|
@@ -20,11 +19,11 @@ class ServiceGenerator < Rails::Generators::NamedBase
|
|
20
19
|
root_dir = "app/services/"
|
21
20
|
Dir.mkdir root_dir unless File.exist?(root_dir)
|
22
21
|
|
23
|
-
|
22
|
+
api_path = root_dir + @api_name.underscore + '/'
|
24
23
|
|
25
|
-
Dir.mkdir
|
24
|
+
Dir.mkdir api_path unless File.exist?(api_path)
|
26
25
|
|
27
|
-
service_dir_path =
|
26
|
+
service_dir_path = api_path + @api_version.downcase + '/'
|
28
27
|
|
29
28
|
Dir.mkdir service_dir_path unless File.exist?(service_dir_path)
|
30
29
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard DeSilvey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.5
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.2.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.5.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
description: Generate API service and endpoints for API consumption
|
70
56
|
email:
|
71
57
|
- rdesilvey@gmail.com
|
@@ -79,7 +65,6 @@ files:
|
|
79
65
|
- lib/generators/endpoint/templates/api_call.erb
|
80
66
|
- lib/generators/endpoint/templates/endpoint_helper.erb
|
81
67
|
- lib/generators/endpoint/templates/endpoint_spec.erb
|
82
|
-
- lib/generators/endpoint/templates/endpoint_test.erb
|
83
68
|
- lib/generators/endpoint/templates/mixin.erb
|
84
69
|
- lib/generators/service/USAGE
|
85
70
|
- lib/generators/service/service_generator.rb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
|
2
|
-
describe '#<%=@endpoint_name.underscore%>' do
|
3
|
-
it 'returns expected data' do
|
4
|
-
skip 'Write tests for <%=@endpoint_name.underscore%>'
|
5
|
-
|
6
|
-
<%='# Define endpoint parameters here' unless @endpoint_params%>
|
7
|
-
response = <%=@full_endpoint_reference%><%="(#{@endpoint_params})" unless @endpoint_params%>
|
8
|
-
end
|
9
|
-
end
|