Class: Linear::Client
- Inherits:
-
Object
- Object
- Linear::Client
- Defined in:
- lib/linear/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.linear.app/graphql"
Instance Method Summary collapse
-
#initialize(api_key = nil) ⇒ Client
constructor
A new instance of Client.
- #query(graphql_query, variables = {}) ⇒ Object
Constructor Details
#initialize(api_key = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/linear/client.rb', line 8 def initialize(api_key = nil) @api_key = api_key || ENV['LINEAR_API_KEY'] raise "No API key configured. Set LINEAR_API_KEY environment variable" unless @api_key end |
Instance Method Details
#query(graphql_query, variables = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/linear/client.rb', line 13 def query(graphql_query, variables = {}) payload = { query: graphql_query, variables: variables }.to_json escaped_payload = Shellwords.escape(payload) result = `curl -s -X POST #{BASE_URL} \ -H "Content-Type: application/json" \ -H "Authorization: #{@api_key}" \ -d #{escaped_payload}` parsed = JSON.parse(result) if parsed["errors"] raise "GraphQL Error: #{parsed["errors"].map { |e| e["message"] }.join(", ")}" end parsed end |