Class: DemoApi::Client
- Inherits:
-
Object
- Object
- DemoApi::Client
- Defined in:
- lib/demo_api/client.rb
Overview
Thin client over the demo GraphQL API.
Each method sends one operation and returns the plain data hash. The
shapes are documented in the GraphQL reference, linked from every method.
Instance Attribute Summary collapse
-
#endpoint ⇒ URI::HTTP
readonly
The GraphQL endpoint.
Instance Method Summary collapse
-
#create_project(input) ⇒ Hash
Creates a project.
-
#folder(id) ⇒ Hash?
Fetches a folder by id.
-
#initialize(endpoint:, token: nil) ⇒ Client
constructor
A new instance of Client.
-
#projects(status: nil, limit: 20) ⇒ Array<Hash>
Lists projects, optionally filtered by lifecycle stage.
Constructor Details
#initialize(endpoint:, token: nil) ⇒ Client
Returns a new instance of Client.
30 31 32 33 |
# File 'lib/demo_api/client.rb', line 30 def initialize(endpoint:, token: nil) @endpoint = URI(endpoint) @token = token end |
Instance Attribute Details
#endpoint ⇒ URI::HTTP (readonly)
Returns the GraphQL endpoint.
26 27 28 |
# File 'lib/demo_api/client.rb', line 26 def endpoint @endpoint end |
Instance Method Details
#create_project(input) ⇒ Hash
Creates a project.
Sends the createProject mutation.
84 85 86 87 88 89 90 91 |
# File 'lib/demo_api/client.rb', line 84 def create_project(input) query = <<~GRAPHQL mutation CreateProject($input: CreateProjectInput!) { createProject(input: $input) { id name status } } GRAPHQL execute(query, { input: input })['createProject'] end |
#folder(id) ⇒ Hash?
65 66 67 68 69 70 71 72 |
# File 'lib/demo_api/client.rb', line 65 def folder(id) query = <<~GRAPHQL query Folder($id: ID!) { folder(id: $id) { id name parent createdAt } } GRAPHQL execute(query, { id: id })['folder'] end |
#projects(status: nil, limit: 20) ⇒ Array<Hash>
Lists projects, optionally filtered by lifecycle stage.
Sends the projects query.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/demo_api/client.rb', line 45 def projects(status: nil, limit: 20) query = <<~GRAPHQL query Projects($status: ProjectStatus, $limit: Int) { projects(status: $status, limit: $limit) { nodes { id name status updatedAt } } } GRAPHQL variables = { status: status&.to_s&.upcase, limit: limit } execute(query, variables).dig('projects', 'nodes') end |