Class: AuthingRuby::Common::NaiveHttpClient

Inherits:
HttpClient
  • Object
show all
Defined in:
lib/authing_ruby/common/HttpClient.rb

Overview

JS SDK 里 NaiveHttpClient 和 HttpClient 的区别: HttpClient 会处理 onError 回调函数,也会从返回的 data 中处理 code, message NaiveHttpClient 只返回 data,也不带请求头 Authorization

Constant Summary

Constants inherited from HttpClient

HttpClient::METHODS

Instance Method Summary collapse

Methods inherited from HttpClient

#faraday_conn

Constructor Details

#initialize(options = {}, tokenProvider = nil) ⇒ NaiveHttpClient

Returns a new instance of NaiveHttpClient.



154
155
156
# File 'lib/authing_ruby/common/HttpClient.rb', line 154

def initialize(options = {}, tokenProvider = nil)
  super(options, tokenProvider)
end

Instance Method Details

#request(config = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/authing_ruby/common/HttpClient.rb', line 158

def request(config = {})
  headers = {
    'x-authing-sdk-version': "ruby:#{AuthingRuby::VERSION}",
    'x-authing-userpool-id': @options.fetch(:userPoolId, ''),
    'x-authing-request-from': @options.fetch(:requestFrom, 'sdk'),
    'x-authing-app-id': @options.fetch(:appId, ''),
    'x-authing-lang': @options.fetch(:lang, ''),
  };
  headers_merge = headers.merge(config.fetch(:headers, {}))
  # 先把 header 合并一下,把用户传进来的和这里默认的合并一下

  config = config.merge({headers: headers_merge})
  # 再把 config 处理一下,把最终 header 合并进去

  response = faraday_conn(config) # 返回 Faraday::Response
  return response.body
end