Class: Wrappix::Templates::Configuration
- Inherits:
-
Object
- Object
- Wrappix::Templates::Configuration
- Defined in:
- lib/wrappix/templates/configuration.rb
Class Method Summary collapse
- .auth_config_attributes(config) ⇒ Object
- .auth_config_initialization(config) ⇒ Object
- .render(module_name, config) ⇒ Object
Class Method Details
.auth_config_attributes(config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wrappix/templates/configuration.rb', line 29 def self.auth_config_attributes(config) case config["auth_type"] when "oauth" "attr_accessor :client_id, :client_secret, :token_url, :access_token" when "basic" "attr_accessor :username, :password" when "api_key" "attr_accessor :api_key, :api_key_header" else "" end end |
.auth_config_initialization(config) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wrappix/templates/configuration.rb', line 42 def self.auth_config_initialization(config) case config["auth_type"] when "oauth" <<~RUBY.strip @client_id = nil @client_secret = nil @token_url = "#{config["token_url"] || "https://api.example.com/oauth/token"}" @access_token = nil RUBY when "basic" <<~RUBY.strip @username = nil @password = nil RUBY when "api_key" <<~RUBY.strip @api_key = nil @api_key_header = "#{config["api_key_header"] || "X-Api-Key"}" RUBY else "" end end |
.render(module_name, config) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wrappix/templates/configuration.rb', line 6 def self.render(module_name, config) <<~RUBY # frozen_string_literal: true module #{module_name} class Configuration attr_accessor :base_url, :timeout, :headers #{auth_config_attributes(config)} def initialize @base_url = "#{config["base_url"] || "https://api.example.com"}" @timeout = 30 @headers = { "Content-Type" => "application/json", "Accept" => "application/json" } #{auth_config_initialization(config)} end end end RUBY end |