red-api 0.2.1 → 0.2.5

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: b953b6b0eb60428808e5e4e96bee115704ccb947e181d1ca00273607ee741a78
4
- data.tar.gz: c4658cbf00f844f698f46ab5a3c0e68816d67f82af29971a76914b8337a5d7a7
3
+ metadata.gz: 510e97c50edf1d8586ec0d8cd9b54341886b29eec03eef6841f5398ee3402db1
4
+ data.tar.gz: bf237d7d9fc214551fd6d9d8160718ae026ce695db5bce64a30209d0204ca672
5
5
  SHA512:
6
- metadata.gz: f075a31f36be34e96985768565d8e3a49c1644c5c3562b5290374d9cf8ec714a3b0d1d1a01db2af96f9cd84dff08307d8eafa615d984b7c1068444face8f6cc8
7
- data.tar.gz: 3d6a8aaba3eb5448c479258d45ff3a0c9e9c1dfa136570c7923908c2915a5e8db5e2e25e0d29fa951d108d0837833d16bd051d7eec97df46cd10ca0cf396b222
6
+ metadata.gz: 644bc8a30789479629ae2de3788853ccd038e99d7a8d972ed9ea93074e0e7824a4bb3a4fb5eb0b1ac31645c947c38d7d591fdf09c17999d9655b6e85d7879402
7
+ data.tar.gz: eeeb353573a4123c156666dacbe9ff91880c0452ff80e75b041c35d6419dc4b2aae145a948b3069bfff69b8f0ce33d7f7519d85206720772da0568978da79d55
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} --method_params 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} --method-params param1 param2 --include-helper-params
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 /endpoint
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,15 +13,17 @@ 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 'Endpoint is required' unless @endpoint
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[1..] unless @endpoint.first != '/'
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?
@@ -1,4 +1,4 @@
1
1
 
2
2
  def <%= @endpoint_name.underscore%>_endpoint<%="(#{@helper_params})" if @helper_params%>
3
- <%= "\"#{@endpoint}\".freeze" if @endpoint %>
3
+ <%= "\"#{@endpoint}\"" if @endpoint %>
4
4
  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/version
12
- app/services/ServiceName/version/api_calls/
13
- app/services/ServiceName/version/api_endpoints.rb
14
- app/services/ServiceName/version/client.rb
15
- app/services/ServiceName/version/endpoint_helpers.rb
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
- argument :api_endpoint, type: :string
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 == '/'
@@ -6,7 +6,7 @@ class <%=@full_api_reference%>::Client
6
6
  def self.client(params)
7
7
  <% if @env_var_opts.present? %><%= "params[:#{@env_var_opts.first.underscore.downcase}] = ENV['#{@env_var_opts.last.underscore.upcase}']"%><% else %># Additional params can be added here<% end %>
8
8
  Faraday.new(
9
- url: api_endpoint,
9
+ url: <%=@api_name.underscore%>_api_endpoint,
10
10
  params: params
11
11
  )
12
12
  end
@@ -1,7 +1,7 @@
1
1
  module EndpointHelpers
2
- def api_endpoint
2
+ def <%=@api_name.underscore%>_api_endpoint
3
3
  # The http API endpoint for this service
4
- <%= "'#{@api_endpoint}'.freeze" %>
4
+ <%= "'#{@api_endpoint}'" %>
5
5
  end
6
6
 
7
7
  # API Endpoint Helpers
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.1
4
+ version: 0.2.5
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-20 00:00:00.000000000 Z
11
+ date: 2021-07-30 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: '0'
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: '0'
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