Module: Boxxspring::Worker::Authorization

Included in:
Base
Defined in:
lib/boxxspring/worker/authorization.rb

Instance Method Summary collapse

Instance Method Details

#authorize(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/boxxspring/worker/authorization.rb', line 7

def authorize( &block )
  begin
    retries ||= 3
    block.call( token )
  rescue Unimatrix::AuthorizationError => exception
    if ( retries -= 1 ) > 0
      token!
      retry
    else
      raise exception
    end
  end
end

#authorize_operation(result = nil, error_message = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/boxxspring/worker/authorization.rb', line 21

def authorize_operation( result = nil, error_message = nil )
  result = yield if block_given?

  if result.is_a?( Array ) && result.first.is_a?( Unimatrix::ForbiddenError )
    raise Unimatrix::AuthorizationError, error_message
  end

  result
end