Module: CampusIvy::Connection

Included in:
Client
Defined in:
lib/campus_ivy/connection.rb

Instance Method Summary collapse

Instance Method Details

#connection ⇒ Object



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

def connection
  @connection ||= Faraday.new(url: config.base_url) do |conn|
    conn.request :json

    # Authentication header
    conn.request :authorization, :Bearer, config.token if config.token

    conn.response :json, content_type: /\bjson$/

    # Custom middleware for handling errors could go here
    # conn.use CampusIvy::Middleware::ErrorHandler

    conn.adapter Faraday.default_adapter
  end
end

#reset_connection ⇒ Object



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

def reset_connection
  @connection = nil
end