Class: RedboothRuby::ClientOperations::Perform

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/redbooth-ruby/client_operations/perform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#camelize, #underscore

Constructor Details

#initialize(resource_name, action, session, options = {}) ⇒ Perform

Returns a new instance of Perform.



8
9
10
11
12
13
14
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 8

def initialize(resource_name, action, session, options = {})
  @resource_name = resource_name
  @action = action
  @session = session
  @options = options
  @tries = 0
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 5

def action
  @action
end

#oauth_token_expired_errorObject

Returns the value of attribute oauth_token_expired_error.



6
7
8
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 6

def oauth_token_expired_error
  @oauth_token_expired_error
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 5

def options
  @options
end

#processing_errorObject

Returns the value of attribute processing_error.



6
7
8
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 6

def processing_error
  @processing_error
end

#resource_nameObject

Returns the value of attribute resource_name.



5
6
7
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 5

def resource_name
  @resource_name
end

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 5

def session
  @session
end

#triesObject

Returns the value of attribute tries.



6
7
8
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 6

def tries
  @tries
end

Instance Method Details

#perform!Object

Performs the resource action

Returns:

  • the execution return or nil



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 19

def perform!
  @tries += 1
  fail RedboothRuby::AuthenticationError unless session
  resource(resource_name).send(action, options_with_session(options))
rescue Processing => processing_error
  @processing_error = processing_error
  perform_processing!
rescue OauthTokenExpired => oauth_token_expired_error
  @oauth_token_expired_error = oauth_token_expired_error
  perform_oauth_token_expired!
end

#perform_oauth_token_expired!Object

Perform refresh on the session access token

Returns:

  • the execution return or raise OauthTokenExpired



46
47
48
49
50
51
52
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 46

def perform_oauth_token_expired!
  if tries == 1 && refresh_session_access_token!
    perform!
  else
    raise oauth_token_expired_error
  end
end

#perform_processing!Object

Delays the execution of the enqueued processing

Returns:

  • the execution return or nil



34
35
36
37
38
39
40
41
# File 'lib/redbooth-ruby/client_operations/perform.rb', line 34

def perform_processing!
  delay = if processing_error && processing_error.response
    processing_error.response.data['retry_after'].to_i
  else
    10
  end
  retry_in(delay)
end