Class: OneRoster::Connection
- Inherits:
-
Object
- Object
- OneRoster::Connection
- Defined in:
- lib/one_roster/connection.rb
Defined Under Namespace
Classes: GatewayTimeoutError
Constant Summary collapse
- OPEN_TIMEOUT =
60- TIMEOUT =
120
Instance Method Summary collapse
- #connection ⇒ Object
- #execute(path, method = :get, params = nil, body = nil, content_type = nil) ⇒ Object
-
#initialize(client, oauth_strategy = 'oauth') ⇒ Connection
constructor
A new instance of Connection.
- #log(message = '') ⇒ Object
- #set_auth_headers(token, cookie) ⇒ Object
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
#connection ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/one_roster/connection.rb', line 38 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/one_roster/connection.rb', line 13 def execute(path, method = :get, params = nil, body = nil, content_type = nil) response = Response.new(raw_request(path, method, params, body, content_type)) if [502, 504].include?(response.status) log_to_sentry( 'client.app_id' => @client.app_id, 'connection.path' => path, 'connection.method' => method, 'connection.params' => params, 'connection.body' => body, 'connection.content_type' => content_type, 'response.http_status' => response.status, 'response.raw_body' => response.raw_body ) raise GatewayTimeoutError if response.timed_out? end response end |
#log(message = '') ⇒ Object
48 49 50 51 52 |
# File 'lib/one_roster/connection.rb', line 48 def log( = '') return unless @client.logger @client.logger.info end |
#set_auth_headers(token, cookie) ⇒ Object
33 34 35 36 |
# File 'lib/one_roster/connection.rb', line 33 def set_auth_headers(token, ) connection. :Bearer, token = end |