Class: Faraday::Response
  
  
  
Defined Under Namespace
  
    
  
    
      Classes: Logger, Middleware, RaiseError
    
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  all_loaded_constants, autoload_all, load_autoloaded_constants
  
  
  
  
  
  
  
  
  
  
  fetch_middleware, load_middleware, lookup_middleware, middleware_mutex, register_middleware
  Constructor Details
  
    
  
  
    #initialize(env = nil)  ⇒ Response 
  
  
  
  
    
Returns a new instance of Response.
   
 
  
  
    
      
27
28
29
30 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 27
def initialize(env = nil)
  @env = Env.from(env) if env
  @on_complete_callbacks = []
end 
     | 
  
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    
Returns the value of attribute env.
   
 
  
  
    
      
32
33
34 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 32
def env
  @env
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #apply_request(request_env)  ⇒ Object 
  
  
  
  
    
Expand the env with more properties, without overriding existing ones. Useful for applying request params after restoring a marshalled Response.
   
 
  
  
    
      
87
88
89
90
91 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 87
def apply_request(request_env)
  raise "response didn't finish yet" unless finished?
  @env = Env.from(request_env).update(@env)
  return self
end 
     | 
  
 
    
      
  
  
    
      
45
46
47 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 45
def body
  finished? ? env.body : nil
end 
     | 
  
 
    
      
  
  
    #finish(env)  ⇒ Object 
  
  
  
  
    
      
62
63
64
65
66
67 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 62
def finish(env)
  raise "response already finished" if finished?
  @on_complete_callbacks.each { |callback| callback.call(env) }
  @env = Env.from(env)
  return self
end
     | 
  
 
    
      
  
  
    #finished?  ⇒ Boolean 
  
  
  
  
    
      
49
50
51 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 49
def finished?
  !!env
end 
     | 
  
 
    
      
  
  
    
      
40
41
42 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 40
def 
  finished? ? env. : {}
end
     | 
  
 
    
      
  
  
    #marshal_dump  ⇒ Object 
  
  
  
  
    
because @on_complete_callbacks cannot be marshalled
   
 
  
  
    
      
74
75
76
77
78
79 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 74
def marshal_dump
  !finished? ? nil : {
    :status => @env.status, :body => @env.body,
    :response_headers => @env.
  }
end
     | 
  
 
    
      
  
  
    #marshal_load(env)  ⇒ Object 
  
  
  
  
    
      
81
82
83 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 81
def marshal_load(env)
  @env = Env.from(env)
end 
     | 
  
 
    
      
  
  
    #on_complete  ⇒ Object 
  
  
  
  
    
      
53
54
55
56
57
58
59
60 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 53
def on_complete
  if not finished?
    @on_complete_callbacks << Proc.new
  else
    yield(env)
  end
  return self
end
     | 
  
 
    
      
  
  
    
      
36
37
38 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 36
def status
  finished? ? env.status : nil
end 
     | 
  
 
    
      
  
  
    #success?  ⇒ Boolean 
  
  
  
  
    
      
69
70
71 
     | 
    
      # File 'lib/puppet/feature/faraday/response.rb', line 69
def success?
  finished? && env.success?
end 
     |