red-api 0.2.0 → 0.2.4
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/README.md +4 -3
- data/lib/generators/endpoint/USAGE +3 -2
- data/lib/generators/endpoint/endpoint_generator.rb +9 -12
- data/lib/generators/endpoint/templates/endpoint_spec.erb +7 -1
- data/lib/generators/service/USAGE +9 -7
- data/lib/generators/service/service_generator.rb +2 -3
- metadata +4 -19
- data/lib/generators/endpoint/templates/endpoint_test.erb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34b9e346a9f677ad543137b0d60b1fc5d4719bb159b445671195b85751f2876e
|
4
|
+
data.tar.gz: 01d83f096388b122f96359dd9507cc3d0804be3cbe513240444625f1948b9f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81805645c940c74a0458597b7d8727dd03c32e5442c4e59858756ac138ff35043d3b90187d44507a9cac8f901b0bcac8807cc74832ec6aa7533cb45258f91702
|
7
|
+
data.tar.gz: 97571792c684c43b80d772ff24e1f18656155a0045bd132a5d44224add2ffd134f41bfce0c7cf3f45389e7efdd248ff1959cecce4169c454195e336b72647710
|
data/README.md
CHANGED
@@ -7,11 +7,11 @@ This simple gem has two generators to support creating a basic API consumer fram
|
|
7
7
|
|
8
8
|
#### Usage
|
9
9
|
```sh
|
10
|
-
rails generate service ApiName https://service/endpoint/ --key api_key service_api_key_env_name
|
11
|
-
rails generate endpoint ServiceName EndpointName /endpoint/#{param1}/#{param2} --
|
10
|
+
rails generate service ApiName Version --endpoint https://service/endpoint/ --key api_key service_api_key_env_name
|
11
|
+
rails generate endpoint ServiceName Version EndpointName --endpoint /endpoint/#{param1}/#{param2} --method-params param1 param2 --include-helper-params
|
12
12
|
```
|
13
13
|
The service generator will setup the framework which uses Faraday for your http calls and Oj gem for faster json parsing.
|
14
|
-
The endpoint generator will setup an endpoint with an endpoint helper method for easier testing.
|
14
|
+
The endpoint generator will setup an endpoint with an endpoint helper method for easier testing and adds a spec file.
|
15
15
|
|
16
16
|
#### Installation
|
17
17
|
```ruby
|
@@ -21,6 +21,7 @@ gem 'red-api'
|
|
21
21
|
```ruby
|
22
22
|
gem 'faraday'
|
23
23
|
gem 'oj'
|
24
|
+
gem 'rspec-rails
|
24
25
|
```
|
25
26
|
|
26
27
|
#### Testing
|
@@ -5,13 +5,14 @@ Description:
|
|
5
5
|
Will copy the --method-params given to your endpoint helper method to use in your endpoint URI path
|
6
6
|
|
7
7
|
Example:
|
8
|
-
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
|
9
9
|
|
10
10
|
Simple Form:
|
11
|
-
rails generate endpoint ServiceName V1 EndpointName
|
11
|
+
rails generate endpoint ServiceName V1 EndpointName
|
12
12
|
|
13
13
|
This will create:
|
14
14
|
app/services/ServiceName/version/api_call/endpoint_name.rb
|
15
|
+
with the endpoint being /v1/ if no endpoint is given
|
15
16
|
|
16
17
|
This will modify:
|
17
18
|
app/services/ServiceName/version/api_endpoints.rb
|
@@ -3,8 +3,8 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
3
3
|
|
4
4
|
argument :api_version, type: :string
|
5
5
|
argument :endpoint_name, type: :string
|
6
|
-
argument :endpoint, type: :string
|
7
6
|
|
7
|
+
class_option :endpoint, type: :string, default: '/'
|
8
8
|
class_option :method, type: :string, default: 'get'
|
9
9
|
class_option :endpoint_params, type: :array
|
10
10
|
class_option :include_helper_params
|
@@ -13,21 +13,23 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
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
|
+
@endpoint = '/' + @endpoint unless @endpoint.first == '/'
|
26
|
+
@endpoint = @api_version.downcase + @endpoint
|
25
27
|
@method = options[:method].to_sym
|
26
28
|
|
27
29
|
create_endpoint_params if options[:endpoint_params].present?
|
28
30
|
create_helper_params if options[:include_helper_params].present?
|
29
31
|
|
30
|
-
spec_file_name = '
|
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
35
|
service_version_dir = spec_api_dir + @api_version.downcase + '/'
|
@@ -38,12 +40,7 @@ class EndpointGenerator < Rails::Generators::NamedBase
|
|
38
40
|
|
39
41
|
spec_file_path = service_version_dir + spec_file_name
|
40
42
|
|
41
|
-
template 'endpoint_spec.erb', 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)
|
46
|
-
end
|
43
|
+
template 'endpoint_spec.erb', spec_file_path
|
47
44
|
|
48
45
|
service_dir_path = "app/services/#{@api_service}/"
|
49
46
|
service_api_version_path = service_dir_path + @api_version + '/'
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe <%=@endpoint_reference%> do
|
4
|
-
|
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
|
5
11
|
end
|
@@ -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 == '/'
|
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.2.
|
4
|
+
version: 0.2.4
|
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-22 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,8 +0,0 @@
|
|
1
|
-
|
2
|
-
describe '#<%=@endpoint_name.underscore%>' do
|
3
|
-
it 'returns expected data' do
|
4
|
-
skip 'Write tests for <%=@endpoint_name.underscore%>'
|
5
|
-
<%='# Define endpoint parameters here' if @endpoint_params%>
|
6
|
-
response = <%=@full_endpoint_reference%><%="(#{@endpoint_params})" if @endpoint_params%>
|
7
|
-
end
|
8
|
-
end
|