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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46c471a9c123c2bcd52de3e2459f7d282b83172a2c75f54fd4240e9931a80a54
4
- data.tar.gz: 3202e5fdff5882c142d9173e593254c09767c67e9aac33765905f4b5eba44274
3
+ metadata.gz: d3247b741f6c7d6a10fab58ebeeb6ab51c355418b4b791d2c2ffc4f1018e28d4
4
+ data.tar.gz: e27d1ceb69d5b89b2a4f87cc7ffaf20b5f19f8e3ce3e58cf9abdea2f92de8c50
5
5
  SHA512:
6
- metadata.gz: 12c9cb3aff98022cc14e545b56dc2388df0ae536bb818b0779dbaa6b6f8de7a8f4260f7ebb61e9dbb6cbab657949988618b3755ff60515f844a543049b3374c9
7
- data.tar.gz: 8ca0ef18944bbf57e5ec00c9a05d81a3ca8c5a3ea1ecb5fffdc4602066e4959371953b95a3d31ab30030760965d97164b63f05fbae2f24ade06936707533616e
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 param1 param2
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: :get
8
+ class_option :method, type: :string, default: 'get'
9
9
  class_option :endpoint_params, type: :array
10
- class_option :helper_params, type: :array
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 unless options[:method]
24
+ @endpoint = @endpoint[1..] unless @endpoint.first != '/'
25
+ @method = options[:method].to_sym
26
26
 
27
- create_endpoint_params unless options[:endpoint_params]
28
- create_helper_params unless options[: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 = @endpoint_name.underscore + '_spec.rb';
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
- 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
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
- @endpoint_params = options[:helper_params][0..-2].each_with_object('') do |p, str|
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 @endpoint_params.present?%>
3
- <%= "\"#{@endpoint}\".freeze" if @endpoint.present? %>
4
- end
2
+ def <%= @endpoint_name.underscore%>_endpoint<%="(#{@helper_params})" if @helper_params%>
3
+ <%= "\"#{@endpoint}\".freeze" if @endpoint %>
4
+ end
@@ -2,4 +2,4 @@ require 'rails_helper'
2
2
 
3
3
  RSpec.describe <%=@endpoint_reference%> do
4
4
  # API Endpoint tests
5
- end
5
+ 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
- <%='# Define endpoint parameters here' unless @endpoint_params%>
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
- api_version_path = root_dir + @api_version.downcase + '/'
23
+ api_path = root_dir + @api_name.underscore + '/'
24
24
 
25
- Dir.mkdir api_version_path unless File.exist?(api_version_path)
25
+ Dir.mkdir api_path unless File.exist?(api_path)
26
26
 
27
- service_dir_path = api_version_path + api_name.underscore + '/'
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/<%= @api_dir_name.underscore%>/<%=@api_version.downcase%>/api_calls/*.rb')].sort.each { |api_call| require api_call }
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard DeSilvey