Class: Dynectastic::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dynectastic/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Request

Returns a new instance of Request.



13
14
15
# File 'lib/dynectastic/request.rb', line 13

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#attemptsObject (readonly)

debug_output $stdout



11
12
13
# File 'lib/dynectastic/request.rb', line 11

def attempts
  @attempts
end

#job_idObject (readonly)

debug_output $stdout



11
12
13
# File 'lib/dynectastic/request.rb', line 11

def job_id
  @job_id
end

#job_incompleteObject (readonly)

debug_output $stdout



11
12
13
# File 'lib/dynectastic/request.rb', line 11

def job_incomplete
  @job_incomplete
end

#resourceObject (readonly)

debug_output $stdout



11
12
13
# File 'lib/dynectastic/request.rb', line 11

def resource
  @resource
end

#responseObject (readonly)

debug_output $stdout



11
12
13
# File 'lib/dynectastic/request.rb', line 11

def response
  @response
end

Instance Method Details

#jobObject



17
18
19
20
21
# File 'lib/dynectastic/request.rb', line 17

def job
  if job_id
    Job.new(self)
  end
end

#perform(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dynectastic/request.rb', line 23

def perform(*args)
  method, path, options = args.shift, args.shift, args.last
  options ||= {}
  prepare_options(options)
  reset_attempts
  
  begin
    process_response(self.class.send(method, path, options))
  rescue HTTParty::RedirectionTooDeep => e
    if e.response['Location'].include?("/REST/Job")
      memorize_response_data(e.response)
      false
    else
      raise e
    end
  
  rescue SessionBusy => e
    if attempts_left?
      sleep(10)
      increment_attempts      
      retry
    else
      raise e
    end
  end
end