Class: AdminApi::AutoGenerateAppTokenApi

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_api/api/auto_generate_app_token_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default, auth_config = AuthConfiguration.default) ⇒ AutoGenerateAppTokenApi

Returns a new instance of AutoGenerateAppTokenApi.



20
21
22
23
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 20

def initialize(api_client = ApiClient.default, auth_config = AuthConfiguration.default)
  @api_client = api_client
  @auth_config = auth_config
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 17

def api_client
  @api_client
end

#auth_configObject

Returns the value of attribute auth_config.



18
19
20
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 18

def auth_config
  @auth_config
end

Instance Method Details

#create_client_credential_return(appTokenConfig) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 32

def create_client_credential_return(appTokenConfig)
    client_credentials_token = @auth_config.create_client_credential_return(appTokenConfig['clientId'], appTokenConfig['clientSecret'])
    if @api_client.config.debugging
      @api_client.config.logger.debug "API called: AppTokenApi#get_app_token_using_get\nData: #{client_credentials_token.inspect}"
    end
  return client_credentials_token
end

#create_password_credential_return(appTokenConfig) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 40

def create_password_credential_return(appTokenConfig)

    password_credentials_token = @auth_config.create_password_credential_return(appTokenConfig['clientId'], appTokenConfig['clientSecret'],appTokenConfig['username'], appTokenConfig['password'] )
    if @api_client.config.debugging
      @api_client.config.logger.debug "API called: AppTokenApi#password_credentials_token\nData: #{client_credentials_token.inspect}"
    end
  return password_credentials_token
end

#get_app_token_using_get(appTokenConfig = {}) ⇒ Array<AppToken>

getAppToken

Parameters:

  • app_name

    app_name

  • opts (Hash)

    the optional parameters

Returns:



28
29
30
31
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 28

def get_app_token_using_get(appTokenConfig = {})
  data, _status_code, _headers = get_app_token_using_get_with_http_info(appTokenConfig)
  data
end

#get_app_token_using_get_with_http_info(appTokenConfig = {}) ⇒ Array<(Array<AppToken>, Fixnum, Hash)>

getAppToken

Parameters:

  • app_name

    app_name

  • opts (Hash)

    the optional parameters

Returns:

  • (Array<(Array<AppToken>, Fixnum, Hash)>)

    Array<AppToken> data, response status code and response headers



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/admin_api/api/auto_generate_app_token_api.rb', line 52

def get_app_token_using_get_with_http_info(appTokenConfig = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: AppTokenApi.get_app_token_using_get ...'
  end
  # verify the required parameter 'app_name' is set
  if @api_client.config.client_side_validation && appTokenConfig['appName'] == nil?
    fail ArgumentError, "Missing the required parameter 'app_name' when calling AppTokenApi.get_app_token_using_get"
  end

  template  = "<tag app-token='##app_token##' ##attrib_map##></tag>";
  @auth_config.config.host = appTokenConfig['basePath']
  @api_client.config.host = appTokenConfig['basePath']

  # resource path
  local_var_path = '/component/v1/app_token'

  # query parameters
  query_params = {}
  #query_params[:'app_name'] = @api_client.build_collection_param(appTokenConfig['appName'], :multi)

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['*/*'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = nil
  auth_names = ['oauth2']

  app_names = appTokenConfig['appName']
  response = [];

  finalAttribMap = []
  if appTokenConfig['attribMap']
    finalAttribMap = appTokenConfig['attribMap'].map { |it| "#{it['name']}='#{it['value']}'"}
  end

  app_names.each do |app|
    if app[:auth_type].downcase == 'client_credentials'
      client_credentials_token = create_client_credential_return(appTokenConfig)
      @api_client.config.access_token = client_credentials_token
    elsif app[:auth_type].downcase == 'password_credentials'
      @api_client.config.access_token =  appTokenConfig['userAccessToken']
      if appTokenConfig['isCredsPassed']
        password_credentials_token = create_password_credential_return(appTokenConfig)
        @api_client.config.access_token = password_credentials_token
      end
    end 

    appTokenData, status_code, headers = @api_client.call_api(:GET, '/app_token?app_name=' + app[:app_name],
      :header_params => header_params,
      :query_params => [],
      :form_params => form_params,
      :body => post_body,
      :auth_names => auth_names,
      :return_type => 'Array<AppToken>')
    if @api_client.config.debugging
      @api_client.config.logger.debug "API called: AppTokenApi#get_app_token_using_get\nData: #{appTokenData.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
    end
    
    appTokenValue = appTokenData && appTokenData.length()>0 ? appTokenData.values_at(0).map(&:app_token)[0] : '';
    tagValue = app[:app_name].downcase.gsub(/_/, '-');
    fillTemplateValue = template.gsub(/tag/, tagValue)
                              .gsub(/##app_token##/, appTokenValue)
                              .gsub(/##attrib_map##/, finalAttribMap!=nil ?  finalAttribMap.join(' ') : '');
  item ={}
  item[app[:app_name]] = appTokenValue;
  if appTokenConfig['isEmbed']
    item[app[:app_name]] = fillTemplateValue;
  end
  response.append(item);
  end
  return response
end