Class: AuthingRuby::Common::NaiveHttpClient
- Inherits:
-
HttpClient
- Object
- HttpClient
- AuthingRuby::Common::NaiveHttpClient
- 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
Instance Method Summary collapse
-
#initialize(options = {}, tokenProvider = nil) ⇒ NaiveHttpClient
constructor
A new instance of NaiveHttpClient.
- #request(config = {}) ⇒ Object
Methods inherited from HttpClient
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( = {}, tokenProvider = nil) super(, 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 |