class Dirble::QueryExecuter

Constants

REQUEST_TYPES

Attributes

connection[RW]
form_fields[RW]
query[RW]
request_type[RW]

Public Class Methods

new(connection, query_params) click to toggle source
# File lib/dirble/query_executer.rb, line 5
def initialize(connection, query_params)
  self.connection = connection
  self.request_type = query_params[:request_type]
  self.query = query_params[:query]
  self.form_fields = query_params[:form_fields]
end

Public Instance Methods

execute() click to toggle source
# File lib/dirble/query_executer.rb, line 12
def execute
  guard_query_params
  replace_placeholder_with_api_key
  if form_fields
    connection.send(request_type, query, form_fields)
  else
    connection.send(request_type, query)
  end
end

Private Instance Methods

guard_query_params() click to toggle source
# File lib/dirble/query_executer.rb, line 26
def guard_query_params
  raise Dirble::Errors::InvalidRequestType, 'Bad request type provided. Please use :get or :post' unless REQUEST_TYPES.include?(request_type)
end
replace_placeholder_with_api_key() click to toggle source
# File lib/dirble/query_executer.rb, line 30
def replace_placeholder_with_api_key
  query.gsub!("{{api_key}}", Dirble.api_key)
end