lib/nrql2nerd/client.rb in nrql2nerd-0.1.0 vs lib/nrql2nerd/client.rb in nrql2nerd-0.1.1a

- old
+ new

@@ -2,23 +2,15 @@ module NRQL2Nerd class Error < StandardError; end class Client - def initialize(api_key: nil, account_id: nil) - @api_key = ENV.fetch("NEW_RELIC_API_KEY", api_key) - @account_id = ENV.fetch("NEW_RELIC_ACCOUNT_ID", account_id) - - raise "NEW_RELIC_API_KEY is not set" if @api_key.nil? - raise "NEW_RELIC_ACCOUNT_ID is not set" if @account_id.nil? - end - def graphql_nrql_query(query) <<~GRAPHQL query { actor { - account(id: #{@account_id}) { + account(id: #{Config.new.account_id}) { nrql(query: "#{query}") { results } } } @@ -48,18 +40,20 @@ end def make_query_request(query) request = Net::HTTP::Post.new(uri) request["Content-Type"] = "application/json" - request["API-Key"] = @api_key + request["API-Key"] = Config.new.api_key request.body = prepare_query(query) client.request(request) end def run_query(query) response = make_query_request(query) JSON.parse(response.body).dig("data", "actor", "account", "nrql", "results") end + + # module_function :graphql_nrql_query, :graphql_hash, :prepare_query, :run_query, :make_query_request, :uri, :client end end