Class: OneRoster::Connection

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

Constant Summary collapse

OPEN_TIMEOUT =
60
TIMEOUT =
120

Instance Method Summary collapse

Constructor Details

#initialize(client, oauth_strategy = 'oauth') ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
# File 'lib/one_roster/connection.rb', line 8

def initialize(client, oauth_strategy = 'oauth')
  @client = client
  @oauth_strategy = oauth_strategy
end

Instance Method Details

#connectionObject



22
23
24
25
26
27
28
29
30
# File 'lib/one_roster/connection.rb', line 22

def connection
  return @connection if @connection

  @connection = if @oauth_strategy == 'oauth2'
                  oauth2_connection
                else
                  oauth_connection
                end
end

#execute(path, method = :get, params = nil, body = nil, content_type = nil) ⇒ Object



13
14
15
# File 'lib/one_roster/connection.rb', line 13

def execute(path, method = :get, params = nil, body = nil, content_type = nil)
  Response.new(raw_request(path, method, params, body, content_type))
end

#log(message = '') ⇒ Object



32
33
34
35
36
# File 'lib/one_roster/connection.rb', line 32

def log(message = '')
  return unless @client.logger

  @client.logger.info message
end

#set_auth_headers(token, cookie) ⇒ Object



17
18
19
20
# File 'lib/one_roster/connection.rb', line 17

def set_auth_headers(token, cookie)
  connection.authorization :Bearer, token
  @cookie = cookie
end