Class: AuthingRuby::Common::GraphqlClient
- Inherits:
-
Object
- Object
- AuthingRuby::Common::GraphqlClient
- Defined in:
- lib/authing_ruby/common/GraphqlClient.rb
Instance Method Summary collapse
-
#initialize(endpoint, options = {}) ⇒ GraphqlClient
constructor
A new instance of GraphqlClient.
- #request(options) ⇒ Object
Constructor Details
#initialize(endpoint, options = {}) ⇒ GraphqlClient
Returns a new instance of GraphqlClient.
12 13 14 15 |
# File 'lib/authing_ruby/common/GraphqlClient.rb', line 12 def initialize(endpoint, = {}) @endpoint = endpoint # API 端点 @options = end |
Instance Method Details
#request(options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/authing_ruby/common/GraphqlClient.rb', line 17 def request() headers = { 'content-type': 'application/json', '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, ''), }; token = .fetch(:token, nil) if token headers['Authorization'] = "Bearer #{token}" end json = .fetch(:json, nil) # puts "@endpoint 是 #{@endpoint}" response = HTTP.headers(headers).post(@endpoint, json: json) return response.body.to_s end |