class Kaseya::Connection

Constants

ERROR_MIDDLEWARE
ODATA_PARAMS

Public Class Methods

new(host, token) click to toggle source
# File lib/kaseya/connection.rb, line 9
def initialize(host, token)
  @host = host
  @token = token

  @connection = Faraday::Connection.new(connection_options) do |conn|
    ERROR_MIDDLEWARE.each do |klass|
      conn.use klass
    end

    conn.authorization :Bearer, @token
    conn.request :json
    conn.response :json
    conn.adapter Faraday.default_adapter
  end
end

Public Instance Methods

delete(path) click to toggle source
# File lib/kaseya/connection.rb, line 40
def delete(path)
  response = @connection.delete(path)
end
get(path, params = {}) click to toggle source
# File lib/kaseya/connection.rb, line 25
def get(path, params = {})
  response = @connection.get(path, format_params(params))
  response.body
end
post(path, params = {}) click to toggle source
# File lib/kaseya/connection.rb, line 30
def post(path, params = {})
  response = @connection.post(path, format_params(params))
  response.body
end
put(path, params = {}) click to toggle source
# File lib/kaseya/connection.rb, line 35
def put(path, params = {})
  response = @connection.put(path, format_params(params))
  response.body
end

Private Instance Methods

connection_options() click to toggle source
# File lib/kaseya/connection.rb, line 46
def connection_options
  {}
end
format_params(params) click to toggle source
# File lib/kaseya/connection.rb, line 50
def format_params(params)
  params.transform_keys do |key|
    case
    when ODATA_PARAMS.include?(key.to_sym)  then "$#{key}"
    when key.is_a?(Symbol)                  then key.to_s.camelize
    else key
    end
  end
end