Class: GraphQLDocs::Client
- Inherits:
-
Object
- Object
- GraphQLDocs::Client
- Defined in:
- lib/graphql-docs/client.rb
Instance Attribute Summary collapse
-
#faraday ⇒ Object
Returns the value of attribute faraday.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/graphql-docs/client.rb', line 8 def initialize() @login = [:login] @password = [:password] if @login.nil? && !@password.nil? fail ArgumentError, 'Client provided a login, but no password!' end if !@login.nil? && @password.nil? fail ArgumentError, 'Client provided a password, but no login!' end @access_token = [:access_token] @url = [:url] @faraday = Faraday.new(url: @url) if @login && @password @faraday.basic_auth(@login, @password) elsif @access_token @faraday.('token', @access_token) end end |
Instance Attribute Details
#faraday ⇒ Object
Returns the value of attribute faraday.
6 7 8 |
# File 'lib/graphql-docs/client.rb', line 6 def faraday @faraday end |
Instance Method Details
#fetch ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/graphql-docs/client.rb', line 32 def fetch res = @faraday.post do |req| req.headers['Content-Type'] = 'application/json' req.body = "{ \"query\": \"#{GraphQL::Introspection::INTROSPECTION_QUERY.gsub("\n", '')}\" }" end res.body end |
#inspect ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql-docs/client.rb', line 40 def inspect inspected = super # mask password inspected = inspected.gsub! @password, '*******' if @password # Only show last 4 of token, secret if @access_token inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" end inspected end |