module Reivt::RevAPI
Intrface for rev API, connects local changes with our remote.
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
An extension of the RevAPI
module
@author [brwnrclse]
Constants
- CLIENT
- CreateDocumentMutation
- CreateRevMutation
- CreateUserMutation
- DeleteDocumentMutation
- DeleteRevMutation
- ENDPOINT
- ENDPOINT_URL
- ID_TOKEN
- SCHEMA
- SCHEMA_PATH
- SigninMutation
Public Class Methods
API call to createDocument @param blob [String] The contents of the Document
@param content_type [String] The kind of Document
@param doc_name [String] The name of the Document
@param rev_id [String] The id of the Rev this Document
belongs to
@return [String] The id of the Document
# File lib/reivt/api/mutations/document_create.mutation.rb, line 27 def self.create_doc(blob, content_type, doc_name, has_diff, rev_id) blob = "That's all folks?" if blob.nil? || blob.strip.empty? doc_name = 'Empty Doc' if doc_name.nil? || doc_name.strip.empty? has_diff = false if has_diff.nil? if content_type.nil? || content_type.strip.empty? content_type = 'plain text' end if rev_id.length < 25 raise Reivt::GraphQLValidationException, 'Missing rev id' end result = CLIENT.query(CreateDocumentMutation, variables: { blob: blob, content_type: content_type, doc_name: doc_name, has_diff: has_diff, rev_id: rev_id }) data = RevAPI.retrieve(result) data.createDocument.id end
API call to createRev @param description [String] What the Rev is about @param title [String] The name of the Rev
@return [String] The id of the created Rev
# File lib/reivt/api/mutations/rev_create.mutation.rb, line 25 def self.create_rev(description, title) description = 'Some rev' if description.nil? || description.strip.empty? title = 'A rev, right?' if title.nil? || title.strip.empty? result = CLIENT.query(RevAPI::CreateRevMutation, variables: { description: description, title: title, user_id: RevAPI::ID_TOKEN }) data = RevAPI.retrieve(result) data.createRev.id end
Authenticate the user against the api to receive a user id @param id [String] The users's id from Auth0
@return [String] The user's id in the rev api
# File lib/reivt/api/mutations/user_create.mutation.rb, line 24 def self.create_user(auth0_id) result = CLIENT.query(RevAPI::CreateUserMutation, variables: { auth0_id: auth0_id }) data = RevAPI.retrieve(result) data.createUser.id end
API call to deleteDocument @param id [String] The unique identifier of the Document
@return [String, RevAPI::GraphQLValidationError] The id of the deleted
Document or an error
# File lib/reivt/api/mutations/document_delete.mutation.rb, line 25 def self.delete_doc(id) if id.length < 25 raise raise Reivt::GraphQLValidationException, 'Missing id to delete' end result = CLIENT.query(DeleteDocumentMutation, variables: { id: id }) data = RevAPI.retrieve(result) data.deleteDocument.id end
API call to deleteRev @param id [String] The unique identifier of the Rev
@return [String, RevAPI::GraphQLValidationError] The id of the deleted Rev
or an error
# File lib/reivt/api/mutations/rev_delete.mutation.rb, line 25 def self.delete_rev(id) if id.length < 25 raise Reivt::GraphQLValidationException, 'Missing id to delete' end result = CLIENT.query(RevAPI::DeleteRevMutation, variables: { id: id }) data = RevAPI.retrieve(result) data.deleteRev.id end
Raise any errors in the response data or simply return the data
@param api_response [Obj] A nested object containing either data or errors
@return [Array] A list containing the data and error object from the req
# File lib/reivt/api.rb, line 45 def self.retrieve(api_response) errors = api_response.errors data = api_response.data if data.nil? msg = errors.details[:data].map { |error| error['message'] } raise Reivt::GraphQLDataException, msg.join(",\n") else data end end
Authenticate the user against the api to receive a user id @param id [String] The users's id from Auth0
@return [String] The user's id in the rev api
# File lib/reivt/api/mutations/user_signin.mutation.rb, line 26 def self.signin_user(auth0_id) result = CLIENT.query(RevAPI::SigninMutation, variables: { auth0_id: auth0_id }) if result.data.nil? nil else data = RevAPI.retrieve(result) data.signinUser.user.id end end