Class: Kaseya::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/kaseya/connection.rb

Direct Known Subclasses

BMS::Connection, VSA::Connection

Constant Summary collapse

ODATA_PARAMS =
[:skip, :top, :orderby, :filter]
ERROR_MIDDLEWARE =
[]

Instance Method Summary collapse

Constructor Details

#initialize(host, token) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kaseya/connection.rb', line 8

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.request :authorization, :Bearer, @token
    conn.request :json
    conn.response :json
    conn.adapter Faraday.default_adapter
  end
end

Instance Method Details

#delete(path) ⇒ Object



39
40
41
# File 'lib/kaseya/connection.rb', line 39

def delete(path)
  response = @connection.delete(path)
end

#get(path, params = {}) ⇒ Object



24
25
26
27
# File 'lib/kaseya/connection.rb', line 24

def get(path, params = {})
  response = @connection.get(path, format_params(params))
  response.body
end

#post(path, params = {}) ⇒ Object



29
30
31
32
# File 'lib/kaseya/connection.rb', line 29

def post(path, params = {})
  response = @connection.post(path, format_params(params))
  response.body
end

#put(path, params = {}) ⇒ Object



34
35
36
37
# File 'lib/kaseya/connection.rb', line 34

def put(path, params = {})
  response = @connection.put(path, format_params(params))
  response.body
end