This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from zenaton/feature/scheduling
Add scheduling
- Loading branch information
Showing
10 changed files
with
473 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'zenaton/exceptions' | ||
|
||
module Zenaton | ||
# Collection of utility classes for the Zenaton library | ||
module Services | ||
# Service that: | ||
# - handles graphql calls | ||
# - translates exceptions into Zenaton specific ones | ||
class GraphQL | ||
CREATE_WORKFLOW_SCHEDULE = <<-'GRAPHQL' | ||
mutation ($createWorkflowScheduleInput: CreateWorkflowScheduleInput!) { | ||
createWorkflowSchedule(input: $createWorkflowScheduleInput) { | ||
schedule { | ||
id | ||
} | ||
} | ||
} | ||
GRAPHQL | ||
|
||
CREATE_TASK_SCHEDULE = <<-'GRAPHQL' | ||
mutation ($createTaskScheduleInput: CreateTaskScheduleInput!) { | ||
createTaskSchedule(input: $createTaskScheduleInput) { | ||
schedule { | ||
id | ||
} | ||
} | ||
} | ||
GRAPHQL | ||
|
||
def initialize(http:) | ||
@http = http | ||
end | ||
|
||
# Makes a GRAPHQL request with some data and sets the correct headers | ||
# | ||
# @param url [String] the url for the request | ||
# @param body [Hash] the payload to send with the request | ||
# @return [Hash] the parsed json response | ||
def request(url, query, variables = nil, headers = {}) | ||
body = { 'query' => query } | ||
body['variables'] = variables if variables | ||
|
||
res_body = @http.post(url, body, headers) | ||
handle_response_body(res_body) | ||
end | ||
|
||
private | ||
|
||
def handle_response_body(response_body) | ||
if external_error?(response_body) | ||
raise Zenaton::ExternalError, format_external_error(response_body) | ||
end | ||
|
||
response_body && response_body['data'] | ||
end | ||
|
||
def external_error?(response_body) | ||
response_body&.key?('errors') | ||
end | ||
|
||
def format_external_error(response_body) | ||
response_body['errors'].map do |error| | ||
path = error['path'] ? "- #{error['path']}: " : '' | ||
"#{path}#{error['message']}" | ||
end.join("\n") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.